Difference between revisions of "Timer"
(remove language stuff) |
(added Timer:pause()) |
||
Line 35: | Line 35: | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
=== Methods === | === Methods === | ||
− | [[Timer.delayedCall]] '' | + | [[Timer.delayedCall]] ''delay calls a function after a set amount of time''<br/><!--GIDEROSMTD:Timer.delayedCall(delay,func,data) delay calls a function after a set amount of time--> |
[[Timer.new]] ''creates a new Timer object''<br/><!--GIDEROSMTD:Timer.new(delay,repeatCount) creates a new Timer object--> | [[Timer.new]] ''creates a new Timer object''<br/><!--GIDEROSMTD:Timer.new(delay,repeatCount) creates a new Timer object--> | ||
− | [[Timer.pauseAll]] '' | + | [[Timer.pauseAll]] ''pauses all timers''<br/><!--GIDEROSMTD:Timer.pauseAll() pauses all timers--> |
− | [[Timer.resumeAll]] '' | + | [[Timer.resumeAll]] ''resumes all timers''<br/><!--GIDEROSMTD:Timer.resumeAll() resumes all timers--> |
− | [[Timer.stopAll]] '' | + | [[Timer.stopAll]] ''stops all timers''<br/><!--GIDEROSMTD:Timer.stopAll() stops all timers--> |
[[Timer:getCurrentCount]] ''returns the current trigger count of the timer''<br/><!--GIDEROSMTD:Timer:getCurrentCount() returns the current trigger count of the timer--> | [[Timer:getCurrentCount]] ''returns the current trigger count of the timer''<br/><!--GIDEROSMTD:Timer:getCurrentCount() returns the current trigger count of the timer--> | ||
Line 45: | Line 45: | ||
[[Timer:getRepeatCount]] ''returns the number of repetitions the timer will make''<br/><!--GIDEROSMTD:Timer:getRepeatCount() returns the number of repetitions the timer will make--> | [[Timer:getRepeatCount]] ''returns the number of repetitions the timer will make''<br/><!--GIDEROSMTD:Timer:getRepeatCount() returns the number of repetitions the timer will make--> | ||
[[Timer:isRunning]] ''returns the current running status of timer''<br/><!--GIDEROSMTD:Timer:isRunning() returns the current running status of timer--> | [[Timer:isRunning]] ''returns the current running status of timer''<br/><!--GIDEROSMTD:Timer:isRunning() returns the current running status of timer--> | ||
+ | [[Timer:pause]] ''pauses timer''<br/><!--GIDEROSMTD:Timer:pause() pauses timer--> | ||
[[Timer:reset]] ''stops the timer and sets the currentCount property to 0''<br/><!--GIDEROSMTD:Timer:reset() stops the timer and sets the currentCount property to 0--> | [[Timer:reset]] ''stops the timer and sets the currentCount property to 0''<br/><!--GIDEROSMTD:Timer:reset() stops the timer and sets the currentCount property to 0--> | ||
[[Timer:setDelay]] ''sets the time interval between timer events in milliseconds''<br/><!--GIDEROSMTD:Timer:setDelay(delay) sets the time interval between timer events in milliseconds--> | [[Timer:setDelay]] ''sets the time interval between timer events in milliseconds''<br/><!--GIDEROSMTD:Timer:setDelay(delay) sets the time interval between timer events in milliseconds--> |
Revision as of 16:56, 15 September 2021
Supported platforms:
Available since: Gideros 2011.6
Inherits from: Object
Description
The Timer class is used to execute a code at specified intervals.
The listener functions are registered through Event.TIMER and Event.TIMER_COMPLETE events.
Example
Rotates a pixel 360°
-- let's define a pixel and add it to the stage
local mypixel = Pixel.new(0xff0000, 1, 64, 64)
mypixel:setPosition(64, 64)
stage:addChild(mypixel)
function onTimer(event)
-- add 1 degree each time the function is called
mypixel:setRotation(mypixel:getRotation() + 1)
end
-- create our timer and add an event listener
-- 24 = delay in milliseconds
-- (optional) 360 = number of repetitions (here the result is 360 degrees)
local timer = Timer.new(24, 360)
-- local timer = Timer.new(24) -- to run indefinitely
timer:addEventListener(Event.TIMER, onTimer, timer)
timer:start()
MethodsTimer.delayedCall delay calls a function after a set amount of time Timer:getCurrentCount returns the current trigger count of the timer |
EventsEvent.TIMER Constants |