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