Flopsy/objects/speech_bubble/speech_bubble.gd

37 lines
689 B
GDScript

extends ReferenceRect
export var speed : float = 0.05
export var flip_h : bool
export var pitch : float = 1
signal animation_ready
func _ready():
modulate.a = 0
if flip_h:
$Arrow.flip_h = true
$Arrow.set_position(Vector2(0, rect_size.y))
$TypeSound.pitch_scale = pitch
func say(text : String):
var tree = get_tree()
$Label.visible_characters = 0
$Label.text = text
if modulate.a != 1:
$Animation.play("fade")
for i in text.length() + 1:
$Label.visible_characters = i
$TypeSound.play()
if tree != null:
yield(tree.create_timer(speed), "timeout")
emit_signal("animation_ready")
func fade_out():
if modulate.a != 0:
$Animation.play_backwards("fade")