I want a countdown timer that counts down from 2 min (could be adjustable). It needs to display minutes and seconds in m:ss( e.g. “1:58”) format. also it needs to stop at 0:00.
Any Ideas? [import]uid: 104376 topic_id: 22096 reply_id: 322096[/import]
I want a countdown timer that counts down from 2 min (could be adjustable). It needs to display minutes and seconds in m:ss( e.g. “1:58”) format. also it needs to stop at 0:00.
Any Ideas? [import]uid: 104376 topic_id: 22096 reply_id: 322096[/import]
This one counts up but could easily be changed to count down; http://techority.com/2011/09/14/display-a-timer-minutes-and-seconds/
Plug and play 
Peach [import]uid: 52491 topic_id: 22096 reply_id: 87783[/import]
I created this code but it doesn’t work.
[lua]local secsText = 00
local minsText = 2
local timeText = display.newText(minsText… “:” …secsText, 40, 40, “Helvetica”, 24)
timeText:setTextColor(255,255,255)
local function updateTime (event)
secsText = secsText - 1
if secsText < 10 then secsText = “0” …secsText elseif secsText < 00 then
secsText = 59
minsText = minsText-1
end
timeText.text = minsText … “:” …secsText
end
timer.performWithDelay(1000, updateTime, 0) [import]uid: 104376 topic_id: 22096 reply_id: 87797[/import]
Do you know what is the problem? [import]uid: 104376 topic_id: 22096 reply_id: 87824[/import]
Do you know what is the problem? [import]uid: 104376 topic_id: 22096 reply_id: 87825[/import]
Oh, I found bugs in Peach’s code… O_O
I might be wrong but you can’t assign a string value to an integer like there
if secsText \< 10 then secsText = "0" ..secsText elseif secsText \< 00 then
I tried this code and it worked fine. One thing, you NEED to put “:0” on line 4 else your timer will start with “2:0” instead. You can change that if you start with “2:30” or any number higher than 9.
[code]local secsText = 0
local minsText = 2
local timeText = display.newText(minsText… “:0” …secsText, 40, 40, “Helvetica”, 24)
timeText:setTextColor(255,255,255)
local function updateTime(event)
secsText = secsText - 1
if secsText < 0 then
secsText = 59
minsText = minsText-1
end
if secsText < 10 then
timeText.text = minsText … “:0” …secsText
else
timeText.text = minsText … “:” …secsText
end
end
timer.performWithDelay(1000, updateTime, 0)[/code]
You could also create a function containing the “under 10 seconds check” and call it each time you need to redraw the string on screen. This would allow you to change the value of secsText without having to change the initial “:0” each time.
~Lew [import]uid: 1058 topic_id: 22096 reply_id: 87846[/import]
Yes, that works!
now do you know how to make the timer paused when the app starts, and then start it when gameIsActive = true?
And also when the timer reaches 0:00 make gameIsActive = false? [import]uid: 104376 topic_id: 22096 reply_id: 87918[/import]
Damn, that should have been updated - I did write a new version after someone commented but must have saved it as a draft - thanks Lewie 
Stieven, there is a timer.pause and timer.resume function which you can read about on API page.
For it reaching 0:00 you could do a second timer or say if minutes == 0 and seconds == 0 then gameIsActive = false. [import]uid: 52491 topic_id: 22096 reply_id: 87991[/import]