Rotating sprites in allegro.

This is a discussion on Rotating sprites in allegro. within the Game Programming forums, part of the General Programming Boards category; This code works great, but only allows a 90 degree rotation of the sprite. I assume this is because of ...

  1. #1
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320

    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...
    Last edited by ~Kyo~; 02-17-2011 at 10:54 AM.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Translate to origin, rotate, translate back to world.

  3. #3
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    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
    You ended that sentence with a preposition...Bastard!

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    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.

  5. #5
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with Allegro sprites
    By godly 20 in forum C++ Programming
    Replies: 16
    Last Post: 01-18-2011, 04:24 PM
  2. Game Programming FAQ
    By TechWins in forum Game Programming
    Replies: 5
    Last Post: 09-29-2004, 03:00 AM
  3. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-21-2002, 12:35 AM
  4. Sprites n Allegro
    By Paninaro in forum Game Programming
    Replies: 1
    Last Post: 07-07-2002, 10:28 AM
  5. + Sprites n allegro
    By Paninaro in forum Game Programming
    Replies: 3
    Last Post: 07-07-2002, 04:15 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21