Difference between revisions of "Timer"
(remove language stuff) |
|||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
− | |||
<!-- GIDEROSOBJ:Timer --> | <!-- GIDEROSOBJ:Timer --> | ||
− | ''' | + | '''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/> |
− | ''' | + | '''Available since:''' Gideros 2011.6<br/> |
− | ''' | + | '''Inherits from:''' [[Object]]<br/> |
− | === | + | === Description === |
− | The | + | The '''Timer''' class is used to execute a code at specified intervals. |
− | The listener functions are registered through [[ | + | The listener functions are registered through [[Event.TIMER]] and [[Event.TIMER_COMPLETE]] events. |
− | === | + | === Example === |
+ | '''Rotates a pixel 360°''' | ||
<source lang="lua"> | <source lang="lua"> | ||
− | |||
-- let's define a pixel and add it to the stage | -- let's define a pixel and add it to the stage | ||
local mypixel = Pixel.new(0xff0000, 1, 64, 64) | local mypixel = Pixel.new(0xff0000, 1, 64, 64) | ||
Line 35: | Line 34: | ||
{|- | {|- | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
− | === | + | === Methods === |
− | [[ | + | [[Timer.delayedCall]] ''delayed call a function after a set amount of time''<br/><!--GIDEROSMTD:Timer.delayedCall(delay,func,data) delayed call a function after a set amount of time--> |
− | <!-- GIDEROSMTD:Timer.delayedCall(delay,func,data) delayed call 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.pauseAll]] ''pause all timers''<br/><!--GIDEROSMTD:Timer.pauseAll() pause all timers--> |
− | <!-- GIDEROSMTD:Timer.new(delay,repeatCount) creates a new Timer object --> | + | [[Timer.resumeAll]] ''resume all timers''<br/><!--GIDEROSMTD:Timer.resumeAll() resume all timers--> |
− | [[ | + | [[Timer.stopAll]] ''stop all timers''<br/><!--GIDEROSMTD:Timer.stopAll() stop all timers--> |
− | <!-- GIDEROSMTD:Timer.pauseAll() pause all timers --> | ||
− | [[ | ||
− | <!-- GIDEROSMTD:Timer.resumeAll() resume all timers --> | ||
− | [[ | ||
− | <!-- GIDEROSMTD:Timer.stopAll() stop all timers --> | ||
− | [[ | + | [[Timer:getCurrentCount]] ''returns the current trigger count of the timer''<br/><!--GIDEROSMTD:Timer:getCurrentCount() returns the current trigger count of the timer--> |
− | <!-- GIDEROSMTD:Timer:getCurrentCount() returns the current trigger count of the timer --> | + | [[Timer:getDelay]] ''returns the time interval between timer events in milliseconds''<br/><!--GIDEROSMTD:Timer:getDelay() returns the time interval between timer events in milliseconds--> |
− | [[ | + | [[Timer:getRepeatCount]] ''returns the number of repetitions the timer will make''<br/><!--GIDEROSMTD:Timer:getRepeatCount() returns the number of repetitions the timer will make--> |
− | <!-- GIDEROSMTD:Timer:getDelay() returns the time interval between timer events in milliseconds --> | + | [[Timer:isRunning]] ''returns the current running status of timer''<br/><!--GIDEROSMTD:Timer:isRunning() returns the current running status of 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--> |
− | <!-- GIDEROSMTD:Timer:getRepeatCount() returns the number of repetitions the timer will make --> | + | [[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:setRepeatCount]] ''sets the number of repetitions the timer will make''<br/><!--GIDEROSMTD:Timer:setRepeatCount(repeatCount) sets the number of repetitions the timer will make--> |
− | <!-- GIDEROSMTD:Timer:isRunning() returns the current running status of timer --> | + | [[Timer:start]] ''starts the timer''<br/><!--GIDEROSMTD:Timer:start() starts the timer--> |
− | [[ | + | [[Timer:stop]] ''stops the timer''<br/><!--GIDEROSMTD:Timer:stop() stops the timer--> |
− | <!-- GIDEROSMTD:Timer:reset() stops the timer and sets the currentCount property to 0 --> | ||
− | [[ | ||
− | <!-- GIDEROSMTD:Timer:setDelay(delay) sets the time interval between timer events in milliseconds --> | ||
− | [[ | ||
− | <!-- GIDEROSMTD:Timer:setRepeatCount(repeatCount) sets the number of repetitions the timer will make --> | ||
− | [[ | ||
− | <!-- GIDEROSMTD:Timer:start() starts the timer --> | ||
− | [[ | ||
− | <!-- GIDEROSMTD:Timer:stop() stops the timer --> | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
− | === | + | === Events === |
− | [[ | + | [[Event.TIMER]]<br/><!--GIDEROSEVT:Event.TIMER timer--> |
− | <!-- GIDEROSEVT:Event.TIMER timer --> | + | [[Event.TIMER_COMPLETE]]<br/><!--GIDEROSEVT:Event.TIMER_COMPLETE timerComplete--> |
− | [[ | + | === Constants === |
− | <!-- GIDEROSEVT:Event.TIMER_COMPLETE timerComplete --> | ||
− | === | ||
|} | |} | ||
{{GIDEROS IMPORTANT LINKS}} | {{GIDEROS IMPORTANT LINKS}} |
Revision as of 22:05, 1 January 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 delayed call a function after a set amount of time Timer:getCurrentCount returns the current trigger count of the timer |
EventsEvent.TIMER Constants |