Book Image

Learning iPhone Game Development with Cocos2D 3.0

By : Kirill Muzykov
Book Image

Learning iPhone Game Development with Cocos2D 3.0

By: Kirill Muzykov

Overview of this book

Table of Contents (19 chapters)
Learning iPhone Game Development with Cocos2D 3.0
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. Open the Hunter.m file to find the following line in the init method:

    [self addChild:_torso];
  2. Make the following change:

    [self addChild:_torso z:-1];
  3. 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...