Time for action – fixing z-order
If you were highly attentive and have a sharp eye, you might have noticed a little issue with our hunter's legs and torso. The issue is that the torso is displayed above the belt part of the pants.

The current z-order and the correct z-order
It is hard to notice since the character is pretty small, but if you zoom in (Ctrl + mouse wheel,) you will be able to see the issue. Let's fix this using the following steps, and then I'll explain why this is happening:
Open the
Hunter.m
file to find the following line in theinit
method:[self addChild:_torso];
Make the following change:
[self addChild:_torso z:-1];
Now, build and run the project. You should see the torso behind the legs, as it should be.
What just happened?
First of all, we need to understand what z-order is. With Cocos2D, we're living in a two-dimensional (2D) world, but we all know there is a third dimension, and this dimension can be quite useful to resolve the order of the things in the Cocos2D world...