An efficient Z-ordering system for sprites?

Get help using Construct 2

Post » Thu Apr 14, 2016 3:49 am

In typical jRPG, 2D view like Zelda, you have a lot of sprites of trees, shrubs, decals, etc that are quite static.

But then you have the player, monsters, etc that move around and so you have to constantly update their position and determine which sprites go on top or below. ie. When the player is "behind" a tree, it should have the tree sprite on top.

I know the basic approach that is to compare them on the Y axis, but my concern is if the map is huge, and there's a LOT of objects to compare to, it would be quite CPU intensive and so on mobiles, performance would suffer.

Is there a more efficient approach?
B
70
S
24
G
19
Posts: 1,757
Reputation: 17,616

Post » Thu Apr 14, 2016 4:17 am

You can reduce the amount to compare somehow. Only sprites on screen would be one example. Another would be only objects overlapping the player or enemies.
B
94
S
33
G
118
Posts: 5,396
Reputation: 75,853

Post » Thu Apr 14, 2016 4:32 am

As R0j0 said, I limit it to the viewport. I also only z-sort when the player is moving (which is often, but still). You could potentially get away with z-sorting less often than every single tick, but it depends on how fast-moving your game is.
B
103
S
38
G
19
Posts: 962
Reputation: 17,996

Post » Thu Apr 14, 2016 7:34 am

Thanks @R0J0hound & @C-7

It's for all the enemy sprites as well as player & squad, running through the forest and fighting fast paced.

I thought about doing overlapping but those checks are brutal on CPU when there's a lot of objects to check. :)

I'll play around with distance checks, pick nearest and LOS in combination with checking every X time rather than every tic. Thanks!
B
70
S
24
G
19
Posts: 1,757
Reputation: 17,616


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 31 guests