XaiJu
Lizardrive
Lizardrive

patreon


SEGA Megadrive game development #4

Manage ZOrder

It is not because we work with top-down 2D elements that we cannot suggest there is depth.  

This is what ZOrder does:


This was achieved by defining a Z position for each visible sprite and using it in the following function:


As you can see, we do not process the first 10 sprites (as we do not compare hero to himself, as well as to other elements which are mainly being used for UI and therefore should always be displayed on top of other elements). 


I also created a function to check if the sprite we intend to process the ZOrder of is near the hero. as modifying sprite’s depth can be CPU consuming. I decided to only process it for sprites in a 48 pixels radius from the hero.


There could be a lot more to be said about sprites and animation... but we will now proceed with controls... 


Next time! ;-)


More Creators