Advertisement Jump to content


This topic is now archived and is closed to further replies.


2D Character Animation

This topic is 5886 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

When tackling something new, I generally like to test my problem-solving skills by trying to do it myself first. Right now, I''m wondering how one can make a 2D game, like a sidescroller for example, while giving each character on the screen a framerate-independent series of animations. Here''s what I''ve come up with so far: * Create a series of enums for each characters current state, like WALK, JUMP, FIRE, PUNCH, etc. * Create a set of frames for each applicable state, for each character. * Accept user input to decide to decide character''s state; use AI calculations to decide enemy''s state. * Store all enemies, fired ammunition, etc. in a linked list. * Use timing mechanisms to decide which frame to display at the time of rendering, i.e. WALK1, WALK2, WALK3, etc. This seems great, although the deeper I get into it the more complex it becomes, and I start wondering if there''s a better way. I''m not afraid of a challenge, but I don''t want to program the hell out of something stupid, you know? It especially seems as though it will be tough to get the timing done correctly. Sooo....before I continue on, is there a better way? I know I wasn''t very specific, but based on what I just explained, do you think I''m on the right path?

Share this post

Link to post
Share on other sites
What do you mean, you''re gonna put all objects of the game in one giant linked list?

I''d skip linked lists all together for your purpose... Use arrays, STL vector if it''d be me...

And what do you mean with: "tough to get the timing done correctly" ?
The animation speed or?

Share this post

Link to post
Share on other sites

I think thats the right track, and I do think you should use linked lists.

Here's how I do it (cut-down version):

store each character to be animated in a file (or script, whatever)
have attributes defined like this:

Name: Man
NumFrames: 5
FrameTime: 100 100 50 100 100
Frames: Walking1.jpg Walking2.jog Standing.jpg Walking3.jpg Walking4.jpg
Strength: 100
// etc.

//Then, when U load it up, you just can call a funtions and fill in your structures like this:

typedef struct sLinkedList
void *pData;
struct sLinkedList *pNext;
} tLinkedList;

typedef struct
int iFrameNumber;
int iFrameTime;
tImageType *pFrameImage;
} tFrame;

typedef struct
char *pcName;
int iNumOfFrames;
tLinkedList pFrames;
int iFrameTimeStart;
int iStrength;
// etc.

} tScreenObjects;

//then you just display each frame with respect to how long it takes to change like this:

. // somewhere in loop

pCurrentFrame = (tFrame *)pCurrentObject->pFrames->pData;

if (pCurrentFrame->FrameTime + pCurrentObject->iFrameTimeStart < CurrentTime())
// move to next frame, and reset time

pCurrentObject->pFrames = NextNode(pCurrentObject->pFrames);
pCurrentObject->iFrameTimeStart = CurrentTime();
. // then display the image

pCurrentFrame = (tFrame *)pCurrentObject->pFrames->pData;
DisplayImage(pCurrentFrame->pFrameImage, Xvalue, Yvalue);

So, thats a run-down how I do it. NOTE: It's all in C, so a C++ implementaion might be a little different.

[edited by - BeerNutts on December 6, 2002 1:42:23 PM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!