I'm trying out a prototype (see attached screenshot) where I have a whole bunch of sprites in a fake "depth". I'm trying to find a way to sort all of these objects so that they render from top to bottom, so that all things high up on the screen will render first (on the bottom) and gradually all other items are drawn on top of previous sprites.
How do I do this?
In an earlier stage I only had one moving character, which was a lot easier since I could compare that character's Y-position to all other elements (if their Y > Player Y then I would move them to a layer below, conversely I'd move things in front to a layer on top of the player)
Now that I'm introducing multiple moving elements I don't know how to formulate a function that does this. I think it should all hapen on one single layer and that I probably need to do this sorting every tick, but IDK.. I'm guessing I need a loop of some sort, but how do I write it?
Hope this makes sense, any help would be awesome