Tutorial 18.3 Player Stats with HP Label
This commit is contained in:
19
ActionRPG-HeartBeast/UI/HealthUI.gd
Normal file
19
ActionRPG-HeartBeast/UI/HealthUI.gd
Normal file
@ -0,0 +1,19 @@
|
||||
extends Control
|
||||
|
||||
var hearts = 4 setget set_hearts
|
||||
var max_hearts = 4 setget set_max_hearts
|
||||
|
||||
onready var label = $Label
|
||||
|
||||
func set_hearts(value):
|
||||
hearts = clamp(value, 0, max_hearts)
|
||||
if label != null:
|
||||
label.text = "HP = " + str(hearts)
|
||||
|
||||
func set_max_hearts(value):
|
||||
max_hearts = max(value, 1)
|
||||
|
||||
func _ready():
|
||||
self.max_hearts = PlayerStats.max_health
|
||||
self.hearts = PlayerStats.health
|
||||
PlayerStats.connect("health_changed", self, "set_hearts")
|
13
ActionRPG-HeartBeast/UI/HealthUI.tscn
Normal file
13
ActionRPG-HeartBeast/UI/HealthUI.tscn
Normal file
@ -0,0 +1,13 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://UI/HealthUI.gd" type="Script" id=1]
|
||||
|
||||
[node name="HealthUI" type="Control"]
|
||||
margin_right = 122.0
|
||||
margin_bottom = 25.0
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
margin_right = 42.0
|
||||
margin_bottom = 14.0
|
||||
text = "HP = 4"
|
Reference in New Issue
Block a user