ring/scenes/slideshow.lua

42 lines
1.0 KiB
Lua

local love = assert( love )
local scene = require( "scene" )
local settings = require( "scenes.settings" )
local strings = require( "i18n.en" )
local printString
local fullString
local loadNextScene
local utf8 = require( "utf8" )
local t = {}
local len = 0
local time = 0
function t.keypressed( key, code, isRepeat )
if code == "return" then return loadNextScene() end
end
function t.draw()
love.graphics.printf( printString, 10, 10, math.min( 400, love.graphics.getWidth() / 2 ), "left" )
love.graphics.print( strings.toContinue, 10, love.graphics.getHeight() - love.graphics.getFont():getHeight() )
end
function t.update( dt )
time = time + dt
if time > 0.05 then
time = 0
len = len + 1
if len > fullString:len() + 40 then return loadNextScene() end
printString = fullString:sub( 1, ( utf8.offset( fullString, len ) or 0 ) - 1 )
end
end
function t.play( str, nextScene )
loadNextScene = nextScene
fullString = str
printString = ""
return scene.load( t )
end
return t