Set Z-Order With Number

New releases and general discussions.

Post » Sun Jan 18, 2009 6:30 pm

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.
Moderator
B
97
S
36
G
19
Posts: 1,584
Reputation: 17,692

Post » Sun Jan 18, 2009 6:34 pm

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).
Moderator
B
87
S
32
G
33
Posts: 3,005
Reputation: 27,397

Post » Sun Jan 18, 2009 7:26 pm

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.
B
3
S
2
G
4
Posts: 271
Reputation: 2,017

Post » Sun Jan 18, 2009 8:47 pm

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.
Moderator
B
97
S
36
G
19
Posts: 1,584
Reputation: 17,692

Post » Sun Jan 18, 2009 8:53 pm

'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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,468

Post » Mon Jan 19, 2009 6:42 am

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.
B
3
S
2
G
4
Posts: 271
Reputation: 2,017

Post » Mon Sep 15, 2014 8:18 am

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
B
9
S
3
Posts: 23
Reputation: 646

Post » Mon Sep 15, 2014 8:26 am

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 ?
B
9
S
3
Posts: 23
Reputation: 646

Post » Mon Sep 15, 2014 1:43 pm

@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.
Moderator
B
97
S
36
G
19
Posts: 1,584
Reputation: 17,692

Post » Mon Sep 15, 2014 2:54 pm

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.
B
9
S
3
Posts: 23
Reputation: 646

Next

Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 0 guests