-
Notifications
You must be signed in to change notification settings - Fork 2
Spritebatch
A sprite batch is used to group multiple sprites together and draw them all in one setting. The main motivation for such a system is efficiency. Drawing each object individually can be really slow, depending on the situation.
You create a batch just like you'd create a normal game object. SpriteBatch derives from GameObject, so it will offer much of the same functionality. For example, you'll be able to draw a batch using the same Draw call or you can add it onto a layer.
Before you can draw anything with a batch, you need to give it either a Texture or a TextureAtlas. Only one can be active at a time. After supplying the batch with either, you can start adding objects to be drawn.
SpriteBatch has only one function you need to call to add a sprite: AddSprite. It only has one required argument, which is a transform for an object you want to draw. You can keep a pointer to the transform you added to modify it while it's being used by the batch. All changes will be automatically reflected.
AddSprite also has a few optional arguments:
-
atlasName- If you're using aTextureAtlas, you can specify the name of the texture to be used. -
color- To be used for tinting the texture -
texCoords- Custom texture coordinates. The coordinates will be automatically fetched from the atlas ifatlasNamehas been supplied.
- By default
SpriteBatchadopts theTransformpointers passed to it and deletes them when appropriate. If you want to take care of the pointers yourself, you need to passfalseto theSpriteBatchconstructor.