SpriteBatch

A sprite batch is a collection of sprites (2D textured planes).

Note

Remember that you need to put all custom code in a custom scene renderer to include it in the composition.

Xenko offers a easy way to deal will batches of sprites through the class. You can use this class to regroup, update, and display sprites efficiently.

You can specify the size of your batch size. This isn't the maximum number of sprites the SpriteBatch is able to display, but the maximum number of sprites it can store before drawing.

Code: Setting the batch size

You can also set states like the ones discussed on the Pipeline state page.

Code: Drawing a sprite batch

There are five modes to draw a sprite batch. They are enumerated in the enum:

  • Immediate: the sprites are draw after each each @'Xenko.Graphics.SpriteBatch.Draw' call
  • Texture: Deferred mode but sprites are sorted based on their texture to reduce effect parameters update
  • BackToFront: Deferred mode with a sort based on the z-order of the sprites
  • FrontToBack: Deferred mode with a sort based on the z-order of the spritesTo set the mode, specify it in the @'Xenko.Graphics.SpriteBatch.Begin' method.

Code: Deferred drawing of the sprite batch

  • rotation
  • scale
  • depth
  • center offset

Code: More complex sprite batch drawing