Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to understand how to create z-order system like you can see in

Character is above the tree when he is in front of it and vice versa.

Also, I'm planning to use sprite batching and all the sprites will not fit in one texture (2048*2048 for cocos2d-iphone). So I need to use several batches (like one for background and one for characters).

Additional "top-background" layer with above the character layer will not solve the problem: what if two characters are staying in front and behind a tree at the same time?

So, I'm thinking about some sort of masking but I don't know how to properly implement it.

Example from the RotMG:

share|improve this question
Do your sprites use any kind of alpha blending? – sam hocevar Dec 6 '11 at 21:28
Not yet, but probably I'll need it in future. – Ivan Mir Dec 7 '11 at 21:13

You need to implement a "2.5D" system. Taking the picture as reference, the ground is drawn first, then all the sprites, using Y as the order. Start from the top (y=0), bush, bush, tree, plant, tree, character, tree, stick, and so on. Please note the character has been drawn before the tree near him, that's it. TL;DR: Draw sprites according to their Y offset.

share|improve this answer

It's simple

z_order = position_y

Where axis origin is top left corner of screen(in cocos2d, it's bottom left). Player has origin at right between his foot. tree has origin at it's root.....

If the map has size of 100x100, and player are at map's limit, his z_order must be 100.

If 2 character are at the same y position, their z_order are equal too.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.