diff --git a/typo.lua b/typo.lua new file mode 100644 index 0000000..da2b2dc --- /dev/null +++ b/typo.lua @@ -0,0 +1,50 @@ +typo = {} + +function typo_new(text, delay, width, align, x, y, font) + local t = { + t = text, + delay = delay, + width = width, + align = align, + x = x, + y = y, + font = font, + + 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.setFont(v.font) + love.graphics.printf(v.text, v.x, v.y, v.width, v.align) + end +end \ No newline at end of file