# Rotating sprites in allegro.

• 02-17-2011
~Kyo~
Rotating sprites in allegro.
This code works great, but only allows a 90 degree rotation of the sprite. I assume this is because of allegro and I think every other graphics lib assuming top left is 0,0 and going from there so I am only playing in one quad... I am wondering how to make it rotate all 360 degrees do I just make a correction factor based on the screen size or what?

Code:

```int main() {     ini();     player = load_bitmap("Player.bmp",NULL);     BUFFER = create_bitmap(scrx,scry);     while(!key[KEY_ESC])     {         int angle = fixatan2(mouse_y, mouse_x);         rotate_sprite(BUFFER,player,(scrx/2),(scry/2),angle);         show_mouse(BUFFER);         blit(BUFFER,screen,0,0,0,0,scrx,scry);     }         return 0; } END_OF_MAIN()```
Answered my own question. Subtracting half of the screen size from each var allows for 360 degree rotation. center the sprite by subbing half the size in x and y... Now to get a grappling hook working for movement...
• 02-18-2011
VirtualAce
Translate to origin, rotate, translate back to world.
• 02-20-2011
Eman
he doesn't have to translate...if he wants to simply rotate the sprite..i think he should just
use ftofix(angle) ...allegro has an angle from 0 to 256 i think. And it is fixed floating point something..
just replace ftofix(angle) in the rotate_sprite function
• 02-21-2011
VirtualAce
Quote:

he doesn't have to translate...if he wants to simply rotate the sprite..i think he should just
It depends on what coordinate space he is starting in. If his sprites are in the 4th quadrant then he must rotate back to the origin, rotate, and then translate back to the 4th quadrant. If he rotates in place he will rotate about the origin x,y units away from the origin which is not what he wants to do.
• 02-22-2011
~Kyo~
All I was really wanting the code to do was for lack of better terms have my sprite always face my mouse cursor...

Code:

```void Player::Set_angle(int x, int y)//x and y are the mouse pointer's x and y coords . {     angle = fixatan2(y-(y_coord+32), x-(x_coord+32)); }```
For allegro this line works perfectly in the end I will change the 32s to reflect the size of the bitmap that is loaded into memory till then this works great for testing the basics of the game I am trying to make.