Frage

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?

War es hilfreich?

Lösung

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();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top