API Docs for: 1.4.0
Show:

Kiwi.Time.Timer Class

Defined in: src\time\Timer.ts:10
Module: Time
Parent Module: Kiwi

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]
)
Kiwi.Time.Timer

Parameters:

  • name String

    The name of the timer.

  • clock Kiwi.Time.Clock

    The game clock instance this Timer is based on.

  • delay Number

    The number of clock units to wait between firing events.

  • [repeatCount=0] Number optional

    The 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:

Kiwi.Time.Timer:

This object.

Methods

addTimerEvent

(
  • A
)
Kiwi.Time.TimerEvent public

Adds an existing TimerEvent object to this Timer.

Parameters:

Returns:

Kiwi.Time.TimerEvent:

The TimerEvent object

clear

(
  • type
)
Boolean public

Removes all TimerEvent objects from this Timer

Parameters:

  • type Number

    The type of TimerEvents to remove. Set to zero to remove them all.

Returns:

Boolean:

True if the event was removed, otherwise false.

createTimerEvent

(
  • type
  • callback
  • context
)
Kiwi.Time.TimerEvent public

Creates a new TimerEvent and adds it to this Timer

Parameters:

  • type Number

    The type of TimerEvent to create (TIMER_START, TIMER_COUNT or TIMER_STOP).

  • callback Function

    The function to call when the TimerEvent fires.

  • context Function

    The context in which the given function will run (usually 'this')

Returns:

Kiwi.Time.TimerEvent:

The newly created TimerEvent.

getCurrentCount

() Number public

Get the number of times the timer has repeated.

Returns:

Number:

objType

() String public

The type of object that this is.

Returns:

String:

"Timer"

pause

() Kiwi.Time.Timer public

Pause the Timer. Only possible when the timer is running.

Returns:

Kiwi.Time.Timer:

this object.

paused

() Boolean public

Whether the timer is in a paused state.

Returns:

Boolean:

processEvents

(
  • type
)
private

Checks the list of TimerEvents added and processes them based on their type.

Parameters:

  • type Number

    The type of events to dispatch

removeTimerEvent

(
  • The
)
Boolean public

Removes a TimerEvent object from this Timer

Parameters:

Returns:

Boolean:

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:

Kiwi.Time.Timer:

this object.

running

() Boolean public

The Timers current state. True if the Timer is running, otherwise false.

Returns:

Boolean:

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:

Kiwi.Time.Timer:

this object.

stop

() Kiwi.Time.Timer public

Stop the Timer. Only possible when the timer is running or paused.

Returns:

Kiwi.Time.Timer:

this object.

stopped

() Boolean public

Whether the timer is in a stopped state.

Returns:

Boolean:

toString

() String public

Returns a string representation of this object.

Returns:

String:

a string representation of the instance.

update

() public

Internal update loop called by the Clock that this Timer belongs to.

Properties

_clock

Kiwi.Time.Clock private

The clock which this timer bases its timing on.

_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

Defined in src\time\Timer.ts:225

Available since 1.2.0

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

Defined in src\time\Timer.ts:234

Available since 1.2.0

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

Defined in src\time\Timer.ts:104

Deprecated: Better time handling in 1.2.0 deprecates this data.

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