Difference between revisions of "Timer"

From GiderosMobile
m (separated class methods from functions methods)
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<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/>
+
'''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/>
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''Available since:''' Gideros 2011.6<br/>
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Object|Object]]<br/>
+
'''Inherits from:''' [[Object]]<br/>
  
=== <translate>Description</translate> ===
+
=== Description ===
The [[Special:MyLanguage/Timer|Timer]] class is used to execute a code at specified intervals.
+
The '''Timer''' class is used to execute a code at specified intervals.
  
The listener functions are registered through [[Special:MyLanguage/Event.TIMER|Event.TIMER]] and [[Special:MyLanguage/Event.TIMER_COMPLETE|Event.TIMER_COMPLETE]] events.
+
The listener functions are registered through [[Event.TIMER]] and [[Event.TIMER_COMPLETE]] events.
  
=== <translate>Example</translate> ===
+
=== Example ===
<source lang="lua">
+
'''Rotates a pixel 360°'''
-- TIMER
+
<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)
Line 31: Line 30:
 
timer:addEventListener(Event.TIMER, onTimer, timer)
 
timer:addEventListener(Event.TIMER, onTimer, timer)
 
timer:start()
 
timer:start()
</source>
+
</syntaxhighlight>
  
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== <translate>Methods</translate> ===
+
=== Methods ===
[[Special:MyLanguage/Timer.delayedCall|Timer.delayedCall]] ''<translate>delayed call a function after a set amount of time</translate>''<br/>
+
[[Timer.delayedCall]] ''delay calls a function after a set amount of time''<br/><!--GIDEROSMTD:Timer.delayedCall(delay,func,data) delay calls 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-->
[[Special:MyLanguage/Timer.new|Timer.new]] ''<translate>creates a new Timer object</translate>''<br/>
+
[[Timer.pauseAll]] ''pauses all timers''<br/><!--GIDEROSMTD:Timer.pauseAll() pauses all timers-->
<!-- GIDEROSMTD:Timer.new(delay,repeatCount) creates a new Timer object -->
+
[[Timer.resumeAll]] ''resumes all timers''<br/><!--GIDEROSMTD:Timer.resumeAll() resumes all timers-->
[[Special:MyLanguage/Timer.pauseAll|Timer.pauseAll]] ''<translate>pause all timers</translate>''<br/>
+
[[Timer.stopAll]] ''stops all timers''<br/><!--GIDEROSMTD:Timer.stopAll() stops all timers-->
<!-- GIDEROSMTD:Timer.pauseAll() pause all timers -->
 
[[Special:MyLanguage/Timer.resumeAll|Timer.resumeAll]] ''<translate>resume all timers</translate>''<br/>
 
<!-- GIDEROSMTD:Timer.resumeAll() resume all timers -->
 
[[Special:MyLanguage/Timer.stopAll|Timer.stopAll]] ''<translate>stop all timers</translate>''<br/>
 
<!-- GIDEROSMTD:Timer.stopAll() stop all timers -->
 
  
[[Special:MyLanguage/Timer:getCurrentCount|Timer:getCurrentCount]] ''<translate>returns the current trigger count of the timer</translate>''<br/>
+
[[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-->
[[Special:MyLanguage/Timer:getDelay|Timer:getDelay]] ''<translate>returns the time interval between timer events in milliseconds</translate>''<br/>
+
[[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-->
[[Special:MyLanguage/Timer:getRepeatCount|Timer:getRepeatCount]] ''<translate>returns the number of repetitions the timer will make</translate>''<br/>
+
[[Timer:pause]] ''pauses timer''<br/><!--GIDEROSMTD:Timer:pause() pauses timer-->
<!-- GIDEROSMTD:Timer:getRepeatCount() returns the number of repetitions the timer will make -->
+
[[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-->
[[Special:MyLanguage/Timer:isRunning|Timer:isRunning]] ''<translate>returns the current running status of timer</translate>''<br/>
+
[[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-->
<!-- GIDEROSMTD:Timer:isRunning() returns the current running status of timer -->
+
[[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-->
[[Special:MyLanguage/Timer:reset|Timer:reset]] ''<translate>stops the timer and sets the currentCount property to 0</translate>''<br/>
+
[[Timer:start]] ''starts the timer''<br/><!--GIDEROSMTD:Timer:start() starts the timer-->
<!-- GIDEROSMTD:Timer:reset() stops the timer and sets the currentCount property to 0 -->
+
[[Timer:stop]] ''stops the timer''<br/><!--GIDEROSMTD:Timer:stop() stops the timer-->
[[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> ===
+
=== Events ===
[[Special:MyLanguage/Event.TIMER|Event.TIMER]]<br/>
+
[[Event.TIMER]]<br/><!--GIDEROSEVT:Event.TIMER timer-->
<!-- GIDEROSEVT:Event.TIMER timer -->
+
[[Event.TIMER_COMPLETE]]<br/><!--GIDEROSEVT:Event.TIMER_COMPLETE timerComplete-->
[[Special:MyLanguage/Event.TIMER_COMPLETE|Event.TIMER_COMPLETE]]<br/>
+
=== Constants ===
<!-- GIDEROSEVT:Event.TIMER_COMPLETE timerComplete -->
 
=== <translate>Constants</translate> ===
 
 
|}
 
|}
 +
 +
{{GIDEROS IMPORTANT LINKS}}

Latest revision as of 14:33, 13 July 2023

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

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

Methods

Timer.delayedCall delay calls a function after a set amount of time
Timer.new creates a new Timer object
Timer.pauseAll pauses all timers
Timer.resumeAll resumes all timers
Timer.stopAll stops 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:pause pauses 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