that_guy
that_guy

Reputation: 2445

windows phone GameTimerEventArgs reset xna

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?

Upvotes: 0

Views: 169

Answers (1)

Andrew Russell
Andrew Russell

Reputation: 27225

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.

Upvotes: 2

Related Questions