How to change the Z value of a Sprite during an action in Cocos2D ?

By | March 27, 2011

Hi,
There may arise some situations where you need to change the z value of a particular sprite during an action in Cocos2D. So how can you do that? See the following lines of code.

CCSprite *sample= [CCSprite spriteWithFile:@"trialImage.png"];
sample.position = ccp(160,240);
[self addChild:sample z:1];
/* Some of your actions goes here! */
[self reorderChild:sample z:9];

This will re order the sprite’s tag to 9 from 1 after ‘your actions’.
šŸ™‚

Leave a Reply

Your email address will not be published.