Last active
August 29, 2015 14:20
-
-
Save coronarob/05accd04ce581b81572f to your computer and use it in GitHub Desktop.
A sample countdown timer
This file contains 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
display.setDefault("background", 0.2, 0.2, 0.4 ) | |
-- Keep track of time in seconds | |
local secondsLeft = 20 * 60 -- 20 minutes * 60 seconds | |
local clockText = display.newText("20:00", display.contentCenterX, 80, native.systemFontBold, 80) | |
clockText:setFillColor( 0.7, 0.7, 1 ) | |
local function updateTime() | |
-- decrement the number of seconds | |
secondsLeft = secondsLeft - 1 | |
-- time is tracked in seconds. We need to convert it to minutes and seconds | |
local minutes = math.floor( secondsLeft / 60 ) | |
local seconds = secondsLeft % 60 | |
-- make it a string using string format. | |
local timeDisplay = string.format( "%02d:%02d", minutes, seconds ) | |
clockText.text = timeDisplay | |
end | |
-- run them timer | |
local countDownTimer = timer.performWithDelay( 1000, updateTime, secondsLeft ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment