Hi guys, ive been playing around with cocos and have 2 sprites, one chases the other.
I have a timer that runs every 0.25 seconds.
That timer does this.
CGPoint animalpoint = [[self getChildByTag:kTagAnimal] position];
int animalY = animalpoint.y;
[[self getChildByTag:kTagAnimal] _setZOrder:animalY];
NSLog(@"Animal zorder is %d", [[self getChildByTag:kTagAnimal] zOrder]);
CGPoint spritepoint = [[self getChildByTag:kTagSprite] position];
int spriteY = spritepoint.y;
[[self getChildByTag:kTagSprite] _setZOrder:spriteY];
NSLog(@"Player zorder is %d", [[self getChildByTag:kTagSprite] zOrder]);
The idea being, that it takes the y position of the sprite, and sets it to the zOrder, so that the closer to the top of the screen you are the 'closer' to the screen the sprite is, and thus is ontop of everything underneath it.
I know im doing a few things that i maybe am not sposed to, but it seems to be changing the zorder fine, just it doesnt update it on the screen, the logs prove the code is working, yet the sprites stay in the same stacking order.
Is there a redraw command that i am missing out? or an alternate correct way of doing what i am trying to acheive?
Thanks