Start, Pause and Game Over screens

I am trying to make a platform game using Box2D and LibGDX. I wonder how you handle Pause, Start and Game Over screens.

By Start screen, I mean this: When the game begins, I start it as paused, so the player can be ready for moving the character. I do this by rendering a black image with alpha= 0.5f, and a Scene2D label “Touch the screen to begin”.
I don’t have a Pause screen yet lol.
Game Over screen is also a black image with 0.5 alpha value and a label saying “Game Over”. I haven’t put any buttons for restart or go to menu, but I am planning to do.

But like I said, I wonder how you handle these kind of screens. Do you make a new class which extends Screen (those who are familiar with LibGDX should understand what I mean :)) and show that when the player pauses the game or when the game is over?

What do you do with these screens? How do you handle this?

I’m using the Screen interface… If your main class derives from the Game class, you can call setScreen and set the game screen.

Edit:
Here is an example from our LD28 entry.

The main class: https://github.com/tomvangreen/ch.digitalmeat.ld28/blob/master/ld28/src/ch/digitalmeat/ld28/ConcertSmugglers.java
Implementation of a screen: https://github.com/tomvangreen/ch.digitalmeat.ld28/blob/master/ld28/src/ch/digitalmeat/ld28/RulesScreen.java

I use a base screen class that implements Screen, and then I have my other screens extend that base class. As a result I have the libgdx Screen functionality but can also put my own stuff into the base screen class.

Thanks for the replies guys.
So, you have another screen for these stuff and you just take the player to that screen when the game stops or it’s over.

I wonder, doesn’t that affect the gameplay? For instance, my game turned out to be an infinite jumper now (lol). So, that means if the player falls, the game should be over. And that means, the player should be able to see what’s going to happen when the game begins so that he can have time to react (for example, press “left” key to prevent the player from falling down and the game from an instant end. Ugh… I mean, if I have a Pause screen, the player won’t be able to see what’s next.

Another concern for me would be preserving the game state, which I have never tried to do. The whole idea of pausing the game is to be able to start from the exact spot you left. I don’t know how to do that. Any guides for this?

EDIT:
@atombrot
I’ll have to get the whole project and play with it, compile it etc. I hope that is okay for you. Of course I’m not gonna distribute it. I won’t use the code, but I might take inspiration from it, as the whole point of me looking at that code is to learn how you guys do it :slight_smile:

i usually have a screen implementation for the main menu and one for the gameplay. I have set up a scene2d stage in my gameplay screen for the ui. If I wanted to implement a pause screen, I add an additional UI element as overlay and make it small or translucent.

To pause the game you simply have to stop updating the game logic, when you enter pause mode. When you continue the game you start updating again.

You don’t need to do much to persist the state, if you just wan’t to implement pause and play. If you want the ability the exit the game and reopen and continue, then you need to write the game state to disk.

You can use my code to understand what’s going on, but you have to keep in mind that this “game” was hacked in 3 days and I’m still getting to know libgdx, so it is not exactly a prime example of a libgdx project :wink:

Well, I’ll try to implement something for this, but let’s see how it goes.

I’m not looking for a perfect or professional or right way to do these screens, so it’s okay atombrot. I’ll download the source, compile it and see how you did that.

But still I’m open to alternative implementations if anyone does this in some other way.

Currently in my rpg engine I have a base that uses a gamestate manager and will update and draw whatever state is currently selected. Feel free to check it out and use it.
My project