Yooo wusup, in this lesson we'll be playing with scenes like pausing, resuming, removing, adding scenes. Have you seen in game how each of them displays how much ammo, weapons, health, money the player has, where the enemy is, stats of vehicles, etc. We're gonna make something similar to that keeping them simple. And we'll be pausing and resuming them.
This part is going to be big, so be ready for it. Fire up the engine.
When the Esc button is pressed, we bring the pause menu where you have some options to mess with and when we press the button again, the pause menu dissappears.
Having the engine opened, put some interactive stuff in the scene and rename it as game. Create a new scene by clicking on the + scene related settings on top, rename it as pause. Just to make sure it is the pause screen you add some extra decorations and whatever you want.
Now here's the main part, add a text and type it as resume (create a copy of it, we need to make "quit" button), convert it as text and set it's collision type to No Collision so the game doesn't detect its collision. If you don't know it center it, you can press Ctrl+Shift+Alt+C a popup shows up and click Origin to Center of Mass (Surface) or Origin to Geometry.
Add a plane and scale it so it fits the text's bounds and it should something like this.
Let me explain how it works, when you hover the mouse over the text you need to perfectly place it over the text for the mechanism to work, but when you hover the text with the plane behind it, it works perfectly.
Now for the logic part, select the plane which is behind the text named as "resume" and add two mouse sensors, an AND controller, two scene actuators and connect them. For the first mouse sensor change the mouse event to Mouse Over Leave the second mouse sensor as it is, which might have the mouse event as Left Button. Change the mode to Resume Scene and choose our game scene. For the second scene actuator set the mode to Remove Scene and choose our pause scene. Because we want our pause scene to resume our main game and remove itself. Make sure to test to see if it works.
Select the copy of the text we created earlier, type it as "quit", convert it as mesh, turn off the collision, add a plane and resize it so it fits the text. Add the logic like we did earlier but for the actuator you need to add a Game actuator and set the type to Quit Game.
Now to our game scene, select the camera, add a keyboard sensor, For the first scene actuator, set the mode to "Add Overlay Scene" and choose our "pause" scene. For the second scene actuator, set the mode to "Suspend Scene" and choose our "game" scene. an AND two scene actuators connect them. It works this way: When the "ESC" is pressed the game scene is paused and pause scene shows up.
Run the game and there is our "pause and resume" stuff. Oh one more thing, if you can't see the mouse you can add an always sensor and a mouse actuator. The mouse visibility of the mouse can be toggled by turning on Visible. Alternatively you can go to Render -> Display -> Mouse Cursor, or with python bge.render.showMouse(True).
Download the project file.
Here is the extra setup for our scene stuff.