-
Notifications
You must be signed in to change notification settings - Fork 1
/
TextAppearance.gd
77 lines (73 loc) · 2.09 KB
/
TextAppearance.gd
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
extends Label
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
export (float) var letterApparitionWaitTime = 0.1
export (float) var punctApparitionWaitTime = 0.3
export (float) var otherApparitionWaitTime = 0.1
export (float) var letterDisappearenceWaitTime = 0.05
export (float) var punctDisappearenceWaitTime = 0.05
export (float) var otherDisappearenceWaitTime = 0.05
const CHARS = "abcdefghijklmnopqrstuvwxyz"
const PUNCT = ",.:-?!"
const NONVIS = "\n\t "
var changing = false
var appearing = true
onready var timer = 0.1
var wait_time = 0
var count = 0
var is_visible_char =true
func _ready():
visible_characters = 0
wait_time = 0.1
start_appear()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if changing:
timer += delta
if timer >= wait_time:
timer = 0
if is_visible_char:
if appearing:
visible_characters += 1
else:
visible_characters -= 1
is_visible_char = true
if visible_characters+count != text.length() and visible_characters != 0:
if CHARS.find(text.substr(visible_characters + count-1, 1)) != -1:
if appearing:
wait_time = letterApparitionWaitTime
else:
wait_time = letterDisappearenceWaitTime
elif PUNCT.find(text.substr(visible_characters + count-1, 1)) != -1:
if appearing:
wait_time = punctApparitionWaitTime
else:
wait_time = punctDisappearenceWaitTime
else:
if NONVIS.find(text.substr(visible_characters + count-1, 1)) != -1:
if appearing:
count += 1
else:
count -= 1
is_visible_char = false
if appearing:
timer = otherApparitionWaitTime
else:
timer = otherDisappearenceWaitTime
if appearing:
wait_time = otherApparitionWaitTime
else:
wait_time = otherDisappearenceWaitTime
else:
changing = false
if Input.is_action_just_pressed("text_appear"):
start_appear()
if Input.is_action_just_pressed("text_disappear"):
start_disappear()
func start_appear():
changing = true
appearing = true
func start_disappear():
changing = true
appearing = false