Domanda

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?

È stato utile?

Soluzione

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();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top