I have Board class:

struct Cell
{
    cocos2d::Sprite* sprite;
    int status;
};

class Board
{
public:
    Cell* cells[5][5];
    ...
};

In .cpp file, I call:

cells[i][j]->sprite = Sprite::create("abc.png");

but error runtime. Please tell me why?

有帮助吗?

解决方案

After creating Sprite you have to retain it if you are not adding it to Layer in function where you have create otherwise it will be released after function call. you should use like

cells[i][j]->sprite = Sprite::create("abc.png");
sprite->retain();

in destructor release it:

cells[i][j]->sprite->release();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top