summaryrefslogtreecommitdiff
path: root/components/textreveal.gd
blob: ed048e18420d463d52cb3431cfcab58d98f42f11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
extends Label
class_name TextReveal

signal finished_reveal()

export(String, MULTILINE) var to_render = "Text"
export var speed = 100.0

############
# INTERNAL #
############


var revealed = 0
var started = false
var finished = false
var t = 0

# Called when the node enters the scene tree for the first time.
func _ready():
	theme = preload("res://fonts/Flipps_Theme.tres")
	align = Label.ALIGN_CENTER

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	if not started:
		return
	t += delta * speed
	var additional = int(t)
	t -= additional
	revealed += additional
	text = to_render.substr(0, revealed)
	rect_position = -rect_size / 2
	if to_render.length() <= revealed:
		started = false
		finished = true
		emit_signal("finished_reveal")

func start():
	started = true
	text = ""
	revealed = 0
	t = 0
	finished = false


func has_finished():
	return finished