I need to create a countdown timer that displays Minutes and Seconds only. Can someone post an example code of how I would do this from lets say 2:00 and then when the timer is at 0 I need it to play a sound. I can figure out the buttons probably so I just need the timer code. [import]uid: 226740 topic_id: 36039 reply_id: 336039[/import]
I have this timer but is not countdown maybe help you
[lua]
local startButtonText = display.newText( “Tap To Start”, 0, 0, native.systemFont, 24 )
startButtonText.x = W / 2; startButtonText.y = (H / 2) + 80
startButtonText:setTextColor( 255, 255, 255 )
– Create basic start/stop button
local timerCount = display.newText( “00:00:0”, 0, 0, native.systemFont, 38 )
timerCount.x = W / 2; timerCount.y = (H / 4) - 60
timerCount:setTextColor( 255, 255, 255 )
local function startTimer(e)
startButtonText:removeSelf()
startButtonText = nil
function timerCount:timer( event )
local count = event.count
tenthSeconds = math.floor(count % 10)
seconds = math.floor(count / 10 ); seconds = math.floor(seconds % 60)
minutes = math.floor(count / 600); minutes = math.floor(minutes % 60)
timeFormat = string.format("%02d:%02d:%01d", minutes, seconds, tenthSeconds)
self.text = timeFormat
if count >= 6000 then
timer.cancel( event.source ) – Cancel timer after 10 mins
end
end
timer.performWithDelay( 100, timerCount, 6000 ) – Call timerCount function every 1/10th second for 10 minutes
end
startTimer() [/lua] [import]uid: 154714 topic_id: 36039 reply_id: 143191[/import]
I have this timer but is not countdown maybe help you
[lua]
local startButtonText = display.newText( “Tap To Start”, 0, 0, native.systemFont, 24 )
startButtonText.x = W / 2; startButtonText.y = (H / 2) + 80
startButtonText:setTextColor( 255, 255, 255 )
– Create basic start/stop button
local timerCount = display.newText( “00:00:0”, 0, 0, native.systemFont, 38 )
timerCount.x = W / 2; timerCount.y = (H / 4) - 60
timerCount:setTextColor( 255, 255, 255 )
local function startTimer(e)
startButtonText:removeSelf()
startButtonText = nil
function timerCount:timer( event )
local count = event.count
tenthSeconds = math.floor(count % 10)
seconds = math.floor(count / 10 ); seconds = math.floor(seconds % 60)
minutes = math.floor(count / 600); minutes = math.floor(minutes % 60)
timeFormat = string.format("%02d:%02d:%01d", minutes, seconds, tenthSeconds)
self.text = timeFormat
if count >= 6000 then
timer.cancel( event.source ) – Cancel timer after 10 mins
end
end
timer.performWithDelay( 100, timerCount, 6000 ) – Call timerCount function every 1/10th second for 10 minutes
end
startTimer() [/lua] [import]uid: 154714 topic_id: 36039 reply_id: 143191[/import]
I have this timer but is not countdown maybe help you
[lua]
local startButtonText = display.newText( “Tap To Start”, 0, 0, native.systemFont, 24 )
startButtonText.x = W / 2; startButtonText.y = (H / 2) + 80
startButtonText:setTextColor( 255, 255, 255 )
– Create basic start/stop button
local timerCount = display.newText( “00:00:0”, 0, 0, native.systemFont, 38 )
timerCount.x = W / 2; timerCount.y = (H / 4) - 60
timerCount:setTextColor( 255, 255, 255 )
local function startTimer(e)
startButtonText:removeSelf()
startButtonText = nil
function timerCount:timer( event )
local count = event.count
tenthSeconds = math.floor(count % 10)
seconds = math.floor(count / 10 ); seconds = math.floor(seconds % 60)
minutes = math.floor(count / 600); minutes = math.floor(minutes % 60)
timeFormat = string.format("%02d:%02d:%01d", minutes, seconds, tenthSeconds)
self.text = timeFormat
if count >= 6000 then
timer.cancel( event.source ) – Cancel timer after 10 mins
end
end
timer.performWithDelay( 100, timerCount, 6000 ) – Call timerCount function every 1/10th second for 10 minutes
end
startTimer() [/lua] [import]uid: 154714 topic_id: 36039 reply_id: 143191[/import]
I have this timer but is not countdown maybe help you
[lua]
local startButtonText = display.newText( “Tap To Start”, 0, 0, native.systemFont, 24 )
startButtonText.x = W / 2; startButtonText.y = (H / 2) + 80
startButtonText:setTextColor( 255, 255, 255 )
– Create basic start/stop button
local timerCount = display.newText( “00:00:0”, 0, 0, native.systemFont, 38 )
timerCount.x = W / 2; timerCount.y = (H / 4) - 60
timerCount:setTextColor( 255, 255, 255 )
local function startTimer(e)
startButtonText:removeSelf()
startButtonText = nil
function timerCount:timer( event )
local count = event.count
tenthSeconds = math.floor(count % 10)
seconds = math.floor(count / 10 ); seconds = math.floor(seconds % 60)
minutes = math.floor(count / 600); minutes = math.floor(minutes % 60)
timeFormat = string.format("%02d:%02d:%01d", minutes, seconds, tenthSeconds)
self.text = timeFormat
if count >= 6000 then
timer.cancel( event.source ) – Cancel timer after 10 mins
end
end
timer.performWithDelay( 100, timerCount, 6000 ) – Call timerCount function every 1/10th second for 10 minutes
end
startTimer() [/lua] [import]uid: 154714 topic_id: 36039 reply_id: 143191[/import]