Reputation: 51
I am trying to create a pause screen in java with libgdx.
My issue is that i am trying to create the screen on-top of the play screen so when the user presses the button 'p' the game will be paused; the state of the game will remain the exact same as to where the user has left off and when they click the resume button, they will be brought back to the play screen, resuming the current state of the game.
Right now i have implemented a pause screen, where the user clicks 'p' and they will be sent to a completely new screen where a resume button is displayed. Now when the user clicks resume it does send the user back to the play screen but it completely restarts it for them. For some reason its not going back to the state they left it in.
Any help would be very much appreciated. T
Upvotes: 0
Views: 152
Reputation: 170
This is because in your LibGDX app you are replacing your active screen, which destroys the previous one.
If you are pausing your game, and you don't want to navigate away from your game screen, you can set up a boolean (isPaused) in your game screen. If this is true, do not update your game elements and render your pause menu. If false, your game updates.
Advantage: This means you don't have to save all your game data as it is still in memory.
Disadvantage: Your pause menu will be more of an overlay component rather than it's own screen, but to the user this can still look however you want. ;)
Upvotes: 1