|
rotating animated sprites |
Toast9
Member #15,893
February 2015
|
Is there a way to rotate an animated sprite? I see that you can rotate a bitmap, but I can't seem to find anything on rotating a sprite(specific area of the bitmap) in allegro 5. The older allegro versions seem to have many sprite rotations, but I'm stuck with allegro 5 only. I have an animated sprite that needs rotating! Any ideas? |
Erin Maus
Member #7,537
July 2006
|
You probably want this method: http://alleg.sourceforge.net/a5docs/refman/graphics.html#al_draw_tinted_scaled_rotated_bitmap_region --- |
jmasterx
Member #11,410
October 2009
|
Even if Allegro did not have this function, you can rotate anything yourself using transformations. For example, this function I have to rotate text: 1
2 void GraphicsContext::resetTransform()
3 {
4 ALLEGRO_TRANSFORM t;
5 al_identity_transform(&t);
6 al_use_transform(&t);
7 }
8
9 void GraphicsContext::useTransform( Transformation& t )
10 {
11 al_use_transform(&t.getTransform());
12 }
13
14 int GraphicsContext::drawRotatedText( const std::string& text,agui::Font* font,const agui::Color& color, int x, int y, float deg, int flags )
15 {
16 int fx = font->getTextWidth(text) / 2;
17 int fy = font->getLineHeight() / 2;
18 m_transform.identity();
19 m_transform.translate(-fx,-fy);
20 m_transform.rotate(deg);
21 m_transform.translate(x,y);
22 useTransform(m_transform);
23 drawText(text,font,color,0,0,flags);
24 resetTransform();
25 return fx * 2;
26 }
Agui GUI API -> https://github.com/jmasterx/Agui |
|