无法使CCPointArray在Cocos2D-x中工作 [英] Can't get a CCPointArray to work in Cocos2D-x

查看:225
本文介绍了无法使CCPointArray在Cocos2D-x中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个点数组(_grid).但是,除了在其中创建函数外,我似乎无法在任何地方使用此CCPointArray.我尝试将其公开在类中并在标头中声明,但都失败了.有提示吗?

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?

推荐答案

之后

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

您打电话给

p->retain();

?

,并记得在析构函数或onExit()中释放它;

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

在您的YOUR_CLASS.h文件中

in your YOUR_CLASS.h file

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

在您的YOUR_CLASS.cpp文件中

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;
}

这篇关于无法使CCPointArray在Cocos2D-x中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆