Difference between revisions of "Timer"
m (separated class methods from functions methods) |
|||
Line 36: | Line 36: | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
=== <translate>Methods</translate> === | === <translate>Methods</translate> === | ||
− | [[Special:MyLanguage/Timer.delayedCall|Timer.delayedCall]] ''<translate>delayed call a function after a set amount of time</translate>''<br/><!-- GIDEROSMTD:Timer.delayedCall(delay,func,data) delayed call a function after a set amount of time --> | + | [[Special:MyLanguage/Timer.delayedCall|Timer.delayedCall]] ''<translate>delayed call a function after a set amount of time</translate>''<br/> |
− | [[Special:MyLanguage/Timer.new|Timer.new]] ''<translate>creates a new Timer object</translate>''<br/><!-- GIDEROSMTD:Timer.new(delay,repeatCount) creates a new Timer object --> | + | <!-- GIDEROSMTD:Timer.delayedCall(delay,func,data) delayed call a function after a set amount of time --> |
− | [[Special:MyLanguage/Timer.pauseAll|Timer.pauseAll]] ''<translate>pause all timers</translate>''<br/><!-- GIDEROSMTD:Timer.pauseAll() pause all timers --> | + | [[Special:MyLanguage/Timer.new|Timer.new]] ''<translate>creates a new Timer object</translate>''<br/> |
− | [[Special:MyLanguage/Timer.resumeAll|Timer.resumeAll]] ''<translate>resume all timers</translate>''<br/><!-- GIDEROSMTD:Timer.resumeAll() resume all timers --> | + | <!-- GIDEROSMTD:Timer.new(delay,repeatCount) creates a new Timer object --> |
− | [[Special:MyLanguage/Timer.stopAll|Timer.stopAll]] ''<translate>stop all timers</translate>''<br/><!-- GIDEROSMTD:Timer.stopAll() stop all timers --> | + | [[Special:MyLanguage/Timer.pauseAll|Timer.pauseAll]] ''<translate>pause all timers</translate>''<br/> |
− | [[Special:MyLanguage/Timer:getCurrentCount|Timer:getCurrentCount]] ''<translate>returns the current trigger count of the timer</translate>''<br/><!-- GIDEROSMTD:Timer:getCurrentCount() returns the current trigger count of the timer --> | + | <!-- GIDEROSMTD:Timer.pauseAll() pause all timers --> |
− | [[Special:MyLanguage/Timer:getDelay|Timer:getDelay]] ''<translate>returns the time interval between timer events in milliseconds</translate>''<br/><!-- GIDEROSMTD:Timer:getDelay() returns the time interval between timer events in milliseconds --> | + | [[Special:MyLanguage/Timer.resumeAll|Timer.resumeAll]] ''<translate>resume all timers</translate>''<br/> |
− | [[Special:MyLanguage/Timer:getRepeatCount|Timer:getRepeatCount]] ''<translate>returns the number of repetitions the timer will make</translate>''<br/><!-- GIDEROSMTD:Timer:getRepeatCount() returns the number of repetitions the timer will make --> | + | <!-- GIDEROSMTD:Timer.resumeAll() resume all timers --> |
− | [[Special:MyLanguage/Timer:isRunning|Timer:isRunning]] ''<translate>returns the current running status of timer</translate>''<br/><!-- GIDEROSMTD:Timer:isRunning() returns the current running status of timer --> | + | [[Special:MyLanguage/Timer.stopAll|Timer.stopAll]] ''<translate>stop all timers</translate>''<br/> |
− | [[Special:MyLanguage/Timer:reset|Timer:reset]] ''<translate>stops the timer and sets the currentCount property to 0</translate>''<br/><!-- GIDEROSMTD:Timer:reset() stops the timer and sets the currentCount property to 0 --> | + | <!-- GIDEROSMTD:Timer.stopAll() stop all timers --> |
− | [[Special:MyLanguage/Timer:setDelay|Timer:setDelay]] ''<translate>sets the time interval between timer events in milliseconds</translate>''<br/><!-- GIDEROSMTD:Timer:setDelay(delay) sets the time interval between timer events in milliseconds --> | + | |
− | [[Special:MyLanguage/Timer:setRepeatCount|Timer:setRepeatCount]] ''<translate>sets the number of repetitions the timer will make</translate>''<br/><!-- GIDEROSMTD:Timer:setRepeatCount(repeatCount) sets the number of repetitions the timer will make --> | + | [[Special:MyLanguage/Timer:getCurrentCount|Timer:getCurrentCount]] ''<translate>returns the current trigger count of the timer</translate>''<br/> |
− | [[Special:MyLanguage/Timer:start|Timer:start]] ''<translate>starts the timer</translate>''<br/><!-- GIDEROSMTD:Timer:start() starts the timer --> | + | <!-- GIDEROSMTD:Timer:getCurrentCount() returns the current trigger count of the timer --> |
− | [[Special:MyLanguage/Timer:stop|Timer:stop]] ''<translate>stops the timer</translate>''<br/><!-- GIDEROSMTD:Timer:stop() stops the timer --> | + | [[Special:MyLanguage/Timer:getDelay|Timer:getDelay]] ''<translate>returns the time interval between timer events in milliseconds</translate>''<br/> |
+ | <!-- GIDEROSMTD:Timer:getDelay() returns the time interval between timer events in milliseconds --> | ||
+ | [[Special:MyLanguage/Timer:getRepeatCount|Timer:getRepeatCount]] ''<translate>returns the number of repetitions the timer will make</translate>''<br/> | ||
+ | <!-- GIDEROSMTD:Timer:getRepeatCount() returns the number of repetitions the timer will make --> | ||
+ | [[Special:MyLanguage/Timer:isRunning|Timer:isRunning]] ''<translate>returns the current running status of timer</translate>''<br/> | ||
+ | <!-- GIDEROSMTD:Timer:isRunning() returns the current running status of timer --> | ||
+ | [[Special:MyLanguage/Timer:reset|Timer:reset]] ''<translate>stops the timer and sets the currentCount property to 0</translate>''<br/> | ||
+ | <!-- GIDEROSMTD:Timer:reset() stops the timer and sets the currentCount property to 0 --> | ||
+ | [[Special:MyLanguage/Timer:setDelay|Timer:setDelay]] ''<translate>sets the time interval between timer events in milliseconds</translate>''<br/> | ||
+ | <!-- GIDEROSMTD:Timer:setDelay(delay) sets the time interval between timer events in milliseconds --> | ||
+ | [[Special:MyLanguage/Timer:setRepeatCount|Timer:setRepeatCount]] ''<translate>sets the number of repetitions the timer will make</translate>''<br/> | ||
+ | <!-- GIDEROSMTD:Timer:setRepeatCount(repeatCount) sets the number of repetitions the timer will make --> | ||
+ | [[Special:MyLanguage/Timer:start|Timer:start]] ''<translate>starts the timer</translate>''<br/> | ||
+ | <!-- GIDEROSMTD:Timer:start() starts the timer --> | ||
+ | [[Special:MyLanguage/Timer:stop|Timer:stop]] ''<translate>stops the timer</translate>''<br/> | ||
+ | <!-- GIDEROSMTD:Timer:stop() stops the timer --> | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
=== <translate>Events</translate> === | === <translate>Events</translate> === | ||
− | [[Special:MyLanguage/Event.TIMER|Event.TIMER]]<br/><!-- GIDEROSEVT:Event.TIMER timer--> | + | [[Special:MyLanguage/Event.TIMER|Event.TIMER]]<br/> |
− | [[Special:MyLanguage/Event.TIMER_COMPLETE|Event.TIMER_COMPLETE]]<br/><!-- GIDEROSEVT:Event.TIMER_COMPLETE timerComplete--> | + | <!-- GIDEROSEVT:Event.TIMER timer --> |
+ | [[Special:MyLanguage/Event.TIMER_COMPLETE|Event.TIMER_COMPLETE]]<br/> | ||
+ | <!-- GIDEROSEVT:Event.TIMER_COMPLETE timerComplete --> | ||
=== <translate>Constants</translate> === | === <translate>Constants</translate> === | ||
|} | |} |
Revision as of 08:32, 5 January 2020
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
-- TIMER
-- 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 |