Timer going down

Hi I've been trying to figure how to do a timer that goes. I know how to up time but I want to down going form 60, 59, 58...

I've got the code for going up

local t = display.newText( "60", 115, 105, "ArialRoundedMTBold", 160 )
t:setTextColor( 0, 0, 0 )

local timeDelay = 500

local t = display.newText( "60", 115, 105, "ArialRoundedMTBold", 160 )
t:setTextColor( 0, 0, 0 )

function t:timer( event )

local count = event.count

self.text = count

if count >= 90 then
timer.cancel( event.source ) -- after the 20th iteration, cancel timer
end
end

timer.performWithDelay( timeDelay, t, -1 )

I've got the timer going up but how would I make it go down.

Hey there, try this;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
display.setStatusBar( display.HiddenStatusBar )
 
local count = 60
local hasRun = 0
 
local t = display.newText( "60", 115, 105, "ArialRoundedMTBold", 160 )
 
local timeDelay = 500
 
function t:timer( event )
 
count = count-1
hasRun = hasRun+1
 
self.text = count
 
if hasRun >= 20 then
timer.cancel( event.source ) -- after the 20th iteration, cancel timer
end
end
 
timer.performWithDelay( timeDelay, t, -1 )

@peach thanks for the sample timer that really worked for my app alot. I'm truly sorry for not appreciating your help. I appreciate a lot and I thank, thank you. :)

Hey,

No worries, I'm happy to help - thanks for the appreciation!

Peach :)

views:1342 update:2011/12/29 9:44:01
corona forums © 2003-2011