20 const BlendState blendState, ALLEGRO_TRANSFORM *pTransformation)
23 m_it = m_inactiveDrawables.begin();
25 m_sortMode = sortMode;
29 if (pTransformation != NULL) al_use_transform(pTransformation);
33 m_pTransformation = pTransformation;
36 m_blendState = blendState;
41 al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);
44 al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
56 if (m_pTransformation != NULL) al_use_transform(m_pTransformation);
61 std::sort(m_drawables.begin(), m_drawables.end(), CompareBackToFront());
65 std::sort(m_drawables.begin(), m_drawables.end(), CompareFrontToBack());
69 al_hold_bitmap_drawing(
true);
75 for (std::vector<Drawable *>::iterator it = m_drawables.begin(); it != m_drawables.end(); ++it)
77 if ((*it)->isBitmap) DrawBitmap(*it);
85 if (m_drawables.size() > 0) m_drawables.clear();
91 ALLEGRO_TRANSFORM identity;
92 al_identity_transform(&identity);
93 al_use_transform(&identity);
98 void SpriteBatch::DrawBitmap(Drawable *pDrawable)
100 al_draw_tinted_scaled_rotated_bitmap_region(
101 pDrawable->Union.pBitmap,
102 pDrawable->Union.sx, pDrawable->Union.sy,
103 pDrawable->Union.sw, pDrawable->Union.sh,
105 pDrawable->Union.cx, pDrawable->Union.cy,
106 pDrawable->x, pDrawable->y,
107 pDrawable->Union.scx, pDrawable->Union.scy,
108 pDrawable->Union.rotation, 0);
111 void SpriteBatch::DrawFont(Drawable *pDrawable)
113 al_draw_multiline_text(
114 pDrawable->Union.pFont,
116 pDrawable->x, pDrawable->y,
118 (
int)pDrawable->Union.align,
119 pDrawable->Union.text->c_str());
125 const Color color,
const TextAlign alignment,
const float drawDepth)
127 assert(m_isStarted &&
"Begin must be called before a Draw function can be run!");
131 if (m_it != m_inactiveDrawables.end())
138 pDrawable =
new Drawable();
139 m_inactiveDrawables.push_back(pDrawable);
140 m_it = m_inactiveDrawables.end();
143 pDrawable->isBitmap =
false;
145 pDrawable->Union.text = text;
146 pDrawable->Union.align = alignment;
148 pDrawable->x = position.
X;
149 pDrawable->y = position.
Y;
150 pDrawable->depth = drawDepth;
158 m_drawables.push_back(pDrawable);
166 const float rotation,
const float drawDepth)
168 assert(m_isStarted &&
"Begin must be called before a Draw function can be run!");
172 if (m_it != m_inactiveDrawables.end())
179 pDrawable =
new Drawable();
180 m_inactiveDrawables.push_back(pDrawable);
181 m_it = m_inactiveDrawables.end();
184 pDrawable->isBitmap =
true;
186 pDrawable->Union.sx = 0;
187 pDrawable->Union.sy = 0;
188 pDrawable->Union.sw = pTexture->
GetWidth();
189 pDrawable->Union.sh = pTexture->
GetHeight();
190 pDrawable->Union.cx = origin.
X;
191 pDrawable->Union.cy = origin.
Y;
192 pDrawable->Union.scx = scale.
X;
193 pDrawable->Union.scy = scale.
Y;
194 pDrawable->Union.rotation = rotation;
197 pDrawable->x = position.
X;
198 pDrawable->y = position.
Y;
199 pDrawable->depth = drawDepth;
203 DrawBitmap(pDrawable);
207 m_drawables.push_back(pDrawable);
214 const float rotation,
const float drawDepth)
216 assert(m_isStarted &&
"Begin must be called before a Draw function can be run!");
220 if (m_it != m_inactiveDrawables.end())
227 pDrawable =
new Drawable();
228 m_inactiveDrawables.push_back(pDrawable);
229 m_it = m_inactiveDrawables.end();
232 pDrawable->isBitmap =
true;
234 pDrawable->Union.cx = origin.
X;
235 pDrawable->Union.cy = origin.
Y;
236 pDrawable->Union.scx = scale.
X;
237 pDrawable->Union.scy = scale.
Y;
238 pDrawable->Union.rotation = rotation;
241 pDrawable->x = position.
X;
242 pDrawable->y = position.
Y;
243 pDrawable->depth = drawDepth;
245 pDrawable->Union.sx = (®ion)->
X;
246 pDrawable->Union.sy = (®ion)->
Y;
247 pDrawable->Union.sw = (®ion)->Width;
248 pDrawable->Union.sh = (®ion)->Height;
252 DrawBitmap(pDrawable);
256 m_drawables.push_back(pDrawable);
262 const float rotation,
float drawDepth)
265 color, origin, scale, rotation, drawDepth);
269 BlendState &blendState, ALLEGRO_TRANSFORM *pTransformation)
271 assert(m_isStarted &&
"Begin must be called before the settings can be retrieved.");
273 sortMode = m_sortMode;
274 blendState = m_blendState;
275 pTransformation = m_pTransformation;
Represents timing and framing values for texture animations.
virtual Texture * GetTexture() const
Gets a pointer to the texture of the animation.
virtual Region * GetCurrentFrame()
Gets a pointer to the current frame.
Represents a four-component color using red, green, blue, and alpha data.
ALLEGRO_COLOR GetAllegroColor() const
Get the color-equivalent allegro color.
Represents a font or true-type font.
virtual ALLEGRO_FONT * GetAllegroFont() const
Get the allegro font representation of the texture.
static int GetScreenWidth()
Gets the screen width in pixels.
Defines a rectangular region defined by a point, height, width.
unsigned short GetResourceID() const
Gets the ID of the resource.
void GetBatchSettings(SpriteSortMode &sortMode, BlendState &blendState, ALLEGRO_TRANSFORM *pTransformation)
Gets the current settings from the sprite batch.
void Begin(const SpriteSortMode sortMode=SpriteSortMode::Deferred, const BlendState blendState=BlendState::Alpha, ALLEGRO_TRANSFORM *pTransformation=NULL)
Begins a sprite batch operation.
void End()
Flushes the sprite batch and restores the device state to how it was before Begin was called.
void Draw(const Texture *pTexture, const Vector2 position, const Region region, const Color color=Color::White, const Vector2 origin=Vector2::ZERO, const Vector2 scale=Vector2::ONE, const float rotation=0, const float drawDepth=0)
Adds a sprite to a batch of sprites to be rendered.
void DrawString(const Font *pFont, std::string *text, const Vector2 position, const Color color=Color::White, const TextAlign alignment=TextAlign::Left, const float drawDepth=0)
Adds a string to a batch of sprites to be rendered.
Represents a 2D grid of texels.
int GetHeight() const
Gets the height of the texture in pixels.
int GetWidth() const
Gets the width of the texture in pixels.
virtual ALLEGRO_BITMAP * GetAllegroBitmap() const
Get the allegro bitmap representation of the texture.
Defines a vector with 2 components (x and y).
float Y
The y-coordinate of the vector.
float X
The x-coordinate of the vector.
Katana Engine is a library of classes, interfaces, and value types that provides a foundation for dev...
SpriteSortMode
Defines the methods for sorting sprites before rendering.
BlendState
Defines the way in which textures blending will be calculated.
TextAlign
Defines the states for text alignment.