Z-order and in front/behind issue

  • I need some help figuring out how to get my character and NPC sprites to properly layer when they're in front and behind of each other. What I want to do is this:

    <img src="http://i.imgur.com/jzZnCtD.png" border="0" />

    Where when the red sprite is in front of the blue sprite it shows up on top, but when the red sprite is behind the blue sprite the blue sprite is on top. Working with single layers just ends up with one sprite always being on top, regardless of position:

    <img src="http://i.imgur.com/8iqRw8i.png" border="0" />

    Is the best way to handle this to cut my sprites in half at the waist with the waist-down being on a lower layer than the waist up? If I put the collision box in the lower half, the sprites should be able to line up properly:

    <img src="http://i.imgur.com/5BF3Qea.png" border="0" />

    So, that works, but I'm posting here in hopes of there being a better way, whether there's a function I didn't know about, or a behavior someone's published, or just an easier trick someone thought up.

    Thanks in advance.

  • Do this:

    every tick

    for each dude (order by y ascending)

    .. dude move to top of the layer

    Should work. Depending on how many objects you have will need to be optimized :)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Do this:

    every tick

    for each dude (order by y ascending)

    .. dude move to top of the layer

    This is what I do.

  • Ahh, thanks so much. Works great.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)