You could have a DisplayManager
which contains some "layers", let's say you want 3 layers, bottom
, middle
and top
. These layers aka lists
contains the instances of the IDisplay
objects. IDisplay
is an interface with a Draw
function.
The DisplayManager
itself has an Update
or Draw
function, however you name it, and you call it between the SpriteBatch's
Begin
and End
function.
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
DisplayManager.Update(spriteBatch);
spriteBatch.End();
...
//In the DisplayManager class:
private static List<IDisplay> top = new List<IDisplay>();
private static List<IDisplay> middle = new List<IDisplay>();
private static List<IDisplay> bottom = new List<IDisplay>();
...
//In the DisplayManager class:
public static void Update(SpriteBatch batch){
for (i = 0; i < bottom.Count; i++)
{
bottom[i].Draw(batch);
}
for (i = 0; i < middle.Count; i++)
{
middle[i].Draw(batch);
}
for (i = 0; i < top.Count; i++)
{
top[i].Draw(batch);
}
}
Note the draw order in the Update function, first draw the "bottom" layer, then the middle and the top.