Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the Z-Order of sprites?

I want to set the Z-order of the sprites I create in Objective-C, specifically in Cocos2D.

This is the error I get when trying to build the following code:

CCSprite *mySprite = [CCSprite spriteWithFile:@"Image.png" rect:CGRectMake(0, 0, 96, 24)]; 
mySprite.zOrder = 0;

...220: error: object cannot be set - either readonly property or no setter found

Z-Order must be able to be set somehow - can it only be set on the line of instantiation and not after it's been created? Do I have to create a setter method for an attribute for CCSprite? Why wouldn't it already have those methods?

like image 288
JJR Avatar asked Aug 18 '10 15:08

JJR


1 Answers

If you need to reorder after adding the sprites, as GamingHorror said, use:

[self reorderChild:sprite z:newZ];

Your answer works if all you need is to set the original order

like image 166
Juan Carlos Méndez Avatar answered Sep 18 '22 19:09

Juan Carlos Méndez