mercredi 30 décembre 2015

as3 - How to sort display objects that constantly switch depths?

I have a 2.5D game (2D game that acts like a 3D game) where you constantly switch depths, where the player displays on top of an object when it walks in front of it and when it walks behind it, the object displays on top of the player. Like when the player's y is less than the object's y, the player would be going behind the object and vice versa.

I tried to use a code like this:

if (player.y < block.y)
    setChildIndex(block, numChildren - 5);
else if (player.y > block.y)
    setChildIndex(block, numChildren - 10);

However, I see if I do it this way with multiple times, I would need tons of codes and the display list would get mixed up and sort the wrong depths in the wrong orders. Would anyone please show an organized depth changer with minimal code?

Aucun commentaire:

Enregistrer un commentaire