Jump to content
  • Advertisement
Sign in to follow this  
EvilNando

[.net] stopwatch issues

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

Looks like im doing something wrong trying to do animations using time calculated by the stopwatch class

quick code:

Stopwatch timer;


void Update()
{
timer.Stop();

world.Render(timer.Milliseconds);

timer = Systems.Diagnostics.Stopwatch.StartNew();
} // end rendering


in my world render I do the following

void Render (Long Milliseconds)
{
elapsed += Milliseconds;

if (elapsed >= anim_speed)
{
elapsed = 0;
current_frame++;
current_frame %= num_frames;
}

render(current_frame);
}


with this im not having consistent animations (jerkiness all over the place) so I was wondering what should I do to improve the situation?

Share this post


Link to post
Share on other sites
Advertisement
First: post compiling code!

You keep on re-creating the timer in the Update method and starting it again.

timer.Milliseconds doesn't even exist (the code does not compile).

Use TotalMillisecondsElapsed.

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!