Last Updated September 23, 2008
SpriteBatch is used to draw rectangular sprites to the screen, the sprite image is a part of a texture, or a whole texture. The spriteBatch.Draw(...) member specifies the texture to draw. The reason it is called a 'batch' is that it draws a group (batch) of sprites to with the same sort order and render state.
If possible use one texture for all of your sprites
It is possible to specify the depth of sprites using a draw() function like;
public void Draw ( Texture2D texture, Vector2 position, Nullable<Rectangle> sourceRectangle, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth )
Then telling sprite batch to order them BacktoFront, but this can cause a slight delay as the list is sorted.
Ideally we should not switch texture in order to avoid stalling the GPU pipeline (default behaviour). Changing texture can be expensive. The optimal way to deal with sprites is to use one texture and to render them in back to front order in immediate mode
Sprites are not drawn until End is called. End will apply graphics device settings and draw all the sprites in one batch, in the same order calls to Draw were received. This mode allows Draw calls to two or more instances of SpriteBatch without introducing conflicting graphics device settings. SpriteBatch defaults to Deferred mode.
Same as Deferred mode, except sprites are sorted by depth in back-to-front order prior to drawing. This procedure is recommended when drawing transparent sprites of varying depths.
Same as Deferred mode, except sprites are sorted by depth in front-to-back order prior to drawing. This procedure is recommended when drawing opaque sprites of varying depths.
Begin will apply new graphics device settings, and sprites will be drawn within each Draw call. In Immediate mode there can only be one active SpriteBatch instance without introducing conflicting device settings. Immediate mode is faster than Deferred mode.
Same as Deferred mode, except sprites are sorted by texture prior to drawing. This can improve performance when drawing non-overlapping sprites of uniform depth.
Shawn Hargreaves Blog; SpriteBatch and SpriteSortMode, SpriteBatch sorting part 2, Return of the SpriteBatch: sorting part 3
© Ken Power 2011