Sign in to follow this  
scheols

SDL Animation Question

Recommended Posts

Hello, I was wondering whats the best way to switch between 2 image frames every time I would press a key. For example, If I loaded 2 bitmaps one will have its foot back and the other would have its foot forward so if I would to keep running the frames back and forth it would look like my sprite was walking. Any suggestions on the BEST way to do this? Thanks in advanced for any suggestions giving. -Lamonte

Share this post


Link to post
Share on other sites
They could be 2 surfaces, and you alternate which one to draw. Perhaps those 2 surfaces would be stored in an array. Or they can be different positions on the same surface, and you alternate which part of the surface to draw. There is no 'BEST' way, really. You just have to decide what is easiest for you to use in your program.

Share this post


Link to post
Share on other sites
Here's a great tutorial on sprite sheets:
http://lazyfoo.net/SDL_tutorials/lesson06/index.php

And here's his main tutorial page:
http://lazyfoo.net/SDL_tutorials/index.php

That should get you started. But for a quick fix you could use a boolean value to decide which image to display...


bool DrawImageOne=true;

while(stuff is happening)
{
if(DrawImageOne)
{
Draw(ImageOne);
}
else
{
Draw(ImageTwo);
}
DrawImageOne=!DrawImageOne;//this will alternate between true and false
}



It's ugly, but if you only need two images it'll do.

-Artum.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this