Countdown timer in seconds and milliseconds

Hi there, 

Would someone please help me with implementing a countdown timer in milliseconds?

I know how to implement a countdown timer in seconds the only thing left for me is to play with the format so the milliseconds will show… dunno how to do that. help would be great!

Thanks,

Itay

timer.performWithDelay(1, countMili, 0)

Does this one work or are you searching for an alternative method?

I’m searching for any kind of working method. In my game I want to have a countdown timer in seconds( that shows milliseconds as well) in a 00:000 format. any idea how do I do that?

Thanks in advance,

Itay

It’s the same way as doing it with seconds. It should work when you use the code above and count the miliseconds into another variable and display it.

Please keep in mind the screen is only going to update either 30 or 60 times per second. At 60fps you’re only going to update ever 16.6667 milliseconds. Any attempt to trigger timers faster than that is futile.

You best bet if you want to display what appears to be millisecond times is to use an Runtime “enterFrame” listener, calculate the time off of system.getTimer() and update your display once per frame.

Whatever triggers your timer to stop can grab the system time, compute the final value and then display it.

Rob

Found this piece of code in the forums. tried to play with it so it will suit my needs but unfortunatly couldnt fully understand it.

I want to implement a countdown timer in milliseconds similar to this one in 00:00 format ( seconds:milliseconds ).

local getTimer = system.getTimer; local mFloor   = math.floor; local mAbs     = math.abs; local function round( val, n )     if( n ) then         return math.floor( ( val \* 10 ^ n ) + 0.5 ) / ( 10 ^ n );     else         return math.floor( val + 0.5 );      end end local timerText = display.newText( "", \_CX, \_H \* 0.1, native.systemFont, 22 ); timerText:setFillColor( 0, 0, 0 ); timerText.startTime = getTimer(); timerText.enterFrame = function( self )     local dt = getTimer() - self.startTime;     local remainder = mAbs( round ( dt / 1000 ) - round( dt / 1000 , 4 ) );     remainder = round( remainder, 4 );     print( remainder );     local seconds = round( dt / 1000 );     local nSecs = string.format("%02.4f", mFloor( seconds ) + remainder );     self.text = nSecs; end Runtime:addEventListener( "enterFrame", timerText );

Help would be apreeciated!

Itay

Try looking at this:

https://forums.coronalabs.com/topic/41992-using-timer-to-show-secondsmilliseconds/

I’ve tried… more or less like the code I pasted above. still cannot understand how do I change that to a countdown timer. cannot manage to find any useful info in the forums about the subject. thanks for the link by way.

Itay

timer.performWithDelay(1, countMili, 0)

Does this one work or are you searching for an alternative method?

I’m searching for any kind of working method. In my game I want to have a countdown timer in seconds( that shows milliseconds as well) in a 00:000 format. any idea how do I do that?

Thanks in advance,

Itay

It’s the same way as doing it with seconds. It should work when you use the code above and count the miliseconds into another variable and display it.

Please keep in mind the screen is only going to update either 30 or 60 times per second. At 60fps you’re only going to update ever 16.6667 milliseconds. Any attempt to trigger timers faster than that is futile.

You best bet if you want to display what appears to be millisecond times is to use an Runtime “enterFrame” listener, calculate the time off of system.getTimer() and update your display once per frame.

Whatever triggers your timer to stop can grab the system time, compute the final value and then display it.

Rob

Found this piece of code in the forums. tried to play with it so it will suit my needs but unfortunatly couldnt fully understand it.

I want to implement a countdown timer in milliseconds similar to this one in 00:00 format ( seconds:milliseconds ).

local getTimer = system.getTimer; local mFloor   = math.floor; local mAbs     = math.abs; local function round( val, n )     if( n ) then         return math.floor( ( val \* 10 ^ n ) + 0.5 ) / ( 10 ^ n );     else         return math.floor( val + 0.5 );      end end local timerText = display.newText( "", \_CX, \_H \* 0.1, native.systemFont, 22 ); timerText:setFillColor( 0, 0, 0 ); timerText.startTime = getTimer(); timerText.enterFrame = function( self )     local dt = getTimer() - self.startTime;     local remainder = mAbs( round ( dt / 1000 ) - round( dt / 1000 , 4 ) );     remainder = round( remainder, 4 );     print( remainder );     local seconds = round( dt / 1000 );     local nSecs = string.format("%02.4f", mFloor( seconds ) + remainder );     self.text = nSecs; end Runtime:addEventListener( "enterFrame", timerText );

Help would be apreeciated!

Itay

Try looking at this:

https://forums.coronalabs.com/topic/41992-using-timer-to-show-secondsmilliseconds/

I’ve tried… more or less like the code I pasted above. still cannot understand how do I change that to a countdown timer. cannot manage to find any useful info in the forums about the subject. thanks for the link by way.

Itay