2D Game Dev – Part 7.2: Basic Animation in Allegro 5

This post is a portion of Part 7 in my on going series about 2D Game Development using the Allegro 5 library. These posts are in course order. You can see all of the posts in this course by clicking the “2D Game Development” button at the top of this site.

It is time to add basic animation to our programs. You will see in this video,  if we cycle still images in order we can trick the eye into believing the object we are seeing on the screen is really moving. Pay attention to the variables used and how the cycling control works.

Full source can be found here

Posted in 2D Game Dev, Allegro, C++, Code, Game Dev, Part 7, Tutorial
12 Comments » for 2D Game Dev – Part 7.2: Basic Animation in Allegro 5
  1. Jacob says:

    hey mike i am having a bit of a problem when i run this program it brings up a window that says “unhandled exeption at 0x100306ee in Sprites!.exe: 0xC0000005: Access violation reading location 0×00000014.” then it has two buttons that say break or? continue, if i break it takes me to tidtable.c and if i continue it takes me back to the same option, this has happened before and i had to reinstall everything in order to fix it could you help me?

    • Mike says:

      It sounds like the image you are trying to access is not in the correct folder. Either that, or you are trying to read outside of the bounds of the image.

    • Tom says:

      I had the same issue Jacob. It was fixed by checking the images are in their expected location.

      If you ever encounter errors that you’re unsure about, try commenting out some lines and running it to see if you get the error. While this isn’t a definite way to find the issue, it will help you 80% of the time.

  2. Jacob says:

    i figured it out i just forgot the .bmp thanks though…

  3. AC says:

    Hey Mike,

    just wanted to let you know these are some incredible tutorials. i’ve been following along and have basically run up to 7.2 in the last day and a half (addicted to this series, for sure).

    Maybe I’m getting a little ahead of myself since there are 7 more lessons left, but during Lesson 5 you mentioned that we now have the tools to create almost any 2D game we can conceive of.

    My question is this: how would we go about a mario-style platformer? Where the screen moves along with the player?

    Keep up the good work, Mike! Definitely going to go through the OOP course too

    • AC says:

      whoops, just got to the later lessons and saw that my question was taken care of. you really did think of everything mate!

      thanks again

  4. Masoman says:

    I’m having a problem where I tried to animate the comets in the the side shooter game, and it only animates 1 of the comets at any point in time. I tried using the code:
    for(int i = 1; i < 2; i++)
    {
    if(comets[i].live == true){
    al_draw_bitmap(cometAnimation[curFrame_comet], (comets[i].x – comet_imageWidth/2), (comets[i].y – comet_imageHeight),0);
    break;
    }
    }

    and it wont work!!!

    • Mike says:

      Yes… look at your loop. You are looping from 1 to 2, so the loop iterates only once.

      • Masoman says:

        Thanks, but it was fixed when I went into your later tutorials. You really do cover everything!!! I just need to learn how to do class based programming now then I can make the game I’ve been wanting to. Thanks for helping though!!!

  5. Zack Mayoh says:

    Heads up: You forgot to destroy your timer in this one!

  6. Niklas says:

    good tutorial as always,

    works great, unless i try to give my image to my drawhero function,

    failed to convert’ALLEGRO_BITMAP’ in ‘ALLEGRO_BITMAP *[]‘..
    or other kind of convert problems,
    do someone got an idea how i solve this?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Error: Twitter did not respond. Please wait a few minutes and refresh this page.