2.4 KiB
2.4 KiB
Section 03 - Lesson 15 | Scoring
- Links
- Notes
Notes
add a Label node
-
add Label node to Root node of Game
- child of CanvasItem and Control
- NOT a Node2D
-
appears in upper left corner of the 2D screen
set label text
- go Scene->Label node->Inspector->Label->text
- type in whatever you want, e.g. '0000' for score
make the size bigger
-
Scene->Label node->Inspector->Control->Theme Override
- set the font and font size
move the label
- Scene->Label node->Inspector->Control->Layout->Transform
- change the Position values
if using shadow and offsets
- you set the colors in Theme Overrides
-
change shadow offset and outline size in
- Inspector->Label->Theme Overrides->Constants
Displaying the score
create a var to hold the score
var _score: int
register when the paddle hits a gem
- currently this is a signal on the paddle node
- disconnect paddle from receiving the signal bc we only want game node to receive it
in the game scene
- Scene->Paddle->Node->Signals
- Area2D ->
area_entered - set the register to the Game node
create a reference the Label node
- purpose: modify what the Label displays from the script
using onready
- type it in
@onready var score_label: Label = $Label
-
drag and drop
- grab the node from the Scene panel
- hold down CMD
- drop it on the script
update the score and the label
- update the _score variable in receiving method
-
set the text property in the label reference to the score
func _on_paddle_area_entered(area: Area2D) -> void: _score +=1 label.text = str(_score)
remove the gem from the scene if it hits the padde
- the area2D node passed into the receiver method is a reference to the gem node
-
so you can use the queue_free method to remove it from the scene queue
area.queue_free()