Allegro sprite animation?

This is a discussion on Allegro sprite animation? within the C++ Programming forums, part of the General Programming Boards category; Ok so this is the image which contains all possible movements: http://dc251.4shared.com/img/7j1ytD2...rite-anim2.bmp And this is the code that moves the ...

  1. #1
    Registered User godly 20's Avatar
    Join Date
    Jan 2011
    Location
    Italy
    Posts
    29

    Question Allegro sprite animation?

    Ok so this is the image which contains all possible movements:http://dc251.4shared.com/img/7j1ytD2...rite-anim2.bmp
    And this is the code that moves the sprite:
    Code:
    if(key [KEY_LEFT]) x-=1 ; //walks left
                if((key [KEY_LEFT]) && (key [KEY_R])) x-=2; //runs left
                if(key [KEY_RIGHT]) x+=1; // walks right
                if((key [KEY_RIGHT]) && (key [KEY_R])) x+=2; //runs right     
                if(key [KEY_DOWN]) y+=1; //walks down
                if((key [KEY_DOWN]) && (key [KEY_R])) y+=2; //runs down       
                if(key [KEY_UP]) y-=1; // walk up
                if((key [KEY_UP]) && (key [KEY_R])) y-=2; //runs up
    How can i make it do the right animation? Please HELP!!
    Last edited by godly 20; 01-20-2011 at 08:54 AM.

  2. #2
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Have you read this: http://www.loomsoft.net/resources/al...ut_lesson7.htm

    I will have a look myself at how to do it meanwhile.

    EDIT:
    I think you need to have all the possible movements in separate frames
    Last edited by Eman; 01-20-2011 at 09:15 AM.
    You ended that sentence with a preposition...Bastard!

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,529
    I'm assuming that you can blit out of a portion of the bitmap?

    When you load your character bitmap, set up a struct something like this
    Code:
    #define NUM_DIRECTIONS 4
    #define NUM_POSES 4
    struct character_anim {
        int x, y, w, h;
    } anim[NUM_DIRECTIONS][NUM_POSES];
    You'll be repeating the centre pose, by drawing 1, 2, 3, 2


    When you're actually moving, add this
    Code:
    if((key [KEY_LEFT]) && (key [KEY_R])) {
        pose = ( pose + 1 ) % NUM_POSES;
        dirn = 0;
        x-=2;
    }
    When you've moved, simply blit out from anim[dirn][pose]
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Animation class not working
    By VirtualAce in forum Game Programming
    Replies: 5
    Last Post: 03-02-2005, 05:48 AM
  2. Game Programming FAQ
    By TechWins in forum Game Programming
    Replies: 5
    Last Post: 09-29-2004, 02:00 AM
  3. sprite rotation in allegro
    By thedumbmutt in forum Game Programming
    Replies: 4
    Last Post: 01-14-2003, 07:43 AM
  4. problem in allegro with sprite leaving trail
    By Leeman_s in forum C++ Programming
    Replies: 18
    Last Post: 09-13-2002, 03:04 PM
  5. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-20-2002, 11:35 PM

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