Pergunta

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?

Foi útil?

Solução

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 em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top