Z order equals to Y Position ?

Get help using Construct 2

Post » Mon Jul 01, 2013 4:56 pm

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
B
7
S
3
G
3
Posts: 53
Reputation: 2,459

Post » Mon Jul 01, 2013 5:06 pm

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.Xionor2013-07-01 17:06:28
B
10
S
3
Posts: 233
Reputation: 1,537

Post » Mon Jul 01, 2013 5:08 pm

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.
B
24
S
9
G
7
Posts: 756
Reputation: 7,312

Post » Mon Jul 01, 2013 5:13 pm

Well, Im 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.
B
7
S
3
G
3
Posts: 53
Reputation: 2,459

Post » Mon Jul 01, 2013 5:25 pm

[QUOTE=vee41]
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.[/QUOTE]

Thanks. This did the trick. So far is really slow (it hangs), but Im gonna tweak it for a while and see why is that, and how can I fix it.
B
7
S
3
G
3
Posts: 53
Reputation: 2,459

Post » Mon Jul 01, 2013 5:32 pm

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/1a3JtTELLES08082013-07-01 17:33:05
Image
B
108
S
24
G
18
Posts: 1,376
Reputation: 22,830

Post » Mon Jul 01, 2013 5:36 pm

[QUOTE=perezbalen] [QUOTE=vee41]
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.[/QUOTE]

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

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.
B
24
S
9
G
7
Posts: 756
Reputation: 7,312

Post » Mon Jul 01, 2013 5:41 pm

CPUsage for small projects, without WEBGL ON, is so low, giving you no problems about it. But for large projects, you would assume that.
Image
B
108
S
24
G
18
Posts: 1,376
Reputation: 22,830

Post » Mon Jul 01, 2013 5:50 pm

[QUOTE=TELLES0808] CPUsage for small projects, without WEBGL ON, is so low, giving you no problems about it. But for large projects, you would assume that.[/QUOTE]

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. :)
B
24
S
9
G
7
Posts: 756
Reputation: 7,312

Post » Fri Jan 15, 2016 12:43 pm

Thanks for this! This thread was the perfect find!
B
33
S
10
G
6
Posts: 259
Reputation: 6,801

Next

Return to How do I....?

Who is online

Users browsing this forum: Lancifer, OddConfection and 25 guests