Difference between revisions of "Timer"
(added example) |
|||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
+ | |||
<languages /> | <languages /> | ||
+ | |||
<!-- GIDEROSOBJ:Timer --> | <!-- GIDEROSOBJ:Timer --> | ||
− | '''<translate>Supported platforms</translate>:''' [[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/> | + | |
− | '''<translate>Available since</translate>:''' Gideros 2011.6<br/> | + | '''<translate>Supported platforms</translate>:''' [[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]] |
− | '''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Object|Object]]<br/> | + | <br/> |
+ | |||
+ | '''<translate>Available since</translate>:''' Gideros 2011.6 | ||
+ | <br/> | ||
+ | |||
+ | '''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Object|Object]] | ||
+ | <br/> | ||
+ | |||
=== <translate>Description</translate> === | === <translate>Description</translate> === | ||
− | <translate | + | <translate> |
− | The [[Special:MyLanguage/Timer|Timer]] class is used to execute a code at specified intervals. The listener functions are registered | + | The [[Special:MyLanguage/Timer|Timer]] class is used to execute a code at specified intervals. |
− | through [[Special:MyLanguage/Event.TIMER|Event.TIMER]] and [[Special:MyLanguage/Event.TIMER_COMPLETE|Event.TIMER_COMPLETE]] events.<br /></translate> | + | <br/> |
+ | |||
+ | The listener functions are registered through [[Special:MyLanguage/Event.TIMER|Event.TIMER]] and [[Special:MyLanguage/Event.TIMER_COMPLETE|Event.TIMER_COMPLETE]] events. | ||
+ | <br/> | ||
+ | </translate> | ||
+ | |||
+ | === <translate>Example</translate> === | ||
+ | <source lang="lua"> | ||
+ | -- 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() | ||
+ | </source> | ||
+ | <br/> | ||
+ | |||
{|- | {|- | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| |
Revision as of 22:47, 27 July 2019
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 |
EventsEvent.TIMER Constants |