Depth Rendering in 2D pixel video game

Hi,
I am new to Monogame and I’ve just tried to use Monogame to create a simple pixel-graphics 2D video game. I’ve learned that whatever get rendered after in the code will be placed on those get rendered before. Is there any feature or library or piece of codes that handle the depth value (Z-value) in 2D environment? I am currently handle it manually and it’s so complicated and messy.
Thank you!

SpriteBatch has a feature for this. It is called SpriteSortMode. Pass a SpriteSortMode that respects layer depth (BackToFront or FrontToBack) with your SpriteBatch.Begin() call, and define a layerDepth value in your SpriteBatch.Draw() calls.

https://docs.monogame.net/api/Microsoft.Xna.Framework.Graphics.SpriteSortMode.html

2 Likes

Yeah it’s great if you want to kill your performance.

Just sort on per-entity basis. Still not great, but an alright middle ground between control and performance.

Thanks man, I’ll try it out