2
\$\begingroup\$

I'm trying to understand how to create z-order system like you can see in http://www.realmofthemadgod.com/

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: https://i.sstatic.net/d8dAe.png

\$\endgroup\$
2
  • \$\begingroup\$ Do your sprites use any kind of alpha blending? \$\endgroup\$ Commented Dec 6, 2011 at 21:28
  • \$\begingroup\$ Not yet, but probably I'll need it in future. \$\endgroup\$
    – Ivan Mir
    Commented Dec 7, 2011 at 21:13

2 Answers 2

1
\$\begingroup\$

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.

\$\endgroup\$
0
1
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .