Can't get a CCPointArray to work in Cocos2D-x

和自甴很熟 提交于 2019-12-12 04:33:44

问题


I want to create a an array of points (_grid). However, I can't seem to use this CCPointArray anywhere except the function it's created in. I've tried making it public in my class and declaring it in my header, but all fail. Any tips?


回答1:


after

CCPointArray* p = CCPointArray::create(8);

did you call

p->retain();

?

and remember to release it in your destructor or onExit();

in your YOUR_CLASS.h file

class YOUR_CLASS : public cocos2d::CCLayer {
    CCPointArray* p;
public:
    CREATE_FUNC(YOUR_CLASS);
    bool init();
    void onExit();
}

in your YOUR_CLASS.cpp file

bool YOUR_CLASS::init(){
    if(CCLayer::init()){
         p = CCPointArray::create(8);
         p->retain();
         return true;
    }
    return false;
}

void YOUR_CLASS::onExit(){
    CCLayer::onExit();
    p->release();
    p = NULL;
}


来源:https://stackoverflow.com/questions/12999771/cant-get-a-ccpointarray-to-work-in-cocos2d-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!