Created
July 22, 2015 04:40
-
-
Save gould/4b6c59db72e6aa5c0999 to your computer and use it in GitHub Desktop.
typer for WP8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--------------------------------- | |
-- Typer | |
local function typer(options) | |
local audio = require"gamkin.audio" | |
local text = options.text or options.target and options.target.text | |
if u.empty(text) then | |
text = "." | |
end | |
local position = 1 | |
local textSpecs = u.extend({}, options) | |
textSpecs.text = "" | |
local textHolder = options.target or display.newText(textSpecs) | |
local time = options.time or 1000 | |
local dt = options.dt or (time/#text) | |
dt = math.max(20, dt) -- Actual time due to fps limits | |
time = dt *#text | |
local ch = audio:playTyper({volume=0.5, loops=-1}) | |
local function cleanUp() | |
textHolder.text = text | |
-- if ch then | |
-- audio:stop(ch) | |
-- ch = nil | |
-- end | |
if options.onComplete then | |
options.onComplete() | |
end | |
end | |
local typeTimer = timer.performWithDelay(dt, function( ... ) | |
-- textHolder.text = text:sub(1, position)..(" "):rep(#text -position) | |
-- if position == #text then | |
cleanUp() | |
-- else | |
-- position = position+1 | |
-- end | |
end, 1) | |
function textHolder:complete() | |
timer.cancel(typeTimer) | |
cleanUp() | |
end | |
return textHolder | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment