Dynamic Z ordering

Get help using Construct 3!

Post » Wed Nov 22, 2017 2:45 pm

Ashley wrote: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.


Hi @Ashley

Ive just seen this.

I supose it is to do with z-sorting every run of a loop compared to z-sorting all at the end

So would it be correct to assume that this recommendation is also applicable to something like

For Each "ZObject" > in order of instance variable Z (ascending) > move to XY
ZObject move to bottom of layer

(as this will process in order of individual instance Z variable,
thus the objects will appear in the correct Z order naturally)

so would actually be better to do like

For Each "ZObject" move to XY
then Sort all ZObjects together according to ivarZ

So now they are moved first in any order then Z sorted all at once after the loop

?

cheers
Last edited by NetOne on Wed Nov 22, 2017 8:11 pm, edited 3 times in total.
My in work shmup game CYBERSTORM DEVLOG - "That Terminator is out there. It can't be bargained with. It can't be reasoned with. It doesn't feel pity, or remorse, or fear. And it absolutely will not stop, ever, until you are dead"
B
50
S
26
G
7
Posts: 402
Reputation: 8,685

Post » Wed Nov 22, 2017 3:14 pm

Changing Z order in a loop is inefficient because it changes the Z order repeatedly. The 'sort Z order' action is efficient because it does the sorting, then changes the Z order once at the end. So you should basically only use the 'sort Z order' actions for large numbers of instances. However if you just update the instance variable it uses in a loop, that's fine, because updating an instance variable doesn't itself change Z order.
Scirra Founder
B
408
S
242
G
92
Posts: 24,931
Reputation: 198,725

Post » Wed Nov 22, 2017 3:21 pm

Ashley wrote:Changing Z order in a loop is inefficient because it changes the Z order repeatedly. The 'sort Z order' action is efficient because it does the sorting, then changes the Z order once at the end. So you should basically only use the 'sort Z order' actions for large numbers of instances. However if you just update the instance variable it uses in a loop, that's fine, because updating an instance variable doesn't itself change Z order.


Thanks, sorry yes I missed the "Move to Top/Bottom in my example above. (will edit)

OK then, I am processing all the enemies and environmental objects in my game (pretty much everything you see on screen) in this inefficient way, every tick!

(And here is me still being impressed with the performance !)

Cheers
My in work shmup game CYBERSTORM DEVLOG - "That Terminator is out there. It can't be bargained with. It can't be reasoned with. It doesn't feel pity, or remorse, or fear. And it absolutely will not stop, ever, until you are dead"
B
50
S
26
G
7
Posts: 402
Reputation: 8,685

Post » Wed Nov 22, 2017 8:11 pm

Nice!

I was starting to see dips to 54 fps in current build when getting above 40 enemies on screen

this simple change has taken me back to 60fps

thanks !
My in work shmup game CYBERSTORM DEVLOG - "That Terminator is out there. It can't be bargained with. It can't be reasoned with. It doesn't feel pity, or remorse, or fear. And it absolutely will not stop, ever, until you are dead"
B
50
S
26
G
7
Posts: 402
Reputation: 8,685

Previous

Return to How do I...?

Who is online

Users browsing this forum: RetroInsight and 0 guests