Changing the image of the sprite in cocos2D ?

By | March 17, 2011


You all know how to add an Image to a sprite. But what if we need to change the image of the same sprite? How to do that?
Use the following line of code to change the image of a sprite which already initialized with a sprite.

[sampleSprite setTexture:[[CCTextureCache sharedTextureCache] addImage:@"newImage.png"]];

where sampleSprite is the name of your sprite and newImage is the new image you want to replace with!


Leave a Reply

Your email address will not be published. Required fields are marked *