In this part, I will show you how to use buttons like start and exit the game by connecting a signal and a few lines of code.
You add yourself a new script in the scene Menu.
I will connect the signal of the NutBatDau node so that when I click it, it will move to scene level 1
Find and connect the pressed() signal. This signal will execute the command when the button is clicked by the user.
You will do the same for yourself for the game exit button.
extends Control func _on_NutBatDau_pressed(): pass # Replace with function body. func _on_NutThoatGame_pressed(): pass # Replace with function body.
Here is the original code.
extends Control func _on_NutBatDau_pressed(): get_tree().change_scene("res://Scences/Map/Map.tscn") pass # Replace with function body. func _on_NutThoatGame_pressed(): get_tree().quit() pass # Replace with function body.
And here is the code that I added and it only adds 2 lines.
At the start button I will add the function change_sence() to change through the scene I want and change_scene() can only be called through get_tree().
At the game exit button, I use the quit() command, this command will automatically close your game
Then you press F6 run the game and will see that when you press BAT DAU you will be moved to another scene and when you press THOAT GAME your game will be exited.
This part is full of things that are quite easy to do.
In the next part, I will guide you how to design and redecorate the Menu interface so that it is beautiful and reasonable. It is expected that the Menu section will last for 2.3 more parts and then create a Menu to stop the game while playing the game.