Freezing StandardGame

When i switch from a InGame-Gamestate to a Menu-GameState i would like to freeze the GamePlay.

I thought i could use StandardGame.lock() to lock the update/render cycle, but it dosen't work.



This can be easily reproduced in jmetest.input.controls.TestControls, just replace game.shutdown() with game.lock().

now the game should freeze when ESC is pressed no ?

hmm i think i was on the wrong track there :slight_smile:



Its much easier to simply set tpf in the InGame-GameState to 0 when the game is paused.

Adding a pause() method to StandardGame might actually be a good idea…feel free to submit a patch for this support.

i did that first, but then i noticed i can't un-pause the game when i lock the update loop heh (since the input handler wont get updated anymore)

So i think its cleaner to do it on the user side.



…well or maybe a StandardGame pause() function could simply set the tpf to to zero.

But i don't know if thats a general purpose solution :slight_smile:

i have the same problem in my game and my solution look like this:



in my static class WorldContext is a boolean defined for gamelogic execution. if i set this to false the main gameloop updates all inputhandlers only and return before the gamelogic run. If i switch to the menustate then the boolean is set to false and true if the menu state go to sleep :wink:


Core-Dump said:

...well or maybe a StandardGame pause() function could simply set the tpf to to zero.
But i don't know if thats a general purpose solution :)


Yeah, that's the thought. That would mean everything based on "time" would not be updated but something like an unpause button in GameControls would work just fine.