So I have a game running right now that uses the "e" in: private void OnUpdate(object sender, GameTimerEventArgs e) to keep the world speeds updated, however I don't know how to reset this GameTimerEventArgs for when I restart the game (without actually exiting the game)
this is how I use it
worldSpeed = (float)(3 + e.TotalTime.TotalMilliseconds / 10000);
suggestions?
Query GameTimerEventArgs.ElapsedTime
each frame. Ignore TotalTime
.
Accumulate the elapsed time in a variable. This way you can reset the variable to zero when you restart the game. You can also implement pausing by not accumulating time while paused.
In your case, it looks like you're increasing the worldSpeed
as gameplay goes on. So rather than accumulate time spent running, you could just accumulate changes to worldSpeed
like this:
if(!paused)
{
worldSpeed += (float)(e.ElapsedTime.TotalMilliseconds / 10000f);
}
And set worldSpeed
to 3 whenever you restart.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.