Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » rotating animated sprites

This thread is locked; no one can reply to it. rss feed Print
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
avatar

---
ItsyRealm, a quirky 2D/3D RPG where you fight, skill, and explore in a medieval world with horrors unimaginable.
they / she

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:

#SelectExpand
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 }

Go to: