Gamedev Framework (gf)  0.9.0
A C++14 framework for 2D games
Public Member Functions | List of all members
gf::SpriteBatch Class Reference

A sprite batch. More...

#include <gf/SpriteBatch.h>

Public Member Functions

 SpriteBatch (RenderTarget &target)
 Constructor. More...
 
void begin ()
 Begin the batch. More...
 
void draw (Sprite &sprite, const RenderStates &states=RenderStates())
 Add a sprite to the batch. More...
 
void draw (const Texture &texture, Vector2f position, const RenderStates &states=RenderStates())
 Add a raw texture to the batch. More...
 
void draw (const Texture &texture, const RectF &textureRect, Vector2f position, const RenderStates &states=RenderStates())
 Add a portion of a raw texture to the batch. More...
 
void end ()
 End the batch. More...
 

Detailed Description

A sprite batch.

A sprite batch is responsible for minimizing the number of draw calls by concatenating the different calls for sprites.

Before using a sprite batch, you have to call begin(), then call draw() for each sprite you want to draw, and finally call end().

gf::SpriteBatch batch(renderer);
batch.begin();
batch.draw(sprite1);
batch.draw(sprite2);
batch.draw(sprite3);
batch.end();
See also
gf::Sprite

Constructor & Destructor Documentation

◆ SpriteBatch()

gf::SpriteBatch::SpriteBatch ( RenderTarget target)

Constructor.

Parameters
targetA render target where the sprites will be drawn

Member Function Documentation

◆ begin()

void gf::SpriteBatch::begin ( )

Begin the batch.

◆ draw() [1/3]

void gf::SpriteBatch::draw ( Sprite sprite,
const RenderStates states = RenderStates() 
)

Add a sprite to the batch.

You must call begin() before calling this function, and end() once you have finished to draw the sprites.

Parameters
spriteThe sprite to draw
statesThe render states

◆ draw() [2/3]

void gf::SpriteBatch::draw ( const Texture texture,
Vector2f  position,
const RenderStates states = RenderStates() 
)

Add a raw texture to the batch.

You must call begin() before calling this function, and end() once you have finished to draw the sprites.

Parameters
textureThe texture to draw
positionThe position of the texture
statesThe render states

◆ draw() [3/3]

void gf::SpriteBatch::draw ( const Texture texture,
const RectF textureRect,
Vector2f  position,
const RenderStates states = RenderStates() 
)

Add a portion of a raw texture to the batch.

You must call begin() before calling this function, and end() once you have finished to draw the sprites.

Parameters
textureThe texture to draw
textureRectThe sub-rectangle of the texture to draw
positionThe position of the texture
statesThe render states

◆ end()

void gf::SpriteBatch::end ( )

End the batch.