• Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
AnonyViet - English Version
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
AnonyViet - English Version
No Result
View All Result

[Tạo 2D Platformer Game với Godot] Part 24: Creating a Pause Menu

AnonyViet by AnonyViet
January 26, 2023
in Tips
0

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 Pause Menu 43

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 44

Because it’s quite small, I adjusted the min size up.
[Tạo 2D Platformer Game với Godot]  Part 24: Creating a 45 . Pause Menu

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 Pause Menu 46

Then I added a Custom Font to make it beautiful.

[Tạo 2D Platformer Game với Godot]  Part 24: Creating Pause Menu 47

Color id: a77322

[Tạo 2D Platformer Game với Godot]  Part 24: Creating a Pause Menu 48

Then add custom Styles to make it pleasing to the eye.

[Tạo 2D Platformer Game với Godot]  Part 24: Creating a Pause Menu 49

And I have the above result[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 Pause Menu 51

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 the Pause Menu 52

Then align to the center
[Tạo 2D Platformer Game với Godot]  Part 24: Creating a Pause Menu 53

I created a new Custom styles.

[Tạo 2D Platformer Game với Godot]  Part 24: Creating Pause Menu 54

Color: a89d24[Tạo 2D Platformer Game với Godot]  Part 24: Creating a Pause Menu 55

Above are the parameters.

[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 57

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 Pause Menu 58

Select Full rect

[Tạo 2D Platformer Game với Godot]  Part 24: Creating a Pause Menu 59

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 a 60 . Pause Menu

Add a Vboxcontainer

[Tạo 2D Platformer Game với Godot]  Part 24: Creating Pause Menu 61

After adding you will see the Vboxcontainer is indented 10mm from the margincontainer.

[Tạo 2D Platformer Game với Godot]  Part 24: Creating Pause Menu 62

Add the Label rename as TieuDe

[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 a Pause Menu 64

Adjust align to Center to center

[Tạo 2D Platformer Game với Godot]  Part 24: Creating a 65 . Pause Menu

Add a custom font to make it beautiful[Tạo 2D Platformer Game với Godot]  Part 24: Creating a Pause Menu 66

Result as above.

[Tạo 2D Platformer Game với Godot]  Part 24: Creating a Pause Menu 67

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 Pause Menu 68

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 a Pause Menu 69

You save the scene

[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 Pause Menu 71

Add a script in the PauseMenu node

[Tạo 2D Platformer Game với Godot]  Part 24: Creating a Pause Menu 72

Then connect 4 signals of 4 buttons.

[Tạo 2D Platformer Game với Godot]  Part 24: Creating a Pause Menu 73

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 Pause Menu 74

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 75

Then Instance to Map.

[Tạo 2D Platformer Game với Godot]  Part 24: Creating a Pause Menu 76

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 77

[Tạo 2D Platformer Game với Godot]  Part 24: Creating a Pause Menu 78 [Tạo 2D Platformer Game với Godot]  Part 24: Creating a Pause Menu 79

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 80 [Tạo 2D Platformer Game với Godot]  Part 24: Creating Pause Menu 81

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 a Pause Menu 82

And I have the above result

Summary

So in this part, I showed you how to create a pause menu for the game.

The article achieved: 5/5 – (100 votes)

Tags: creatingGameGodotmenuPartPausePlatformertạovới
Previous Post

MHHDoS – Tool DDoS Attack with 36 hottest attack types 2021

Next Post

How to create free VPS from UCloud without VISA

AnonyViet

AnonyViet

Related Posts

4 ways to fix bluetooth connectivity on Windows 11
Tips

4 ways to fix bluetooth connectivity on Windows 11

August 8, 2025
How to know the computer is tracked and processed by Keylogger
Tips

How to know the computer is tracked and processed by Keylogger

August 7, 2025
Opal: Create applications who do not need to write code
Tips

Opal: Create applications who do not need to write code

August 3, 2025
How to activate a new Start menu on Windows 11
Tips

How to activate a new Start menu on Windows 11

July 29, 2025
Intellgpt: AI tool for osint and data science
Tips

Intellgpt: AI tool for osint and data science

July 28, 2025
How to create Google Ai Pro 12 months free with Indian student account
Tips

How to create Google Ai Pro 12 months free with Indian student account

July 27, 2025
Next Post
How to create free VPS from UCloud without VISA

How to create free VPS from UCloud without VISA

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Recent News

Instructions for receiving 80GB of free data from VinaPhone from August 15

Instructions for receiving 80GB of free data from VinaPhone from August 15

August 15, 2025
Online driving exam preparation: Support theory and practice

Online driving exam preparation: Support theory and practice

August 15, 2025
How to add application to your favorite bar

How to add application to your favorite bar

August 14, 2025
Wowhay.com – The door opens the world of modern knowledge and network culture

Wowhay.com – The door opens the world of modern knowledge and network culture

August 13, 2025
Instructions for receiving 80GB of free data from VinaPhone from August 15

Instructions for receiving 80GB of free data from VinaPhone from August 15

August 15, 2025
Online driving exam preparation: Support theory and practice

Online driving exam preparation: Support theory and practice

August 15, 2025
How to add application to your favorite bar

How to add application to your favorite bar

August 14, 2025
AnonyViet - English Version

AnonyViet

AnonyViet is a website share knowledge that you have never learned in school!

We are ready to welcome your comments, as well as your articles sent to AnonyViet.

Follow Us

Contact:

Email: anonyviet.com[@]gmail.com

Main Website: https://anonyviet.com

Recent News

Instructions for receiving 80GB of free data from VinaPhone from August 15

Instructions for receiving 80GB of free data from VinaPhone from August 15

August 15, 2025
Online driving exam preparation: Support theory and practice

Online driving exam preparation: Support theory and practice

August 15, 2025
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

©2024 AnonyVietFor Knowledge kqxs hôm nay xem phim miễn phí mm88 8XBET mm88 trang chủ new88

No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office

©2024 AnonyVietFor Knowledge kqxs hôm nay xem phim miễn phí mm88 8XBET mm88 trang chủ new88

wpDiscuz
0
0
Would love your thoughts, please comment.x
()
x
| Reply