CC_SYNTHESIZE(int,beadColor,_BeadColor);在非静态成员函数之外使用'this'无效

时间:2013-12-17 14:04:02

标签: c++ cocos2d-iphone

我的cocos2d-x代码中存在一些问题。 我在这里发布我的代码。

BeadSprite.h

#include "cocos2d.h"
#include "iSet.h"
#include "LHSprite.h"

enum{
    BlueBead = 1,
    RedBead = 2,
    GreenBead = 3,
    WhiteBead = 4,
    BlackBead = 5,
    HeartBead = 6,
    StrongBlueBead = 7,
    StrongRedBead = 8,
    StrongGreenBead = 9,
    StrongWhiteBead = 10,
    StrongBlackBead = 11,
    StrongHeartBead = 12,
    ClearBead = 13,
};

USING_NS_CC;

class BeadSprite : public LHSprite
{
private:

    void changeBeadColorAction(int ToColor);
    void changeBeadColor(int ToColor);
    void boombBeads(int ToColor);
    void boombStrongBeads(int ToColor);
    void boombStrongFX();
    void runShatterEffectWithCan(CCDelayTime* time);
public:
    /*static LHSprite* spriteWithName(const std::string& spriteName,
                                    const std::string& sheetName,
                                    const std::string& spriteHelperFile);*/
    CC_SYNTHESIZE(int, beadColor, _BeadColor);
};

#endif

BeadSprite.cpp

#include "BeadSprite.h"
using namespace cocos2d;

void FsetBeadColor(const std::string& color){
    if(color == "BlueBead") this->beadColor = BlueBead; <-Invalid use of 'this' outside of a non-static member function
    if(color == "RedBead") this->beadColor = RedBead; <-Invalid use of 'this' outside of a non-static member function
    if(color == "GreenBead") this->beadColor = GreenBead; <-Invalid use of 'this' outside of a non-static member function
    if(color == "WhiteBead") this->beadColor = WhiteBead; <-Invalid use of 'this' outside of a non-static member function
    if(color == "BlackBead") this->beadColor = BlackBead; <-Invalid use of 'this' outside of a non-static member function
    if(color == "HeartBead") this->beadColor = HeartBead; <-Invalid use of 'this' outside of a non-static member function
}

void changeBeadColorAction(int ToColor){

}

错误: BeadSprite.cpp:31:29:在非静态成员函数之外使用'this'无效

如何修复此错误?请 :( 这使用cocos2d-x-2.2.1

1 个答案:

答案 0 :(得分:4)

您对CC_SYNTHESIZE的使用将创建一个私人会员beadColor和公开访问者get_BeadColor以及设置者set_BeadColor。因此,您的函数实现具有错误的名称,需要被认定为属于类BeadSprite

void BeadSprite::set_BeadColor(const std::string& color) {
  // ...
}