Changing the sprite of an object included in a CCSpriteBatchNode


#1

I have an object called Rock, this inherits from CCSprite.
I have added that as a child to a CCSpriteBatchNode, which is associated with a texture containing 2 sprites (boulder_1.png, and boulder_1_broken.png).
These were loaded in earlier as spriteframes from a plist file.

When the Rock object reaches half health, I want to be able to change the sprite.
I am trying to do this with this:

rock->initWithSpriteFrameName("boulder_1_broken.png");

as I did to setup the sprite but this throws an error when tried to draw.

Does anyone know another way I should be re-setting the image on the object?
Thanks in advance.


#2
setTexture(CCTextureCache::sharedTextureCache()->addImage("filename"));

You should not call init… on already initialized objects.


#3

Thanks a lot.
It is Monday, I am really not with it today haha


#4

Wasn’t quite what I needed put it pointed me in the right direction.
Since all my sprites are already loaded as sprite frames I did this instead:

rock->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("boulder_1_broken.png"));

But thanks a lot =D