summaryrefslogtreecommitdiff
path: root/components/textreveal.gd
blob: 9b5bfaa5fce4736ae68e3cc958170024ef6d0842 (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
49
50
51
52
53
extends Label
class_name TextReveal

signal finished_reveal()

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

export var xpos = 0
export var ypos = 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")
	rect_position = Vector2(xpos, ypos)

# 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
	if additional >= 1:
		BackgroundMusic.type_sound()
	text = to_render.substr(0, revealed)
	rect_position = -rect_size / 2 + Vector2(xpos, ypos)
	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