I’ve got the following piece of code:
spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, null, null, null, null, cam.TransformMatrix);
spriteBatch.Draw(_comicBackground, workspace, Color.AliceBlue);
foreach (LayoutField lf in comicStrip.LayoutFields)
{
spriteBatch.Draw(_layoutFieldBackground, new Rectangle(lf.PosX, lf.PosY, lf.Width, lf.Height), Color.White);
}
spriteBatch.End();
but regardless of SpriteSortMode (FrontToBack | BackToFront) background is always being displayed on top of the results of foreach loop, covering my layout in the result.
It’s not a show-stopper as I can draw my sprites in reverse order but I’d rather keep them in the order in which they should be drawn on the screen.
The
FrontToBackandBackToFrontsort modes require you to specify a sprite depth value in yourDraw()calls; see thelayerDepthparameter here. If you want to draw sprites in the order that you make theDraw()calls, useSpriteSortMode.DeferredorSpriteSortMode.Immediate.