Request for Pseudo Code -- sprite anims
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
There are many ways to do it here's one:
That's it, a simple method, probably there are more effective ones but this one works fine to start with.
\Jimmy H
//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 playerint playerMove;//animation functionvoid Animate(){//setup sequence (pressing keys, moving around)//in this case the result of it was RUNLEFT1playerMove = 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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement