The heads up display (HUD) will display info such as score, time remaining, game over messages and a start button.
Add a CanvasLayer node and rename it to HUD
Save the scene as hud.tscn
A CanvasLayer acts like a clear sheet of glass placed directly over your game screen. Any UI elements you place inside it (like scores, health bars, timers or buttons) will always stay glued to the screen in front of the action, completely unaffected by camera movement or player position.
Add a Label node to the scene
Rename it to GameStatusLabel
Set the Label's Anchor to
This ensures it occupies the full width of the screen
Now set both Horizontal Alignment and Vertical Alignment to Center
Finally set the text to Coin Grabber!
Select New Label Settings
Click and Expand Label Settings
Drag the Kenney Bold.ttf font
Experiment with shadows and outlines!
Add a MarginContainer node
Duplicate the GameStatusLabel twice
Rename the duplicates to ScoreLabel and TimeLabel
Set both their Text properties to 0
Drag them under the MarginContainer
Set the Horizontal Alignment of ScoreLabel to Right
Set the Horizontal Alignment of TimeLabel to Left
Add a Timer node as a child of HUD
Set Wait Time to 2s and One Shot to On
Set the Text property to START
Set the Button Anchor to Center Bottom
To make the components functional
Attach a script to the HUD node
Create a custom signal to broadcast the start of the game
Previously we connected signals
This time we will connect the signal using code
Connect the timout signal for the timer
Connect the pressed signal for the button
Create the two functions we are connecting to
Finally, create a function
For when the game is lost
Connect the Timeout signal of GameTimer
Either via code or the Inspector
Create the game_over function
Connect its start_game() signal
Remove the call to new_game from the ready function!
Connect the pickup signal
Either in code or via Inspector
Update the new_game function
Now press F5 to run the game
Select Current to set Main as the Main scene
The first scene which runs when starting the game
Now we can refine and improve it.