Jump to content
  • Advertisement
Sign in to follow this  
p997

[.net] Timer for sprite animation

This topic is 4545 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've incorporated the dxmutmisc.sc from DirectX SDK to my program, so that i could use the high resolution timer (FrameworkTimer class) to time my sprite animation. in my code i used a float number animationRate to determine the frame rate: public void Run() { InitializeGraphics(); InitializeResources(); FrameworkTimer .QueryPerformanceFrequency (ref timerFrequency ); while (gameRunning) { Show(); Application.DoEvents(); FrameworkTimer.QueryPerformanceCounter(ref timeStart); Render(); FrameworkTimer.QueryPerformanceCounter(ref timeEnd); animationRate = ((float)timeEnd - (float)timeStart) /timerFrequency; } however, the result of animationRate is less than 0.02xxx on some computer while it is more than 0.07xxx on others. Now i got 2 questions. how do i use this animationRate to control my animation speed(changing sprite frames)since the number is so small? and how do i make the timer less CPU speed dependent, so that my program can run on different computers and still have the same effects. Thanks for any comments in advance.

Share this post


Link to post
Share on other sites
Advertisement
Use delta timing.

Every update you can add 0.1 to a float variable, and switch frames at 1.0. The thing is, you use the delta and only add (0.1 * delta) every update. The delta is time since the last update. This way every PC will more or less go from 0.0 to 1.0 at the same rate.

Here. This article talks about physics programming, but it's the same idea. Use your high rez timer to get the time every update, and then get the delta from them.

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!