The usual way to go about this is by constantly updating each sprite’s draw order. For instance, in SpriteKit the zPosition
property changes how a sprite is drawn relative to other sprites.
What you’ll need to do is:
- find out how draw order of sprites can be changed in libgdx - there is hopefully some kind of “z order” or “draw order” or “depth” property
- set the property based on the sprite’s y coordinate, or simply set it to the sprite’s Y coordinate (you may need to inverse it though depending on whether positive or negative z order makes sprites come out in front of others)
- update this property either every frame, or whenever the Y coordinate changes (ie during movement) - the latter is preferred if most of the sprites do not move most of the time
This will ensure proper depth sorting of the sprites with the map but also with other nearby sprites.