I'm trying to make a game with a perspective like the old RPGs.
If the Playersprite (or any NPCs sprite, moving objects like flying arrows...) is in front of a tree, it should be in front of it on the z-order. Is the Player behind the tree its Z-Order should be behind.
Actually this is no problem with this piece of code:
But if the Player decides to build a castle out of many walls, surrounded by many trees with lots of static objects around (around 1000 objects on screen might happen), this code uses a lot of horsepower to rearrange the Z-order every tick.
I made a small example here: https://drive.google.com/file/d/0B0hkmULXH76qTnFzaDlVWTllU3c/view?usp=sharing
If you press space, new trees will spawn. If you make enough in Debugmode you can see it uses way to much ressources for just rearranging the order.
Now my question: Is there a way to keep the Z-order of the static objects (like trees and walls) and just rearrange the Z-order of moving things?
I aready tried to create a pixel for every y-coordinate on screen which is in the z-order-family and everything that moves is set in front of the pixel with the same y-coordinate. But somehow it didn't work very well - even spawning a pixel for every y-coordinate on start of layout takes ages on larger layouts.
If there would be a way to pick the next object with a higher or lower y-coordinate on Layout, I would set the moving object behind or in front of it...
So far my thoughts about the problem. If you have ideas, feel free to tell me, i'd appreciate it.