Cocos2dx Sprite Exchange

Hello!

I have a question. How to exchange sprites so its optimal and so that it does not take to much memory. My situation looks like this:

Sprite* animalSprite = Sprite::create("cat.png");

but the sprite “animalSprite” is changing every second so is it ok to do something like this:

if (dog)
     animalSprite = Sprite::create("dog.png");
else
    animalSprite = Sprite::create("cat.png");

every second?
Will the memory be cleaned or should I do it in an other way? I cant do something like dogSprite and catSprite :wink: I need only 1 sprite and thats animalSprite. So will the Sprite::create kill the device?

You could create both and use setVisible() to control which one is shown.

You can also change the texture of animalSprite at your every second interval.

You should change the texture of sprite, better then set visible

It’s very easy to do, plus don’t forgot after set the texture, set the texture rect too, just in case , that’s way, everything gonna work