Jump to content
  • Advertisement
Sign in to follow this  


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

What is the best way to animate a character. Is the best way to have a vector of HBITMAPS and have it go to a new one every frame or what? I was thinking maybe make a vector vector<HBITMAP> walk;vector<HBITMAP> attack; like for each action a vector holds a set of frames. Is this the best way or is there a better way. Any input is welcome. Thanks, Cory Fisher

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
try not to use vectors instead simple arrays should suffice. Tranversing a vector can become computational intensive hence an array would be simpler.

Share this post

Link to post
Share on other sites
You should also be storing more information than just image data, such as timing. Some animations will be quick (fast punch) while others will be long (boss death), so you're going to need to store timing information.

I wrote three classes: AnimationData, Animation and AnimationSet.

AnimationData contains the texture name, source rectangle (sprite sheet), and number of milliseconds the frame should be played for.

An Animation is basically just a controller for AnimationData. It contains an array of AnimationData, which represents a frame of animation. It also stores the number of frames in the animation, looping information and it names the animation.

Finally, the AnimationSet class controls the individual animations. It keeps track of the timing (if it's time to switch frames) and let's you call upon things by name.

You end up with something like this:

-> Set() checks for an AnimationSet named attack.
-> If so, it sets it to the current animation.

-> AnimationSet.Update(deltaTime)
-> Update()
- if current animation has frames left or loops
-> Animation.Update(deltaTime)
-> AnimationData.Update(deltaTime)
-> If it's time to advance the frame, do so. Otherwise, do nothing.
- otherwise we return to the default idle animation, which every AnimationSet has.
-> this.Set("idle");

This solution is working well for me.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • 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!