Jump to content
  • Advertisement


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


Animation class

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

Hi, I am coding a animation class, but I have been a problem. I want to keep all frames and all directions from the animation in a single surface (walk right, walk left, etc), but I don´t know how I can handle the frames of the animation for an unique direction. Some suggestion? PD: Sorry, my english is not the best PD2: the class is for a 2D game.

Share this post

Link to post
Share on other sites
Basically... I''d just store each animation horizontally, and the different directions vertically...

-> ->> ->>>

<- <<- <<<-

/\ / \ / \

\/ \ / \ /

(right, left, up, down direction animations)

Now, you simply hold the direction...

#define Right 0
#define Left 1
#define Up 2
#defien Down 3

Now, you use the direction to set your Y value in your animation.

0 = first line
1 = second line
2 = third line
3 = fourth line.

If each of your animations are the same dimentions (lets use 32x32 for this example)

Blit(Destination,ImageSurface,Direction*32, AnimationFrame*32);

Billy - BillyB@mrsnj.com
(Hey, I''''m no longer anonymous!)

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
I am working on this same thing right now.

I broke everything up into 3 structures.

A frame, which has an x, y, width, height in the image for the frame and the duration.

A scene, which has a collection of frames and a name (walk_left, walk_up, fire_gun, etc.).

An animation, which has a collection of scenes and an image handle.

I am currently working on reading all this information in from a tagged (xml) file.

Share this post

Link to post
Share on other sites
I want use the same animation class for objects,not only for players. So you solution can have any problem because objects do not have different directions. How I can establish the transitions between directions? with a state pattern?

Another question, Should I to put the sound associated to the animation in the class animation ?, I don´t believe it, but either where to put it?.


Share this post

Link to post
Share on other sites
Hey, I was the anonymous poster, I had forgotten my password.

What do you mean by a map?

I have an animation manager.

I register the animation file with the manager, it loads it in and returns a handle.

When something needs to use that animation, you pass the handle asking for an instance.

This instance holds current scene, current frame and animation handle.

The animation manager then handles all the timing for frames.

When you want to show the animation on screen you pass the animation manager the instance and x, y coords and it draws the right frame for the current scene.

If i want to say change the scene from walk_up to walk_left I call the animation manager with the instance and the name of the scene to switch to.

This may sound a little convulted, but it allows the expensive operation of loading an animations information to be done ahead of time and shared across different objects.

The inexpensive creation of an instance can be called at anytime and not takeaway frame rates.

The animation manager has a think function that loops over a linked list of animation instances seeing if any need to be updated. So single frame animations or the last frame of an animation just don''t ask to be updated again.

Another thing I am considering is allowing a command frame that will allow things like looping or moving from one scene to another.


Share this post

Link to post
Share on other sites
Not currently, most animations don''t have enough scenes to worry about optimizing finding a specific one by name.

An animation instance stores the current scene using an array index so the only time the lookup cost is incurred is when you switch scenes.

Share this post

Link to post
Share on other sites
JAlonso, you just do it. Put the animation frames for a given direction down the off-screen surface, move over to the next column for the next direction, make a new ''animation colunn''. IIRC, DooM I/II worked much like that.

map is typically implemented with a red-black tree.
STL Port and some other STL libraries provide hash container extentions.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!