So I am making this top-down RPG. For a sprite in the game, there are two objects: (1)the image of the sprite, and (2)the invisible collision box.
These applies to all sprites in-game, which includes NPC.
I tried to make it so that when the hero is in front of an npc(since it's top-down, that means he is on a larger Y coordinate), his image is above the image of the npc, and when the hero is behind the npc, his image is then put under the npc sprite.
I made this by checking the Y coordinates however it only applies to a single NPC - what if there are hundreds of npc sprites on the layout? It seems impractical to check each and every one. And also there is a possible case that I will spawn two of the same npc class on a layout.
I don't know how the event will go so it could pick up the correct object and since the sprite is actually two objects in itself(image and collBox), I wonder how to check the Y coord of the box and apply it to the correct positioning to the image he is assosciated with.