In this part, I will guide you to create a button to choose a level like in the Map level there are some level 1,2,3 cells and then choose to play.
| Join the channel Telegram of the AnonyViet 👉 Link 👈 |
Select Level
Scene![[Tạo 2D Platformer Game với Godot] Part 23: Choosing Level 25 [Tạo 2D Platformer Game với Godot] Part 23: Choosing Level](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-12-06-28.png)
You create yourself a new scene with Control as the root node and 1 TextureButton and 3 Texturects.
TextureButton is what I use to create an image for the level and easily check if it is clicked.
The 3 Texture Rects are used to display the star.
![[Tạo 2D Platformer Game với Godot] Part 23: Choose Level 26 [Tạo 2D Platformer Game với Godot] Part 23: Choosing Level 22](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-12-09-05.png)
![[Tạo 2D Platformer Game với Godot] Part 23: Choose Level 27 [Tạo 2D Platformer Game với Godot] Part 23: Choose Level 23](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-12-09-26.png)
You copy the circle in the UI folder in the Level map to the TextureButton
![[Tạo 2D Platformer Game với Godot] Part 23: Choose Level 29 [Tạo 2D Platformer Game với Godot] Part 23: Choosing Level 25](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-12-10-02.png)
Then the Texture Rect then 3 drag the star in.
![[Tạo 2D Platformer Game với Godot] Part 23: Choosing Level 30 [Tạo 2D Platformer Game với Godot] Part 23: Choose Level 26](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-12-10-56.png)
Then adjust the stars in order from left to right.
![[Tạo 2D Platformer Game với Godot] Part 23: Choose Level 31 [Tạo 2D Platformer Game với Godot] Part 23: Choose Level 27](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-12-11-45.png)
Then I renamed it again.
![[Tạo 2D Platformer Game với Godot] Part 23: Choose Level 32 [Tạo 2D Platformer Game với Godot] Part 23: Choose Level 28](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-12-13-32.png)
Add a Label named SoLevel to display Level.
![[Tạo 2D Platformer Game với Godot] Part 23: Choose Level 34 [Tạo 2D Platformer Game với Godot] Part 23: Choosing Level 30](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-12-13-52-1.png)
I used Customs Font in the previous section.
![[Tạo 2D Platformer Game với Godot] Part 23: Choose Level 35 [Tạo 2D Platformer Game với Godot] Part 23: Choose Level 31](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-12-17-00.png)
Then save the scenes again.
![[Tạo 2D Platformer Game với Godot] Part 23: Choose Level 36 [Tạo 2D Platformer Game với Godot] Part 23: Choose Level 32](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-12-17-56.png)
Then add it the Script.
![[Tạo 2D Platformer Game với Godot] Part 23: Choose Level 38 [Tạo 2D Platformer Game với Godot] Part 23: Choose Level 34](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-12-36-35.png)
Then connect the signal pressed of HinhTron.
Script
extends Control
export (String) var MapName
export (String,FILE) var Scene
export (String) var Level
onready var ngoisaovang = preload("res://Assets/LevelMap/3 UI/Star1.png")
var SoDiem = 0
func _ready():
$SoLevel.text = Level
func _process(delta):
if SoDiem >= 1 and SoDiem <= 30:
$NgoiSao1.texture = ngoisaovang
elif SoDiem >= 30 and SoDiem <= 95:
$NgoiSao1.texture = ngoisaovang
$NgoiSao2.texture = ngoisaovang
elif SoDiem >= 95:
$NgoiSao1.texture = ngoisaovang
$NgoiSao2.texture = ngoisaovang
$NgoiSao3.texture = ngoisaovang
func _on_HinhTron_pressed():
get_tree().change_scene(Scene)
pass # Replace with function body.
As for the code, I will have the above.
![[Tạo 2D Platformer Game với Godot] Part 23: Choose Level 39 [Tạo 2D Platformer Game với Godot] Part 23: Choose Level 35](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-12-29-05.png)
Here I will use export to export 3 variables to Inspector
And Sodiem here I will follow the 100 scale. SoDiem here will be derived from the number of stars that you collect when playing 1 level if all stars are enough, SoDiem is 100 and $NgoiSao1,2,3 will switch to yellow.
line has onready var I use it to load prior to The image of the yellow star means that when you run the game, it will always load, and if you use load(), it will load the image when you touch it.
![[Tạo 2D Platformer Game với Godot] Part 23: Choosing Level 40 [Tạo 2D Platformer Game với Godot] Part 23: Choose Level 36](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-12-32-42.png)
Then Instance the newly created Level into the LevelMap.
![[Tạo 2D Platformer Game với Godot] Part 23: Choose Level 42 [Tạo 2D Platformer Game với Godot] Part 23: Choose Level 38](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-12-33-46.png)
You fill in the information.
MapName is the name of the root node of the underlying Scene.
Scene is you choose the scene of that level.
Level is used to display the level.
![[Tạo 2D Platformer Game với Godot] Part 23: Choose Level 43 [Tạo 2D Platformer Game với Godot] Part 23: Choose Level 39](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-12-33-59.png)
MapName with the root node name.
![[Tạo 2D Platformer Game với Godot] Part 23: Choose Level 44 [Tạo 2D Platformer Game với Godot] Part 23: Choosing Level 40](https://anonyviet.com/wp-content/uploads/2021/11/22-11-2021-12-40-51.png)
And after running the game, I will have the same result as above.
After clicking on it, I will be transferred to Level 1.
summary
In the next part, I will show you how to create a stop menu and when you win a level.








