Set Z-Order With Number

This forum is currently in read-only mode.
From the Asset Store
10 Beautiful Pokemon-like Building Pixel Art Sprite Sets
  • I think it would be nice if you could set the Z-order of objects with a number. For example, if object one has a Z-order of -1 and object 2 has one of 0, object 2 will appear ahead of object one. This would be handy for things like isometric games where you could set the Z-order of all objects to their Y coordinate. Game Maker handles Z-order using numbers like this, and it really helps for ordering everything correctly.

  • You can sort stuff based on the y position by adding all the objects that need to be sorted to a family, then use a for-each ordered condition using family.y and send the family to front or back(can't remember which at the moment).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So you're saying that when you do a for each loop on a family of objects the loop starts with the object that has the highest (or lowest?) y position? That's handy to know if that's the case, but it's not well-documented and it's certainly not intuitively obvious.

    I think a nice way to handle this would be to have an option to automatically z sort items by y-coordinate. Linkman's suggestion would give more flexibility but I think the iso game z-sorting issue is the main motivator here and this auto sort would work well for that problem. Also, maybe you could auto z-sort just the objects involved in the collision. So on (for example) a busy isometric rts layout you'll save a lot of unnecessary z-sorting.

  • I know you can use the For Each Ordered condition, but that could eat up processing time if you had a lot of objects to loop through.

  • 'For each ordered' is a good way - it's not CPU intensive if it's not nested with any other loops.

    Sort by Y co-ordinate:

    + For each Sprite order by Sprite.Y ascending

    -> Sprite: send to front

    Sort by any old number:

    + For each Sprite order by Sprite('some_variable_with_z_number')

    -> Sprite: send to front

    Then you can set any old number to the 'some_variable_with_z_number' private variable, and it'll sort the Z order from that.

  • So many times, so many ways Ashley reminds us that in Construct you can do a lot with what you've already got.

    Hey that was almost a poem. Here, I'll give it to you in Haiku form ... nevermind.

  • Hi. I am displaying an isometric tilemap... with the (0,0) tile (on the grid) mapped top centre. This means that the required Z-order for any particular tile representing a grid location is given by Z=x+y... So each 'diagonal on the grid, horizontal on the screen' row will have tiles with the same Zorder value - they cannot overlap so that is fine and normal for iso.

    If I replace a tile somewhere then I could just set the Zorder for the newly created tile as I know what value I want to give it.... but Construct2 does not seem to let me do that ?

    Is there any way to avoid having to loop over the entire grid everytime I replace a single tile - the visible grid is 20x20, so this a non-trivial nested pair.

    I was expecting to find a settable property: Family.Zorder = <value> and be able to just set it myself! Please advise how I can do this.

    Cheers

  • Hmmm... replying (without an answer) to my own post. The Layers are supposed to be very efficient... As I have 40 distinct tiling Zorders, would it be reasonable and/or sensible (!) to create 40 layers for the Zorders of iso tiles and then set the layer number programmatically, which does seem to be possible.

    Or perhaps that will have some unpleasant side-effect such as greatly increasing number of draw calls ?

  • mrexcessive - This is a five year old thread concerning Construct Classic, but I presume you're using Construct 2. You'd be much better off asking your question in the Construct 2 help section.

    Please be sure you check how old(and relevant) a thread is before asking questions in the future.

  • Yer... Well I did search around and this seemed to be the most relevant... didn't notice it was for Classic... Apologies! Will repost on a new thread as you suggest... thank you.

  • 'For each ordered' is a good way - it's not CPU intensive if it's not nested with any other loops.

    Sort by Y co-ordinate:

    + For each Sprite order by Sprite.Y ascending

    -> Sprite: send to front

    Just touching up on this old subject. With the loop above, it only works for instances of an object because you are forced to pick one. In Construct 2 (not classic), to have the loop set Z ordering for multiple objects, create a family of those objects then:

    + For each Family order by Family.Y ascending

    -> Family: send to front

    The only caveat is they all have to be in the same layer.

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