In this part, I will guide you how to create a pause menu while playing a game and press pause then the game stops and you can continue playing, playing again, exiting.
| Join the channel Telegram of the AnonyViet 👉 Link 👈 |
And create a menu when the game ends, it includes: Next Level, Play again, exit the menu.
![[Tạo 2D Platformer Game với Godot] Part 24: Creating a 45 . Pause Menu [Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 43](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-01-40.png)
I add CanvasLayer as the root node and rename it as PauseMenu
![[Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 46 [Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 44](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-02-35.png)
Because it’s quite small, I adjusted the min size up.![[Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 47 [Tạo 2D Platformer Game với Godot] Part 24: Creating a 45 . Pause Menu](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-02-41.png)
It got bigger when the min size was adjusted and in the text box I added 2 signs | |
![[Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 48 [Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 46](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-03-29.png)
Then I added a Custom Font to make it beautiful.
![[Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 49 [Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 47](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-04-37.png)
Color id: a77322
![[Tạo 2D Platformer Game với Godot] Part 24: Creating a 50 . Pause Menu [Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 48](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-04-44.png)
Then add custom Styles to make it pleasing to the eye.
![[Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 51 [Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 49](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-04-52.png)
And I have the above result
![[Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 53 [Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 51](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-09-07.png)
I added a new Control node and renamed it PauseMenu and added a Panel to be the Background then renamed it.
![[Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 54 [Tạo 2D Platformer Game với Godot] Part 24: Creating the Pause Menu 52](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-09-14.png)
Then align to the center![[Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 55 [Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 53](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-09-27.png)
I created a new Custom styles.
![[Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 56 [Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 54](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-10-55.png)
Color: a89d24![[Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 57 [Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 55](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-11-07.png)
Above are the parameters.
![[Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 59 [Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 57](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-13-58.png)
You add the MarginConTainer node under the Background.
I use margincontainer to align it beautifully.
![[Tạo 2D Platformer Game với Godot] Part 24: Creating a 60 . Pause Menu [Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 58](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-14-15.png)
Select Full rect
![[Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 61 [Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 59](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-14-43.png)
Then Theme Overrides -> Constants you fill in about 10 and customize according to your game.![[Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 62 [Tạo 2D Platformer Game với Godot] Part 24: Creating a 60 . Pause Menu](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-16-30.png)
Add a Vboxcontainer
![[Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 63 [Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 61](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-16-39.png)
After adding you will see the Vboxcontainer is indented 10mm from the margincontainer.
![[Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 64 [Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 62](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-18-38.png)
Add the Label rename as TieuDe
![[Tạo 2D Platformer Game với Godot] Part 24: Creating a 65 . Pause Menu [Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 63](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-19-17.png)
![[Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 66 [Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 64](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-19-22.png)
Adjust align to Center to center
![[Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 67 [Tạo 2D Platformer Game với Godot] Part 24: Creating a 65 . Pause Menu](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-19-49.png)
Add a custom font to make it beautiful![[Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 68 [Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 66](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-20-32.png)
Result as above.
![[Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 69 [Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 67](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-24-07.png)
I added 3 more buttons like the picture and 3 Ninepatchrect as spaces.
![[Tạo 2D Platformer Game với Godot] Part 24: Creating a 70 . Pause Menu [Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 68](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-28-21.png)
Then you add custom fonts and custom styles to the button.
You can add or not add.
![[Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 71 [Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 69](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-29-23.png)
You save the scene
![[Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 73 [Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 71](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-31-03-300x245.png)
Add a script in the PauseMenu node
![[Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 74 [Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 72](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-34-25-300x238.png)
Then connect 4 signals of 4 buttons.
![[Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 75 [Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 73](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-49-07-300x77.png)
Then hide the pause menu because I only show it when I press the show button.
func _on_NutTiepTuc_pressed():
get_tree().paused = false
$PauseMenu.hide()
Code in continue button.
get_tree().paused = false : I will tell the tree to continue working.
$PauseMenu.hide() : I will hide the PauseMenu because I want to continue playing the game.
func _on_NutChoiLai_pressed(): get_tree().paused = false get_tree().reload_current_scene() pass # Replace with function body.
get_tree().reload_current_scene() : I will tell the tree to replay the scene.
func _on_NutVeMenu_pressed():
get_tree().paused = false
get_tree().change_scene("res://Scences/Map/LevelMap.tscn")
pass # Replace with function body.
get_tree().change_scene("res://Scences/Map/LevelMap.tscn"): I will move to the Level Map scene.
func _on_HienPauseMenu_pressed():
$PauseMenu.show()
get_tree().paused = true
pass # Replace with function body.
$PauseMenu.show() : is that I will show the PauseMenu because it is hidden.
get_tree().paused = true : is that I will call the current tree and tell it to stop. When stopped, all nodes on the tree will stop working.
extends CanvasLayer
func _on_NutTiepTuc_pressed():
get_tree().paused = false
$PauseMenu.hide()
func _on_NutChoiLai_pressed():
get_tree().paused = false
get_tree().reload_current_scene()
pass # Replace with function body.
func _on_NutVeMenu_pressed():
get_tree().paused = false
get_tree().change_scene("res://Scences/Map/LevelMap.tscn")
pass # Replace with function body.
func _on_HienPauseMenu_pressed():
$PauseMenu.show()
get_tree().paused = true
pass # Replace with function body.
So I will have full code like this.
![[Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 76 [Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 74](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-01-55-27-198x300.png)
And in the Inspector’s PauseMenu, you need to change the pause mode to Process so that when the tree pauses, but the PauseMenu still works.
![[Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 77 [Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 75](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-02-07-57-300x293.png)
Then Instance to Map.
![[Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu [Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-02-07-33.png)
Here are my results
Level Map
Ah, I forgot in the previous parts to add a return button in the Level map scene to return to the Main Menu.
![[Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 79 [Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 77](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-02-02-30.png)
![[Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 81 [Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 79](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-02-04-24.png)
You add the Button node and then rename it. Then add custom fonts, custom styles.
![[Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 83 [Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 81](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-02-05-24-300x87.png)
Create your own script at Level Map.
Then connect the signal in the QuayVe node.
extends Node2D
func _on_QuayVe_pressed():
get_tree().change_scene("res://Scences/UI/Menu.tscn")
pass # Replace with function body.
About the code I have above.
![[Tạo 2D Platformer Game với Godot] Part 24: Creating Pause Menu 84 [Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu 82](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-02-06-54.png)
And I have the above result
Summary
So in this part, I showed you how to create a pause menu for the game.






