ccspritecocos2d-x

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


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.


Solution

  • mySprite->setTexture(CCTextureCache::sharedTextureCache()->addImage("newImage.png"));
    

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