5

I have a question regarding the pausing/freezing a game while a window/pausemenu will appear at center of the screen. I've already created a pausescreen class which will be called each time the back key is being pressed.

My problem is that I don't know how to freeze or put the game to pause, this becomes a problem because whenever i tried to click on the outsides of the pause window the player could move around.

Essa Rebaño
  • 113
  • 1
  • 3
  • 11

2 Answers2

3

superjumper code

follow this link . You will find a gameScreen , there they have specified game state which is responsible for pausing and resuming the game. Read it and your problem will be solved.

twiz
  • 9,041
  • 8
  • 52
  • 84
Pranav008
  • 1,225
  • 8
  • 11
  • dear sir, I have just tried to follow superjumper code and still wasn't able to satisfy myself. Still I wasn't able to pause my game or freeze the background while my pausewindow is visible. I have declared state and gamestates pause and unpaused. Create an two update method for paused and unpaused. paused contains the setscreen which will call my window while unpaused contains the controls and render properties of my gamescreen. Do you have any idea on how i should solve it? – Essa Rebaño Jul 23 '13 at 13:26
  • In the code mentioned above, you will notice 2 methods updatePause() and presentPaused(). updatePause() is used to detect the touch on pause screen and presentPaused is used to draw the pause screen. So you DONT have to call setscreen in pause method. Basic idea is if during pause state we dont call update method(method in which you move actors in your game or detect touch events or other events) of UnpausedState() then our game will freeze. For more help you need to provide us the code (or just an overview of it) so as we can tell u the mistake in it. – Pranav008 Jul 24 '13 at 05:37
  • 1
    @joao2fast4u The URL has just moved to https://github.com/libgdx/libgdx-demo-superjumper/blob/master/core/src/com/badlogicgames/superjumper/GameScreen.java – twiz Jul 28 '14 at 18:57
0

All you need is to check current game state in render() function. Here is sample solution: libgdx game how to display pause screen when user click on pause icon

Community
  • 1
  • 1
pawegio
  • 1,722
  • 3
  • 17
  • 29