Difference between revisions of "Timer"
(added Timer:pause()) |
m (Text replacement - "<source" to "<syntaxhighlight") |
||
Line 12: | Line 12: | ||
=== Example === | === Example === | ||
'''Rotates a pixel 360°''' | '''Rotates a pixel 360°''' | ||
− | < | + | <syntaxhighlight 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) |
Revision as of 14:31, 13 July 2023
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° <syntaxhighlight lang="lua"> -- 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>
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 |