I am programmatically adding a label to the screen, which drifts up then fades out. The problem I am having is if I add multiple instances they seem to be using the same rect_position
and overlap on top of each other:
FadlingLabel.gd:
extends Label
class_name FadingLabel
var action_start = null
const LABEL_RISE_SPEED = 15
const ACTION_TIME = 5
const FADE_DELAY = 3
func _process(delta):
if action_start != null:
action_start = action_start + delta
rect_position = rect_position - Vector2(0, LABEL_RISE_SPEED * delta)
if (ACTION_TIME - action_start < FADE_DELAY):
modulate.a = 1.0 - ((action_start-FADE_DELAY) / (ACTION_TIME-FADE_DELAY))
if (action_start >= ACTION_TIME):
queue_free()
func start_fade(string, pos):
set_text(string)
rect_position = pos
action_start = 0
And using like so:
var energy_tick = FadingLabel.new()
add_child(energy_tick)
energy_tick.start_fade(ENERGY_USED_FORMAT_STRING % amount, Vector2(200, 200))