Reputation: 1129
Doing a probability machine simulation.
Need to pause the simulation upon a button press.
At the moment, what I have is, if I press 'P', my simulation pauses absolutely fine. But when I press the Unpause key, simulation unpauses, but it doesn't unpause from the state it was paused at.
i.e. if I pause the machine when the balls are the middle, after unpausing, the balls respawn from the top, telling me that the ball has travelled in the meantime to the bottom.
The algorithm I used to achieve this is -
if (UserPress == 'P')
Pause = !Pause;
if (Pause)
{
ball.Update;
ReDraw();
}
Upvotes: 0
Views: 199
Reputation: 10896
If you're using real-time to perform the "simulation" inside Update(), even when un-paused, real-time has elapsed since it was paused and therefore the "ball" moved. You will need to relate elapsed time since the last un-paused frame to the time you're using inside ball.Update().
Unless, of course, there's something else entirely going that I cannot see in the code.
Upvotes: 1