finished scoring
This commit is contained in:
parent
a4324f0294
commit
7ad10083dd
2 changed files with 68 additions and 1 deletions
|
|
@ -41,7 +41,7 @@ Put the following in the script that you want to create nodes in based on a scen
|
|||
- allows assigning variables through the interface
|
||||
|
||||
#+ATTR_HTML: :width 300px
|
||||
[[file:../../../_share/media/albert/img/section03/S03_L15_EX01.png]]
|
||||
[[file:../../../_share/media/albert/img/section03/S03_L14_EX01.png]]
|
||||
|
||||
- =PackedScene=
|
||||
- resource that holds a scene in a packed, ready to load state
|
||||
|
|
|
|||
|
|
@ -7,3 +7,70 @@
|
|||
- [[https://www.udemy.com/course/jumpstart-to-2d-game-development-godot-4-for-beginners/learn/lecture/45070487#announcements][S03:L26.15 - Scoring]]
|
||||
|
||||
* 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
|
||||
|
||||
#+ATTR_HTML: :width 600px
|
||||
[[file:../../../_share/media/albert/img/section03/S03_L15_EX01.png]]
|
||||
|
||||
*** 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
|
||||
#+BEGIN_SRC gdscript
|
||||
var _score: int
|
||||
#+END_SRC
|
||||
|
||||
*** 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
|
||||
1. type it in
|
||||
#+BEGIN_SRC gdscript
|
||||
@onready var score_label: Label = $Label
|
||||
#+END_SRC
|
||||
|
||||
2. 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
|
||||
#+BEGIN_SRC gdscript
|
||||
func _on_paddle_area_entered(area: Area2D) -> void:
|
||||
_score +=1
|
||||
label.text = str(_score)
|
||||
#+END_SRC
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue