- Edited
This is the health bar for a game I'm helping someone develop:
I want the bbcode text that displays the amount of HP left to shake when the player's HP gets below a set threshold. The problem is that because I have to constantly set the bbcode text to update the player's current health - and this resets the [shake][/shake] tag for some reason, making appear as though the text is not moving.
I haven't been able to do what I wanted yet, and have tried several different approaches to it - is this simply impossible?
This is what the local node tree looks like if this helps at all:
extends Control
# Declare member variables here. Examples:
export(int) var max_health = 20
export(int, 0, 20) var current_health = 20
export(int) var warning_lvl = 10
export(int) var shake_rate = 20
export(int) var shake_amount = 10
var text = "[center]" + str(current_health) + " / "+ str(max_health) +"[/center]"
var still = true
# Called when the node enters the scene tree for the first time.
func _ready():
$HPC/HPBar.max_value = max_health
$HPC/HPBar.value = current_health
find_node("HPPercentage").bbcode_text = text # The RichTextLabel being referenced
func set_health(hp):
current_health = hp
if current_health <= warning_lvl:
still = true
func add_health(hp):
current_health += hp
if current_health > max_health:
current_health = max_health
if current_health <= warning_lvl:
still = true
func sub_health(hp):
current_health -= hp
if current_health < 0:
current_health = 0
if current_health <= warning_lvl:
still = true
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
$HPC/HPBar.max_value = max_health # HPBar is a TextureProgress node
$HPC/HPBar.value = current_health
if current_health <= warning_lvl and still:
text = "[center][shake rate=" + str(shake_rate) + " level=" + str(shake_amount) + "]" + str(current_health) + " / "+ str(max_health) + "[/shake][/center]"
still = false
if current_health > warning_lvl:
text = "[center]" + str(current_health) + " / "+ str(max_health) +"[/center]"
find_node("HPPercentage").bbcode_text = text