ステータスバー、ヘルスバー

構成はControlの下にVBOXとHBOXを入れてLabelとProgressBar

ProgressBar単体の処理
数値で色を変える処理を入れている
extends ProgressBar
func _on_value_changed(value: float) -> void:
_change_color(value)
func _change_color(value):
var color: Color = Color.GREEN
if value <= 25:
color = Color.RED
elif value <= 50:
color = Color.YELLOW
get("theme_override_styles/fill").bg_color = color
StatusBarで100からの引き算でバーを表示する。
プレイヤーから値を継承していないので単純に減っていくのみになる
extends Control
@onready var helth_bar: ProgressBar = $VBoxContainer/Helth/HelthBar
@onready var magic_bar: ProgressBar = $VBoxContainer/Magic/MagicBar
var helth = 100
var magic = 100
func _ready() -> void:
_refresh_helth()
_refresh_magic()
func _refresh_helth():
helth_bar.value = helth
func _refresh_magic():
magic_bar.value = magic
func _on_helth_timer_timeout() -> void:
helth -= 5
helth = clamp(helth, 0, 100)
_refresh_helth()
func _on_magic_timer_timeout() -> void:
magic -= 5
magic = clamp(magic, 0, 100)
_refresh_magic()