访问C ++ / Cocos2dx中的基类方法

时间:2014-03-27 16:00:54

标签: c++ cocos2d-x

我有一个继承自CCArmature类的CCEnemy类。但是当我调用在CCArmature中声明的方法时,它会导致错误。怎么了?

我的CCEnemy.h

#include "cocos2d.h"

#ifndef __CCEnemy_H__
#define __CCEnemy_H__

#if ENABLE_PHYSICS_BOX2D_DETECT
#include "../../Box2DTestBed/GLES-Render.h"
#include "Box2D/Box2D.h"
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
#include "chipmunk.h"
#endif

USING_NS_CC;

class CCEnemy : public cocos2d::extension::CCArmature
{
public:
    static CCEnemy* create(int enemyID, const char *enemyName);
    static CCEnemy* create(int enemyID, const char *enemyName, float speed);
    static CCEnemy* create(int enemyID, const char *enemyName, float speed, float strength);
    static CCEnemy* create(int enemyID, const char *enemyName, float speed, float strength, float mMana);
    static CCEnemy* create(int enemyID, const char *enemyName, float speed, float strength, float mMana, float mCost);
    int getenemyID();
    float getEnemySpeed();
    float getEnemyStrength();
    float getEnemyMana();
    float getEnemyCost();
    void setEnemySpeed(float speed);
    void setEnemyStrength(float strength);
    void setEnemyMana(float mana);
    void setEnemyCritical(float cost);

//Enemy property
protected:
    int mEnemyID; //ID của enemy
    float mSpeed; //tốc độ bay
    float mStrength; //sức công phá
    float mMana; //máu
    float mCost;

    void onEnemyHit(); //"đạn" đụng vật cản
};

#endif 

CCEnemy.cpp

#include "common/Define.h"

USING_NS_CC;
using namespace cocos2d;
using namespace cocos2d::extension;

CCEnemy* CCEnemy::create(int enemyID, const char *enemyName){
    CCEnemy *pobArmature = new CCEnemy();
    if (pobArmature && pobArmature->init(enemyName))
    {               
        pobArmature->autorelease();
        pobArmature->mEnemyID = enemyID;    
        pobArmature->mSpeed = 0;
        pobArmature->mStrength = 0;
        pobArmature->mMana = 0;
        pobArmature->mCost = 0;
        return pobArmature;
    }
    CC_SAFE_DELETE(pobArmature);
    return NULL;
}

CCEnemy* CCEnemy::create(int enemyID, const char *enemyName, float speed){
    CCEnemy *pobArmature = new CCEnemy();
    if (pobArmature && pobArmature->init(enemyName))
    {               
        pobArmature->autorelease();
        pobArmature->mEnemyID = enemyID;    
        pobArmature->mSpeed = speed;
        pobArmature->mStrength = 0;
        pobArmature->mMana = 0;
        pobArmature->mCost = 0;
        return pobArmature;
    }
    CC_SAFE_DELETE(pobArmature);
    return NULL;
}

CCEnemy* CCEnemy::create(int enemyID, const char *enemyName, float speed, float strength){
    CCEnemy *pobArmature = new CCEnemy();
    if (pobArmature && pobArmature->init(enemyName))
    {               
        pobArmature->autorelease();
        pobArmature->mEnemyID = enemyID;    
        pobArmature->mSpeed = speed;
        pobArmature->mStrength = strength;
        pobArmature->mMana = 0;
        pobArmature->mCost = 0;
        return pobArmature;
    }
    CC_SAFE_DELETE(pobArmature);
    return NULL;        
}

CCEnemy* CCEnemy::create(int enemyID, const char *enemyName, float speed, float strength, float mMana){
    CCEnemy *pobArmature = new CCEnemy();
    if (pobArmature && pobArmature->init(enemyName))
    {               
        pobArmature->autorelease();
        pobArmature->mEnemyID = enemyID;    
        pobArmature->mSpeed = speed;
        pobArmature->mStrength = strength;
        pobArmature->mMana = mMana;
        pobArmature->mCost = 0;
        return pobArmature;
    }
    CC_SAFE_DELETE(pobArmature);
    return NULL;        
}

CCEnemy* CCEnemy::create(int enemyID, const char *enemyName, float speed, float strength, float mMana, float mCost){
    CCEnemy *pobArmature = new CCEnemy();
    if (pobArmature && pobArmature->init(enemyName))
    {               
        pobArmature->autorelease();
        pobArmature->mEnemyID = enemyID;    
        pobArmature->mSpeed = speed;
        pobArmature->mStrength = strength;
        pobArmature->mMana = mMana;
        pobArmature->mCost = 0;
        return pobArmature;
    }
    CC_SAFE_DELETE(pobArmature);
    return NULL;        
}


void CCEnemy::onEnemyHit(){
    //Xử lý khi "đạn" có va chạm, có thể là hiệu ứng của đạn...
}

float CCEnemy::getEnemySpeed(){
    return mSpeed;
}

float CCEnemy::getEnemyStrength(){
    return mStrength;
}

float CCEnemy::getEnemyMana(){
    return mMana;
}

float CCEnemy::getEnemyCost(){
    return mCost;
}

void CCEnemy::setEnemySpeed(float speed){
    mSpeed = speed;
}

void CCEnemy::setEnemyStrength(float strength){
    mStrength = strength;
}

void CCEnemy::setEnemyMana(float mana){
    mMana = mana;
}

void CCEnemy::setEnemyCritical(float cost){
    mCost = cost;
}

代码有错误' class CCEnemy'没有名为' setBody'

的成员
CCEnemy *enemy = CCEnemy::create(0, s_DragonName);
enemy->setBody(body); //setBody is declared in CCArmature

0 个答案:

没有答案