Sign in to follow this  


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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this