clowder/scripts/typewrite.gd

20 lines
477 B
GDScript3
Raw Normal View History

2024-03-03 20:22:50 +01:00
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()