×
A new build of Corona SDK is now available to subscribers. Not a subscriber? Subscribe now.
CoronaSDK 2012.741 | Released: 7 Feb 2012, 8:45am | What's New | Download Now

Timer

Features demonstrated:

A table listener

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
local background = display.newImage( "color_blur.png" )
 
local t = display.newText( "0", 115, 105, "ArialRoundedMTBold", 160 )
t:setTextColor( 0, 0, 0 )
 
function t:timer( event )
        local count = event.count
 
        print( "Table listener called " .. count .. " time(s)" )
        self.text = count
 
        if count >= 20 then
                timer.cancel( event.source ) -- after the 20th iteration, cancel timer
        end
end
 
-- Register to call t's timer method 50 times
timer.performWithDelay( 500, t, 50 )