We need to create a way for the player to see how many coins they have collected.
We need to create a way for the player to see how many coins they have collected.
Open your Player Scene.
Open your Player Scene.
Add a Label Node
Add a Label Node
Godot will switch to 2D mode
Godot will switch to 2D mode
All UI is done in a 2D space.
All UI is done in a 2D space.
The editor shows a blue square,
The editor shows a blue square,
this is the size of our game window,
this is the size of our game window,
and all elements placed inside
and all elements placed inside
will be visible on the screen.
will be visible on the screen.
Position elements by dragging mouse,
Position elements by dragging mouse,
and scale them using the orange circles
and scale them using the orange circles
Place the label top left.
Place the label top left.
Add text in the inspector
Add text in the inspector
This updates in the Scene
This updates in the Scene
Score is now also visible in the game window but we will now increase the font size.
Score is now also visible in the game window but we will now increase the font size.
Click on Label Settings
Click on Label Settings
Add New LabelSettings
Add New LabelSettings
Now change:
Now change:
Font Size
Font Size
Outline Size
Outline Size
Outline Colour
Outline Colour
Now the score is more visible
Now the score is more visible
Rename the label to ScoreText
Rename the label to ScoreText
Updating the score programmatically
Updating the score programmatically
Add a reference variable to our label node:
Add a reference variable to our label node:
Now update the label in add_score()
Now update the label in add_score()
str() converts numeric values to text.
str() converts numeric values to text.
Play Test your game to ensure it is working as expected.
Play Test your game to ensure it is working as expected.