Z order equals to Y Position ?

0 favourites
  • 10 posts
  • Hi

    I'm doing an isometric game, and am having trouble with z order. Basically what I need is for the z order to be determined by the y position on screen, so that objects overlap correctly.

    In essence:

    Every tick, every object get a z-order equal to its Y coordinate (since y increases downwards).

    Any idea how to implement something like this?

    Thanks

  • You can for example create as many Layers as you want to have Z-Orders. For example 10 layers for 10 different Z levels. You then order them in your prefered order.

    And you can make the following.

    Every tick ->

    If Object1.Y < 100 - Object1.MoveToLayer 1

    else IF 100 < Object1.Y <200 - Object1.MovetoLayer 2

    else IF 200 < Object1.Y <300 - Object1.MovetoLayer 3

    That works for a limited number of Z dimensions.

    For an infinite number, it is possible to move an object either to the Top of the Z Order or the Bottom of it, but im not sure what your game is trying to achieve, thus not sure if that would help you.

  • There is plugin that sort all objects in layer automagically.

    Another way to do it is to place all your objects that are supposed to be sorted to same layer and family called "ZOrder", then add this event:

    Every tick

    for each ZOrder (sort by Y ascending)

    .. ZOrder move to bottom of layer

    This can (and should) be optimized a bit if there are lots of objects.

  • Well, I�m trying to do this. In one moment of the game, the enemy is a few pixels higher than the player. In another, the enemy is a few pixels below. But in both cases they overlap a bit.

    If the z order is not correct, the illusion that one is behind the other is broken.

  • Every tick

    for each ZOrder (sort by Y ascending)

    .. ZOrder move to bottom of layer

    This can (and should) be optimized a bit if there are lots of objects.

    Thanks. This did the trick. So far is really slow (it hangs), but I?m gonna tweak it for a while and see why is that, and how can I fix it.

  • Create a Family

    • put everything what need to be sorted inside this family.

    Every tick

    For each Family Y < Family Y - Send back;

    Sample: http://goo.gl/1a3Jt

  • >

    > Every tick

    > for each ZOrder (sort by Y ascending)

    > .. ZOrder move to bottom of layer

    >

    > This can (and should) be optimized a bit if there are lots of objects.

    Thanks. This did the trick. So far is really slow (it hangs), but I?m gonna tweak it for a while and see why is that, and how can I fix it.

    One way is to only calculate it for moving objects, not for every object. Usually Zorder only changes if objects move, thus saving lots of processing stuff.

  • CPUsage for small projects, without WEBGL ON, is so low, giving you no problems about it. But for large projects, you would assume that.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • CPUsage for small projects, without WEBGL ON, is so low, giving you no problems about it. But for large projects, you would assume that.

    I've had noticeable differences with around 60 objects, even with webGL enabled. Usually it's simple to optimize it so that you don't need to reorder every object every tick. :)

  • Thanks for this! This thread was the perfect find!

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