[.net] stopwatch issues

Started by
0 comments, last by ernow 13 years, 4 months ago
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?
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.

This topic is closed to new replies.

Advertisement