I have created a number of CCSprites using spriteWithFile.
How do I change the image for the sprite during runtime?
I need to change a few sprites images quite regularly.
CCTexture *tex = [CCTexture textureWithFile:fileName];
self.texture = tex;
If you are using SpriteSheets, this will work.
NSString* newSprite = [NSString stringWithString:@"SPRITE_NAME.png"];
CCSpriteFrameCache* cache = [CCSpriteFrameCache sharedSpriteFrameCache];
[sprite setDisplayFrame:[cache spriteFrameByName:newSprite]];
[yourSprite setTexture:[[CCSprite spriteWithFile:@"yourImage.png"]texture]];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With