Lib timer
Timer library.
Based on hump.timer.
Functions
| new () | Create new timer instance. |
| addPeriodic (delay, func[, count]) | Schedule a function that is called periodically. |
| doFor (delta, func[, after]) | Execute a function every frame until time expires. |
| cancel (handle) | Cancel a timer. |
| clear () | Cancel all timers. |
| update (dt) | Update the timer. |
| tween (duration, subject, target[, method='linear'][, after], ...) | Create a tween. |
Functions
- new ()
-
Create new timer instance.
By default all functions are called on a single global instance.
Returns:
-
Timer
timer instance
Usage:
local specialTimer = timer.new() specialTimer.add(10, function() print("yay!") end) -- print "yay!" after 10 seconds specialTimer.update( dt ) -- call this every frame
- addPeriodic (delay, func[, count])
-
Schedule a function that is called periodically.
Add a function that will be called
counttimes everydelayseconds. Ifcountis omitted, the function will be called until it returns false or timer.cancel or timer.clear is called.Parameters:
- delay number seconds between consecutive calls
- func function function to execute periodically
- count number number of times the function is called (optional)
Returns:
-
table
timer handle
- doFor (delta, func[, after])
-
Execute a function every frame until time expires.
Optionally runs
after()oncedeltaseconds have passed.Parameters:
- delta
number
number of seconds that the function
funcwill be called - func function function to execute every frame
- after
function
function to execute once
deltaseconds expired (optional)
- delta
number
number of seconds that the function
- cancel (handle)
-
Cancel a timer.
Parameters:
- handle table timer handle
- clear ()
- Cancel all timers.
- update (dt)
-
Update the timer.
Parameters:
- dt number delta time
- tween (duration, subject, target[, method='linear'][, after], ...)
-
Create a tween.
Readh the hump.timer tween section for more information.
Parameters:
- duration number duration of tween
- subject table object to be tweened
- target table target values
- method string tweening method (default 'linear')
- after function function to execute after the tween finished (optional)
- ... mixed additional arguments for the tweening function (amplitude, period or bounciness)