How to change z order value of a sprite in Cocos2D ?

By | May 19, 2011

Hi,

Sometimes during the execution of program you may need to change the z order value of sprite for better working. Use the following sample of code to change the z order value of a sprite in Cocos2D/Box2D iPhone programming.

CCSprite *urSprite = [CCSprite spriteWithFile:@"coderzheavenLogo.png"];
urSprite.position = ccp(240,160);
//First setting the z value to 1
[self addChild:urSprite z:1];
.
.
.
.
.
//After some other executions are over setting z value to 7
[self reorderChild:urSprite z:7];

🙂

Leave a Reply

Your email address will not be published. Required fields are marked *