clowder/scripts/typewrite.gd
2024-03-03 21:17:01 +01:00

20 lines
477 B
GDScript

extends CanvasLayer
@onready var label = $Sprite2D/RichTextLabel
signal Done
func typewrite(text,sound,speed, hide_after):
visible = true
label.text = text
label.visible_characters = 0
$AudioStreamPlayer.stream = sound
var wait_time = speed / len(text)
for i in range(len(text)+1):
label.visible_characters = i
$AudioStreamPlayer.play()
await get_tree().create_timer(wait_time).timeout
await get_parent().interact
if hide_after:
visible = false
Done.emit()