Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] Timer for sprite animation

Started by p997 Apr 16, 2006 at 11:47 PM 0 replies 700+ views
Original Post
p997
p997
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.
Daaark
Daaark
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.