Skip to main content

Timer

The Excalibur timer hooks into the internal timer and fires callbacks, after a certain interval, optionally repeating.

Index

Constructors

constructor

  • Parameters

    • options: TimerOptions

      Options - repeats, numberOfRepeats, fcn, interval

    Returns Timer

Properties

publicid

id: number = 0

publicinterval

interval: number = 10

publicmaxNumberOfRepeats

maxNumberOfRepeats: number = -1

publicrandom

random: Random

publicrandomRange

randomRange: [number, number] = ...

publicrepeats

repeats: boolean = false

publicscene

scene: Scene<unknown> = null

Accessors

publiccomplete

  • get complete(): boolean
  • Returns boolean

publicisRunning

  • get isRunning(): boolean
  • Returns boolean

publictimeElapsedTowardNextAction

  • get timeElapsedTowardNextAction(): number

  • Returns number

    milliseconds elapsed toward the next action

publictimeToNextAction

  • get timeToNextAction(): number

  • Returns number

    milliseconds until the next action callback, if complete will return 0

publictimesRepeated

  • get timesRepeated(): number
  • Returns number

Methods

publiccancel

  • cancel(): void
  • Cancels the timer, preventing any further executions.


    Returns void

publicgetTimeRunning

  • getTimeRunning(): number
  • Returns number

publicoff

  • off(fcn: () => void): void
  • Removes a callback from the callback list to be fired after the interval is complete.


    Parameters

    • fcn: () => void

      The callback to be removed from the callback list, to be fired after the interval is complete.

    Returns void

publicon

  • on(fcn: () => void): void
  • Adds a new callback to be fired after the interval is complete


    Parameters

    • fcn: () => void

      The callback to be added to the callback list, to be fired after the interval is complete.

    Returns void

publicpause

  • Pauses the timer, time will no longer increment towards the next call


    Returns Timer

publicreset

  • reset(newInterval?: number, newNumberOfRepeats?: number): void
  • Resets the timer so that it can be reused, and optionally reconfigure the timers interval.

    Warning** you may need to call timer.start() again if the timer had completed


    Parameters

    • optionalnewInterval: number

      If specified, sets a new non-negative interval in milliseconds to refire the callback

    • optionalnewNumberOfRepeats: number

      If specified, sets a new non-negative upper limit to the number of time this timer executes

    Returns void

publicresume

  • Resumes the timer, time will now increment towards the next call.


    Returns Timer

publicstart

  • Starts the timer, if the timer was complete it will restart the timer and reset the elapsed time counter


    Returns Timer

publicstop

  • Stops the timer and resets the elapsed time counter towards the next action invocation


    Returns Timer

publicupdate

  • update(delta: number): void
  • Updates the timer after a certain number of milliseconds have elapsed. This is used internally by the engine.


    Parameters

    • delta: number

      Number of elapsed milliseconds since the last update.

    Returns void