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?
Develop games in your browser. Powerful, performant & highly capable.
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.
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.
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!