Jump to content
  • Advertisement
Sign in to follow this  
DanMarshall

Request for Pseudo Code -- sprite anims

This topic is 5459 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok. So I've read my C primer books and my Allegro books and I'm confident enough about what I'm doing to start my game. Only one thing eludes me: multiple sprite animations. I've got a big .bmp file with all the idle, running, jumping, crouching anims for my platformer guy, and I've got the necessary frame grabbing algorithm sorted. All I need is some pseudo code to help me organise what I'm doing -- how should I set up my code so that the appropriate anim plays when running left, right, standing, shooting etc? Any help very much appreciated...! Dan

Share this post


Link to post
Share on other sites
Advertisement
There are many ways to do it here's one:


//data

//enum all the parts of the animation (parts in your bitmap)
enum moves
{
STAND1,
STAND2,
STAND3,
RUNLEFT1,
RUNLEFT2,
JUMP1 //and so on
};

//structure for source image data (where to copy from in the bitmap)
struct sourceCoordinates
{
int x1, y1, x2, y2;
};

//array of source image data (source rectangles)
source mySourceCoordinates =
{
{0, 0, 10, 10}, //corresponds to STAND1
{10, 0, 20, 10}, //corresponds to STAND2
{20, 0, 30, 10} //and so on
}

//variable that keeps track of the current animation of a player
int playerMove;

//animation function
void Animate()
{
//setup sequence (pressing keys, moving around)
//in this case the result of it was RUNLEFT1
playerMove = RUNLEFT1;

int x1 = mySourceCoordinates[playerMove].x1;
int y1 = mySourceCoordinates[playerMove].y1;
int x2 = mySourceCoordinates[playerMove].x2;
//...and so on

//draw the image from your source rectangle here!
}



That's it, a simple method, probably there are more effective ones but this one works fine to start with.

\Jimmy H

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!