Pregunta

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?

¿Fue útil?

Solución

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();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top