If these are each separate DrawableGameComponents, you should set the DrawOrder property of each component so that they draw in the correct order.
To make it more manageable as you add more components, the DrawOrder should be an enum:
/* DisplayLayer.cs */
public enum DisplayLayer
{
Background, //back-layer
Particles,
Player,
MenuBack,
MenuFront //front-layer
}
public class MyComponent : DrawableGameComponent
{
public MyComponent(Game game) : base(game)
{
this.DrawOrder = (int)DisplayLayer.Background;
}
/* etc. */
}
If this is all being drawn within a single DrawableGameComponent, then you should take @Andrew's advice and simply draw them in the correct order. If for some reason you can't do that, you can still have the clarity of enums when using layerDepth by simply normalizing the value of the enum to be between 0 and 1:
/* DisplayLayer.cs */
public enum DisplayLayer
{
MenuFront, //front-layer
MenuBack,
Player,
Particles,
Background, //back-layer
MAX_LAYER //Do not use this as a layer
}
public void Draw()
{
spriteBatch.Begin(SpriteSortMode.BackToFront);
foreach(Thingy thingy in thingys)
spriteBatch.Draw(/* blah blah */, (float)thingy.DisplayLayer/(float)DisplayLayer.MAX_LAYER);
spriteBatch.End();
}
(The ordering of the enum is reversed because layerDepth uses lower numbers for the front-layer rather than the back-layer)