Difference between revisions of "Timer"

From GiderosMobile
(added example)
Line 69: Line 69:
 
=== <translate>Constants</translate> ===
 
=== <translate>Constants</translate> ===
 
|}
 
|}
 +
 +
{{Timer}}

Revision as of 02:29, 4 December 2019



Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.pngPlatform html5.pngPlatform winrt.pngPlatform win32.png

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()


Methods

Timer.delayedCall delayed call a function after a set amount of time
Timer.new creates a new Timer object
Timer.pauseAll pause all timers
Timer.resumeAll resume all timers
Timer.stopAll stop all timers
Timer:getCurrentCount returns the current trigger count of the timer
Timer:getDelay returns the time interval between timer events in milliseconds
Timer:getRepeatCount returns the number of repetitions the timer will make
Timer:isRunning returns the current running status of timer
Timer:reset stops the timer and sets the currentCount property to 0
Timer:setDelay sets the time interval between timer events in milliseconds
Timer:setRepeatCount sets the number of repetitions the timer will make
Timer:start starts the timer
Timer:stop stops the timer

Events

Event.TIMER
Event.TIMER_COMPLETE

Constants