Archived

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

Animation Explaination

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

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 this post


Link to post
Share on other sites
In his book, Lamothe uses BOB''s for animation.
Each is BOB is actually a sprite, an object that can be animated and moved on screen.
To create a new object you just declare: BOB dog; (For example)
Then you load in the frames from bitmaps and set the various animations (Walk to the left, Walk to the right, Jump, whatever...)
Then to animate the BOB you would use whatever function Lamothe made. In "Windows game programming gurus" it''s Animate_BOB(&dog);.
To animate both a dog and a cat at the same time, you would select the animation you want for both of them, speed of animation and do Animate_BOB(&dog); Animate_BOB(&cat); (Or whatever), right afterwards, you would move them on the screen and finally draw them to the screen.
Get it ?


Share this post


Link to post
Share on other sites
The Animate function, how does it goes? Let''s say...

Animate(&dog); //this is one frame the goes to cat? or full animation?
Animate(&cat);

Share this post


Link to post
Share on other sites
When you do Animate(&cat);, The cat''s get animated according to it''s number of frames, last frame drawn and animation speed.
This way you only animate the cat, you also need to Animate(&dog); (To animate the dog )

Share this post


Link to post
Share on other sites
SPRITE (in this BOB) is a structure that holds information about your SPRITE. That information includes information such as x, y, width, height, current_frame, number_of_frames, frames_buffer about the sprite. Now, what your animate function uses in order to find out how many frames the sprite has, and which frame to display next is the current_frame data member of your SPRITE structure (or BOB). How it animates it is as follows:

DrawPicture(x, y, frames_buffer[current_frame]);

Now, when you need to go to the next frame (depending on the player''s actions) you can check to see if we''re at the end of the frame.

Animate(&dog);

if (++current_frame == number_of_frames)
{
current_frame = 0;
}

Another way you can do the same thing is like this:

Animate(&dog);

current_frame = ++current_frame % number_of_frames;

btw, buffer_frames, are all the bitmaps (or frame buffers) that the animation needs in order to be able to animate.

Hope this helps!


..-=gLaDiAtOr=-..

Share this post


Link to post
Share on other sites
So the Animation() function only animate one frame each time it is called?

Then what if you say, if the "Space" key is pressed fire...and fire takes..say..3 frames...So you need 3 frames to be displayed continuously along with other sprite''s animation. Do you call the function 3 times?

Share this post


Link to post
Share on other sites
quote:

So the Animation() function only animate one frame each time it is called?



Animate() is called once per frame on every object that you have.

This is how you do it:

Animate(&dog);
Animate(&cat);
Animate(&frog);

This is NOT how you do it:

Animate(&dog);
Animate(&dog);
Animate(&cat);
Animate(&dog);
Animate(&frog);

or any variations of this.

Hope you understand the concept now!

quote:

Then what if you say, if the "Space" key is pressed fire...and fire takes..say..3 frames...So you need 3 frames to be displayed continuously along with other sprite''s animation. Do you call the function 3 times?



Again, you display a 3-framed animation of a fire in iterations of your main loop (while(1) or while(!done)...), meaning the whole animation process takes 3 frames to be displayed. This is how you code it:

// main loop
while(!done)
{
Animate(&dog);
bullet.current_frame = ++bullet.current_frame & bullet.number_of_frames;
}

And this is the wrong way:

// main loop
while(!done)
{
while (bullet.current_frame < bullet.number_of_frames)
{
Animate(&dog);
bullet.current_frame++;
}
}

Hope you understand what''s going on now!

-------------------------------------
That's just my 200 bucks!

..-=gLaDiAtOr=-..

Share this post


Link to post
Share on other sites
well heres my 200 bucks alos

This is how you do it:

Animate(&dog);
Animate(&cat);
Animate(&frog);

This is NOT how you do it:

Animate(&dog);
Animate(&dog);
Animate(&cat);
Animate(&dog);
Animate(&frog);

i think youve gotta do it the second way. ie what happens if one dogs walking and the others taking a leak.

btw check some of me source http://members.xoom.com/myBollux/home.html
for 2d sprite animations + also 3d model animations


Edited by - zedzeek on July 17, 2000 6:19:59 PM

Share this post


Link to post
Share on other sites
quote:

i think youve gotta do it the second way. ie what happens if one dogs walking and the others taking a leak.



You didn''t listen to what I said

What I said was that you need to call the Animate() function on EACH object only ONE time every frame!!! What you are talking about is having TWO dogs (one taking a leak and the other walking). Of course, the type of object is the same (i.e. inherits from the same class), but the object instance is completely different from any other objects of the same type. So what you''d do is call the Animate() function on both dogs (but not call it twice on the same dog, because it will skip a frame which will not be rendered to the screen). Now that I''ve cleared up what I meant in the last post, hopefully you''ll agree with me If not, let''s get the beer from the fridge, sit on the table, and start arguing

-------------------------------------
That's just my 200 bucks!

..-=gLaDiAtOr=-..

Share this post


Link to post
Share on other sites