0

Objective-C を数年間使用した後、C++ と Cocos2d-x を学び始めたところです。今夜の障害は、CCArray 関数をクラス全体の変数として使用する方法を学習することのようです。

HelloWorldScene.h

class HelloWorld : public cocos2d::CCLayer
{

public:
    // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
    virtual bool init();  

    // there's no 'id' in cpp, so we recommand to return the exactly class pointer
    static cocos2d::CCScene* scene();

    // a selector callback
    void menuCloseCallback(CCObject* pSender);

    // implement the "static node()" method manually
    CREATE_FUNC(HelloWorld);

    // static Array of tiles
    static cocos2d::CCArray* uniquetiles;
};

HelloWorldScene.cpp

uniquetiles=CCArray::create();
uniquetiles->addObject(d00);

コードを実行しようとすると、「'Helloworld::uniquetiles' への未定義の参照です」というエラーが表示されます

ここで何が間違っていますか?これは簡単なようです。

4

2 に答える 2

3

この変数をクラス定義に追加する必要があります。

private:
    CCArray* uniquetiles;
于 2013-06-04T14:46:22.397 に答える