Search code examples
objective-ccocos2d-iphonespritebuilder

How to replace Sprite Frame in CCNode?


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!


Solution

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

    Try something like this:

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