Hello, genuine question, I've been racking my brains, but still can't figure out a solution.
What I want: To simulate the Z vector (x,y,z) in a 2D rendering Game, using something like layers when drawing.
Context: Game Engine using Monogame Framework to deal with Graphics.
Using the 2D Monogame Library.
How it works:
It draws things in the order that was requested.
So, first of all I ask it to draw the map grid(with layers) after the player.
The problem: even though I can achieve something close to what I want, using this approach of layers in the DrawMapGrid.
When the player is rendered it always will be above it all in the same last level, and I want one player to be in the layer 1, and the second player to be in the layer 2.
For example: in a bridge, the player in layer 2 is above it, and the player in the layer 1 is below, the player layer 1 need to be hidden when is crossing the bridge from below.
I imagine that recording the player layer level, and using a for loop to render the player right before the map grid of that exact layer can work. But it seems so wrong to me, render the player together with the map grid.
Thank you.
Game1.spriteBatch.Begin();
DrawMapGrid();
DrawPlayer(0);
DrawPlayerName(0);
Game1.spriteBatch.End();
private static void DrawMapGrid()
{
byte maxMapLayer = 3;
for (byte layer = 0; layer < maxMapLayer; layer++)
{
for (int x = 0; x < Constants.MAX_MAP_X; x++)
{
for (int y = 0; y < Constants.MAX_MAP_Y; y++)
{
DrawTile(x * 32, y * 32);
}
}
}
}