How to swap the sprite in the CCSprite object in Cocos2d-X

azelez picture azelez · May 4, 2012 · Viewed 14k times · Source

I have an object that inherited from CCSprite. I want from inside this object to change the image.

How do I change the image (sprite) without creating a new CCSprite object in Cocos2d-X?

Thanks, Adrian.

Answer

Nikhil Aneja picture Nikhil Aneja · May 5, 2012
mySprite->setTexture(CCTextureCache::sharedTextureCache()->addImage("newImage.png"));

No need to alter your custom class.. Hope this helps.. :)