#### Archived

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

# Animation Explaination

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

## Recommended Posts

A nice explaination about animation in games would be nice. Let''s say you have a dog sprite with 3 frames for walking and a cat sprite with 5 frames for jumping, how would you animate them both at the sametime on screen? Would be sprite need to have a function something the Animate()? if so how would it work? In the book "Windows Game Programming for Dummies", it mentioned a BOB or something like that. I couldn''t understand how it works. And about the GPDUMB engine, there was no codes for the functions to explain and give a little example. HELP!!!!!!!!!!!!!!!!

##### Share on other sites
Well, hopefully you have it set up so each of the frames has their own buffer, or be able to display the cell you want. Once you can do that, animation is pretty simple. Just include a 'frame' variable or something in the struct you're using. Now onto the animation...

I'm assuming a few things here:
1) You have some sort of general entity structure in which you can tell what type of entitiy it is(take a look at the BOBs you mentioned in LaMothe's book, thats a good place to start).

2) You have an array with some entities(AKA, BOBs) in it.

Now all you have to do is 2 things: make an EntityAnimate() function that will cycle through each entity and draw them based on what their 'frame' variable is, and then update the 'frame' variable in their AI (which can be done in pretty much the same way, i.e, cycling through the entities and calling a function that will switch between each type of ent). Of course, there are a ton of better (and harder) ways to do this, using linked lists, function pointers, etc. but from your post, it sounded like you were just starting out (sorry for the misconception if you aren't ), so responded with the simplest and most straightforward way I could think of.

And, just to make things clearer, here's a little example:
  #include #define DOG 1#define CAT 2void AnimateEnts(void);void AIEnts(void);typedef struct{ int x,y; int type; int frame;} ENTITY, *PENTITY;ENTITY someEnts[256];void main(void){ bool gameOver=false; while(!gameOver) { AIEnts(); //first make the ents think... AnimateEnts();//now draw them. //Actually, these could be combined into one.. }}void AIEnts(void){ for(int x=0; x < 256; x++) //cycle through each ent. Assume they're valid { switch(someEnts[x].type) { case CAT: x++; //move it around.. frame++; break; case DOG: y++ frame++; break; } //ehm... you wouldn't *really* want them to cycle through //each frame on every cycle, unless you have a lot of frames, //because then they'd animate very (VERY!) quickly.}void AnimateEnts(void){ for(int x=0; x<256; x++) { gameLibDrawFrame(someEnts[x].frame); }}

Edited by - A. Buza on July 17, 2000 10:33:00 AM

Edited by - A. Buza on July 17, 2000 10:34:53 AM

##### Share on other sites
Nice example, but one thing...If you created 256 entities(sprites) and cycle through the every single time. If all of the 256 sprites needs to be animated then its ok, but if only one or two needs to be animated, wouldn''t that be slow?

##### Share on other sites
Sure, It''d be slower that if you had something like a linked list. I only used a static array for clairity and brevities sake.
If you''re up to it, there are quite a few tutorials on linked lists on the net (and probably on this site), they''re great for stuff like this.

1. 1
2. 2
3. 3
Rutin
18
4. 4
5. 5
JoeJ
14

• 14
• 10
• 23
• 9
• 32
• ### Forum Statistics

• Total Topics
632631
• Total Posts
3007534
• ### Who's Online (See full list)

There are no registered users currently online

×