-
Notifications
You must be signed in to change notification settings - Fork 1
/
typo.lua
54 lines (41 loc) · 876 Bytes
/
typo.lua
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
local typo = {}
function typo.new(text, delay, width, align, x, y, font, colour)
local t = {
t = text,
delay = delay,
width = width,
align = align,
x = x,
y = y,
font = font,
colour = colour,
string = {},
index = 1,
timer = 0,
text = ''
}
local i = 1
for c in text:gmatch('.') do
t.string[i] = c
i = i + 1
end
table.insert(typo, t)
end
function typo.update(dt)
for i,v in ipairs(typo) do
v.timer = v.timer + dt
if v.timer >= v.delay and v.index <= #v.string then
v.text = v.text .. tostring(v.string[v.index])
v.index = v.index + 1
v.timer = 0
end
end
end
function typo.draw()
for i,v in ipairs(typo) do
love.graphics.setColor(v.colour)
love.graphics.setFont(v.font)
love.graphics.printf(v.text, v.x, v.y, v.width, v.align)
end
end
return typo