Sign in to follow this  
EvilNando

[.net] stopwatch issues

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

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