2D Character Animation

Started by
2 comments, last by Utwo 21 years, 4 months ago
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?
---signature---" Actually, at the time, I didn't give a damn about the FoxNews issue... just that you would come swooping in with your Super Mith cape flapping behind you and debunk it just because it didn't happen in your living room." - InnocuousFox
Advertisement
thats the way I''ve seen every game out there do it (at least that I can think of)... so yes you''d be on the right track
The Great Milenko"Don't stick a pretzel up your ass, it might get stuck in there.""Computer Programming is findding the right wrench to hammer in the correct screw."
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?
---GUI Programming Division Manager at Wildfire Gamesworking on the 0 A.D. project
Utwo,

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: ManNumFrames: 5FrameTime: 100 100 50 100 100Frames: Walking1.jpg Walking2.jog Standing.jpg Walking3.jpg Walking4.jpgStrength: 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 looppCurrentFrame = (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 imagepCurrentFrame = (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]

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

This topic is closed to new replies.

Advertisement