Kiwi.Time.Timer Class
The Timer class hooks into a game Clock and allows you run code at a specified point in game time. Use the start() method to start a timer. Add TimerEvents to set-up code to be run on the timer interval. Timer objects can run once or repeat at specified intervals to execute code on a schedule.
Constructor
Kiwi.Time.Timer
-
name
-
clock
-
delay
-
[repeatCount=0]
Parameters:
-
name
StringThe name of the timer.
-
clock
Kiwi.Time.ClockThe game clock instance this Timer is based on.
-
delay
NumberThe number of clock units to wait between firing events.
-
[repeatCount=0]
Number optionalThe number of times to repeat the timer before it is expired. If you don't want it to ever expire, set a value of -1.
Returns:
This object.
Item Index
Methods
Properties
Methods
addTimerEvent
-
A
Adds an existing TimerEvent object to this Timer.
Parameters:
-
A
Kiwi.Time.TimerEventTimerEvent object
Returns:
The TimerEvent object
clear
-
type
Removes all TimerEvent objects from this Timer
Parameters:
-
type
NumberThe type of TimerEvents to remove. Set to zero to remove them all.
Returns:
True if the event was removed, otherwise false.
createTimerEvent
-
type
-
callback
-
context
Creates a new TimerEvent and adds it to this Timer
Parameters:
-
type
NumberThe type of TimerEvent to create (TIMER_START, TIMER_COUNT or TIMER_STOP).
-
callback
FunctionThe function to call when the TimerEvent fires.
-
context
FunctionThe context in which the given function will run (usually 'this')
Returns:
The newly created TimerEvent.
getCurrentCount
()
Number
public
Get the number of times the timer has repeated.
Returns:
objType
()
String
public
The type of object that this is.
Returns:
"Timer"
pause
()
Kiwi.Time.Timer
public
Pause the Timer. Only possible when the timer is running.
Returns:
this object.
paused
()
Boolean
public
Whether the timer is in a paused state.
Returns:
processEvents
-
type
Checks the list of TimerEvents added and processes them based on their type.
Parameters:
-
type
NumberThe type of events to dispatch
removeTimerEvent
-
The
Removes a TimerEvent object from this Timer
Parameters:
-
The
Kiwi.Time.TimerEventTimerEvent to remove
Returns:
True if the event was removed, otherwise false.
resume
()
Kiwi.Time.Timer
public
Resume the Timer. Only possible if the timer has been paused.
Returns:
this object.
running
()
Boolean
public
The Timers current state. True if the Timer is running, otherwise false.
Returns:
start
()
Kiwi.Time.Timer
public
Start the Timer. This will reset the timer and start it. The timer can only be started if it is in a stopped state.
Returns:
this object.
stop
()
Kiwi.Time.Timer
public
Stop the Timer. Only possible when the timer is running or paused.
Returns:
this object.
stopped
()
Boolean
public
Whether the timer is in a stopped state.
Returns:
toString
()
String
public
Returns a string representation of this object.
Returns:
a string representation of the instance.
update
()
public
Internal update loop called by the Clock that this Timer belongs to.
Properties
_countEvents
Array
private
A collection of the TimerEvents associated with TimerEvent.TIMER_COUNT
_currentCount
Number
private
The number of times the timer has repeated so far.
Default: 0
_delay
Number
private
The delay, in game clock units, that the timer will wait before firing the event
Default: 0.016
_elapsed
Number
private
Time elapsed on the current repetition
_isPaused
Boolean
private
Whether the timer is in a paused state.
Default: false
_isRunning
Boolean
private
Whether the timer is in a running state.
Default: false
_isStopped
Boolean
private
Whether the timer is in a stopped state.
Default: true
_lastElapsed
Number
private
Clock time on last frame, used to calculate frame length and time elapsed
_startEvents
Array
private
A collection of the TimerEvents associated with TimerEvent.TIMER_START
_stopEvents
Array
private
A collection of the TimerEvents associated with TimerEvent.TIMER_STOP
_timeLastCount
Number
deprecated
private
The time the last repeat occurred in clock units.
delay
Number
public
The delay, in game clock units, that the timer will wait before firing the event
This property must be greater than 0.
Default: 0.016
name
String
public
The name of the timer.
Default: null
repeatCount
Number
public
The number of times the timer will repeat before stopping.
Default: 0