I was trying something like this:
My timer function
func create_timer(duration, body, function, oneshot):
timer = Timer.new()
timer.set_one_shot(oneshot)
timer.set_wait_time(duration)
timer.connect("timeout", body, function)
add_child(timer)
timer.start()
func update_health():
while health_bar.value > enemy.health:
create_timer(.25, self, "update_health_bar", true)
func update_health_bar():
health_bar.value -= 1
Which ended up making my game unresponsive whenever it tried updating the health bar. I was trying to decrease the value of the texture bar by 1 every x amount of seconds until it equaled the current health of the enemy/player.
My other attempt was to have a variable called update_healthbar and have it set to false by default.
func _process(delta):
if update_healthbar:
while health_bar.value > enemy.health:
health_bar.value -= delta * (some number)
update_healthbar = false
func update_health():
update_health_bar = true
In this try, if the number i multiplied by delta was greater than 30, the health bar appeared to update instantly all at once. Anything lower would lead to the game crashing like my first attempt.