Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » allegro 5 c++ draw rotated frame

Credits go to Trent Gamblin for helping out!
This thread is locked; no one can reply to it. rss feed Print
allegro 5 c++ draw rotated frame
bleepBlop
Member #14,822
January 2013

I am trying to draw frames which I would then rotate from a bitmap, however, the image only seems to be drawn in the corner of the screen not in the place that the sprite has the position put.

My method to draw frames and rotate is :

void drawFrame(SPRITE *spr,ALLEGRO_BITMAP *source, int columns)
{
int fx = (spr->curFrame % columns) * spr->width;
int fy = spr->animRow * spr->height;

ALLEGRO_BITMAP *bitmap = al_create_bitmap(32,32);
al_set_target_bitmap(bitmap);
al_draw_bitmap_region(source,fx,fy,spr->width, spr->height,spr->x-spr->width / 2, spr->y-spr->height/2,0);
al_set_target_bitmap(al_get_backbuffer(display));
al_draw_rotated_bitmap(bitmap, spr->width/2, spr->height/2,spr->x-spr->width / 2, spr->y-spr->height/2,ALLEGRO_PI, 0);
al_draw_rectangle(spr->x - spr->width/2, spr->y - spr->height/2,spr->x + spr->width/2, spr->y + spr->height/2,al_map_rgb(255,255,255),1.0);
}

It just doesn't seem to follow the actual x at all, it basically goes constantly to 0 width and 0 height, is there a better (functional) way of doing this? My whole code is : http://pastebin.com/XAhf9HAT

Thanks for the help.

Trent Gamblin
Member #261
April 2000
avatar

Look at the documentation for al_draw_rotated_bitmap again. It says dx and dy are the point where cx, cy is drawn, not the top left.

bleepBlop
Member #14,822
January 2013

It still seems to just be drawn in the top left corner and only be seen when the x and y goes there, it never stays on the image itself. It's like the x and y (spr->x and spr->y) does not update for the image itself.

So I don't know, maybe drawing the frame does not function with then drawing a rotated image? I can't find anywhere any example of someone doing this so I can do some checking.
Any idea how to do this?

*EDIT: FIXED, read up a bit on it and I was making a mistake while changing the target.

Go to: