Z ordering

Discussion and feedback on Construct 2

Post » Thu Jun 09, 2011 6:53 am

How will Construct 2 do the Z ordering? Is it possible to have it number based this time, instead of just the "bring to front" and "bring to back", or is that the only way it can work?
B
134
S
65
G
16
Posts: 1,765
Reputation: 19,188

Post » Thu Jun 09, 2011 2:09 pm

It could be number based, but then what do you do when two objects, or even 20 objects, have the same number?

I thought layers were the best way to Z order things to their approximate location (background, mainground, foreground etc.), so that Z order within a layer isn't so important, so things like 'send to front/back' are sufficient. What are you trying to do that needs such fine control?

Incidentally 0.x supports Z ordering by number as well - use an ordered for-each over a private variable to send each instance to back, and they'll end up Z ordered by the private variable.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Thu Jun 09, 2011 2:52 pm

You would want the fine control for stuff like card games, isometric, and even sprite chains.
A floating point system like CC uses for z height might work, but it could use some organization like first object to a whole number remains on top, while the next sent there would go to 1.9, 1.8, etc, course that might be confusing at some point since logically those are bigger numbers.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Fri Jun 10, 2011 12:39 am

I get a lot of slow down looping through all the objects all the time, ordering them (using the for each object, and bring to front/back). But having a number system would help to slot things in easier, especially when your creating/destroying a lot. Using layers helps, but its not always appropriate because of how dynamic you may want the sorting to be, such as with an isometric game.
B
134
S
65
G
16
Posts: 1,765
Reputation: 19,188

Post » Fri Jun 10, 2011 1:26 am

If C2 implements the orthogonal projection feature C1 has, that could do the same thing (automatically sorted by Z value). With that, if two objects are on the same depth value, then it uses the regular sorting.

Another benefit of that is depending on the situation, it might mean you don't have to run a for each loop through all the objects, making it more efficient. The only problem with that is it means you couldn't use that method of sorting and have z depth at the same time. Perhaps if orthogonal projection could be used on a per-layer basis, or does that get too weird?
Moderator
B
87
S
32
G
33
Posts: 3,005
Reputation: 27,397

Post » Fri Jun 10, 2011 1:43 am

HTML5 canvas doesn't really have anything corresponding to orthogonal projection - it just depends on the order you draw them.

@alspal, how much slow down do you get? I thought the for-each-ordered and send-to-back conditions were efficiently coded. Does it really make a big fps difference toggling that one event?
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Fri Jun 10, 2011 2:14 am

Your right actually, maybe its because I was using a lot more sprites before but it seems to work fine now. My FPS only goes from about 1200 to 550 when I use always for each ordering (2000 objects and not much other code yet). I guess its fine the way it is, sorry.
B
134
S
65
G
16
Posts: 1,765
Reputation: 19,188

Post » Fri Feb 10, 2012 11:51 am

Bump: z-ordering with foreach and "send to top of layer" may be just as efficient, but it sure makes a mess out of your code - especially if you have to order several different objects that aren't grouped into a family.

With number based z-ordering, I can keep track of the numbers myself, and assure there is never a collision (order numbers being equal). Even if there is, construct could draw whatever first (the first one that gets called in the draw loop is behind) without any other special logic to handle such z-order collisions.

It sounds exactly like the sort of problem a game creating engine should abstract away.Fimbul2012-02-10 11:55:16
B
35
S
8
G
8
Posts: 532
Reputation: 6,868

Post » Mon Feb 13, 2012 11:18 am

What about an Index, layer 1, all the sprites inside it will have an auto-increased index, so, my last sprite will be the 1.14, where 1 is from the layer, 14 is from his Z order in that layer. This way, none of them will have the same index and you'll fine control them.

Sometimes I use Fireworks, Corel, etc, and there you can feel what the alspal is asking for. In Fireworks don't have the index, but have a list, where the top names are on the top of that specific layer, and top layer folders, where the top layer folder on the list is the top layer showing up.

What it means is the easy of use. Clicking, dragging and dropping a layer folder is much more easy and intuitive than any other method. And when you place your sprites inside that layer, they will be show inside that layer as a list.

So, I would suggest, why Our Layer List can't have a list listing all the sprites inside that layer, ordering them by his Z order, with unique Z order for each one?


Taking advantage of this situation, what about the UID being show by his side, in (UID)? Because it being hard to remember or check everytime the UID, but using this, you will make sure to have the correctly UID at least of the objects on the canvas.

More one suggestion, some drop-down menus by right clicking, like "blocking for edition" (that lock on the image), "hidden", etc.

Edited: After testing how to reproduce adventure games with C2, believe me, the Z ordering system can difficult it near to the impossible.
It's all because of the miss of an index where you can organize what is in the front and what is behind the player, who will walk around in a "perspective" World.

I tried to fix the origin point in the bottom, and check if it's down or up the player origin, and it worked, but when you send the sprite from behind, it hidden behind all other sprites too, but to make it perfect, I tried to organize it with and Code Indexed for each sprite. At least now, with 10 game objects on the Canvas, I have written near to 200 lines of code only to organize what is behind and what is on the front of the player.
ImageImageImageImageImageImage
B
92
S
19
G
12
Posts: 1,192
Reputation: 18,276

Post » Mon Feb 13, 2012 4:06 pm

All we need is for each ordered. That will make it easy to do Z ordering in one event.

For each ordered: sortfamily.y (ascending)
- send to front

Or use a instance variable instead for more custom stuff.Arima2012-02-13 16:08:10
Moderator
B
87
S
32
G
33
Posts: 3,005
Reputation: 27,397

Next

Return to Construct 2 General

Who is online

Users browsing this forum: humanescape, NetOne and 3 guests