Timer

Type     [gd]

class

Library

core

Inheritance

Timer ➝ Object

See also [bg]

Display:addTimer()


Overview


  Creates a timer event that calls user function after user-set time. Timer class inherits Object class.



Syntax



local obj = Timer(time, func [, loops [, onEnd]] )


• time : (required) delay time in milli-second

• func : (required) callback function. After 'time' milli-seconds, func is called

• loops : (optional: default value is 1) repeating number.

               if loops is INF, then func is periodically called forever

• onEnd : (optional) this function is called when 'func' is called 'loops' times.


Note: The timer object is removed automatically when the 'func' is called 'loops' times.


The func receives a table as a first argument containing the following fields

    • count : number of calling func

    • isFinal : true if this is the final call of func

    • time : elapsed time in milli-second


Methods



methods

description

return value

obj:pause()

pause timer

self

obj:resume()

resume timer

self

obj:remove()

remove timer object immediately.

nil

obj:isRemoved()

return true if timer object is removed already

boolean

obj:isPaused()

return true if timer object is paused

boolean




Examples


-- after 1 second, '1s' is printed

Timer( 1000, function() print('1s') end)



-- scale up by 0.1 five times in every 2 seconds

local moon = Image('moon.png')

local func = function(e)

    moon:setScale(1 + e.count*0.1)

end

Timer(2000, func, 5)


댓글 없음:

댓글 쓰기