0
votes

I haven't been able to figure this one out. I know how to replace a sprite frame from a CCSprite, but I can't figure out how to replace a sprite frame when my object is already a CCNode. I think it should be possible since I'm using Spritebuilder and there is an option to change the Sprite frame on my CCNode within Spritebuilder, but I need to change it during run time.

Is this possible or do I have to switch all of my CCNodes to CCSprites when I want to change the sprite frame during run time?

(Sorry it seems like I'm not trying to offer any solutions or show my work, but I've been reading through class references for a while and haven't made any progress)

Thanks!

1
you should show your attempts though. If you are indeed using a CCNode instance, you can't assign a sprite frame to it because it's not a sprite. If you do have a CCSprite instance but you only obtain a CCNode instance (ie via getChildWithName:) then you need to cast it to CCSprite.LearnCocos2D

1 Answers

0
votes

It's likely that your CCSprite is a child of your CCNode

Try something like this:

CCSprite *sprite = yourCCNode.children[0];
[sprite setSpriteFrame: newFrame];