Dynamic Z ordering

Get help using Construct 3!

Post » Mon Jun 19, 2017 3:58 am

This is less of a "How do I" and more of a "can I do this more optimized?"

I have a fairly simple event setup for dynamic z ordering using Y pos on a family of objects:

+ System: Every tick
----+ Zorder: Is visible
----+ System: For each Zorder
----+ System: Pick Zorder where Zorder.​Y > PlayerController.​Y
-----> Zorder: Move in front PlayerAnim
----+ System: Else
----+ Zorder: Is visible
----+ System: For each Zorder
----+ System: Pick Zorder where Zorder.​Y < PlayerController.​Y
-----> Zorder: Move behind PlayerAnim

This works well for my needs, and it handles it fairly well, i think. 67 sprites (all animated braziers) settles at around 5% CPU usage while walking up and down the layout constantly.
What I'm wondering is if anyone has done, or knows of something, more efficient CPU wise to do this? or is this about as clean as it can get?


quickedit. realized the pick should be before the loop. swapped them around, and its to about 4% now, which is nice, but main question still stands, thanks!
B
13
S
3
G
1
Posts: 12
Reputation: 1,241

Post » Mon Jun 19, 2017 5:31 am

Add everything that needs z-ordering to 1 family.

Every 0.1 second
Z-order is on screen
For each z-order order by z-order.Y ascending
Z-order move to top of layer
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,592

Post » Mon Jun 19, 2017 5:48 am

i love using rex z-order plugin:
http://c2rexplugins.weebly.com/rex_zsorter.html
B
43
S
16
G
7
Posts: 55
Reputation: 6,568

Post » Mon Jun 19, 2017 5:56 am

thanks @lennaert dont know why i didn't think of using x based seconds to do that computation. the exact method you posted certainly helped, though I had to change it a bit for my use case. I ended up going with

+ System: Every 0.1 seconds
+ Zorder: Is on-screen
----+ System: Pick Zorder where Zorder.​Y > PlayerController.​Y
----+ System: For each Zorder order by Zorder.​Y ascending
-----> Zorder: Move in front PlayerAnim
----+ System: Else
----+ System: Pick Zorder where Zorder.​Y < PlayerController.​Y
----+ System: For each Zorder order by Zorder.​Y ascending
-----> Zorder: Move behind PlayerAnim

to achieve my desired effect:
Image

I cant just move everything to the top layer, as it messes up when the player would walk in front of the objects, but your advice on the 0.1 seconds timer as well as using on-screen instead of is visible, and also along with using a for each ordered bought CPU usage down to a much better 2%. Im sure that it will scale much better on things like overworld maps as well.
B
13
S
3
G
1
Posts: 12
Reputation: 1,241

Post » Mon Jun 19, 2017 5:57 am

sagispin wrote:i love using rex z-order plugin:
http://c2rexplugins.weebly.com/rex_zsorter.html


Unfortunately I dont know if that plugin would work, considering im on C3 and not C2. I also just enjoy figuring out how to do things without plugins and just using pure event sheets. that plugin did pop up in more than a few threads though!
B
13
S
3
G
1
Posts: 12
Reputation: 1,241

Post » Mon Jun 19, 2017 6:56 am

Your welcome, rovacado. There are many variations of the zordering approach, as in your case, you just need to find one that suits your mechanic and setup well :)

the 0.1 seconds interval is a very good one when it comes to performance btw, you can use it in many occasions.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,592

Post » Mon Jun 19, 2017 8:39 pm

Bring them into a family. Add an instance variable representing Y.

+ (no conditions)
-> family: Set Y_Order to Self.​Y
-> System: Sort family Z order by Y_Order

And its done. Think they need to be on the same layer.

Additional, if the player is the only moving thing, start with (player) Is overlapping (Family), update for family and player (player is not in the family picklist). Now you can execute this 1000 times in one tick, dont matter.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Mon Jun 26, 2017 11:49 pm

@99Instances2Go
Didn't manage to make it work. Would you post a .capx, please ? Thanks in advance !
B
38
S
16
G
5
Posts: 269
Reputation: 5,964

Post » Thu Nov 09, 2017 6:35 pm

rovacado wrote:thanks @lennaert dont know why i didn't think of using x based seconds to do that computation. the exact method you posted certainly helped, though I had to change it a bit for my use case. I ended up going with

+ System: Every 0.1 seconds
+ Zorder: Is on-screen
----+ System: Pick Zorder where Zorder.​Y > PlayerController.​Y
----+ System: For each Zorder order by Zorder.​Y ascending
-----> Zorder: Move in front PlayerAnim
----+ System: Else
----+ System: Pick Zorder where Zorder.​Y < PlayerController.​Y
----+ System: For each Zorder order by Zorder.​Y ascending
-----> Zorder: Move behind PlayerAnim

to achieve my desired effect:
Image

I cant just move everything to the top layer, as it messes up when the player would walk in front of the objects, but your advice on the 0.1 seconds timer as well as using on-screen instead of is visible, and also along with using a for each ordered bought CPU usage down to a much better 2%. Im sure that it will scale much better on things like overworld maps as well.


LIKE THIS...
Image

BUT HOW SOLVE THIS...
Image


CODE:

Image
B
8
S
1
Posts: 26
Reputation: 452

Post » Fri Nov 10, 2017 8:52 am

FWIW, using "move to front" or "move to back" in a loop is very inefficient. This is why we made the System 'Sort Z order' action - it's much more efficient for ordering lots of instances.
Scirra Founder
B
403
S
238
G
89
Posts: 24,654
Reputation: 196,155

Next

Return to How do I...?

Who is online

Users browsing this forum: No registered users and 0 guests