Options
All
  • Public
  • Public/Protected
  • All
Menu

Countdown timer that calls a function on each tick, and optionally on completion.

Example

// Moving a sprite into position on a game scene over 2 seconds,
// with a half-second delay before starting.
const timer = new Timer((r: number) =>
(sprite.pos.y = elasticOut(r) * game.height - game.height / 1.6),
() => {}, 2, .5
)

Hierarchy

  • Timer

Index

Constructors

Properties

Methods

Constructors

constructor

  • new Timer(onTick: TickFunc, onDone?: Function, duration?: number, delay?: number): Timer
  • Initialize Timer object.

    Parameters

    • onTick: TickFunc

      Function called every tick (core loop update).

    • Optional onDone: Function

      Function called on timer completion.

    • Default value duration: number = 1

      Time in seconds for the timer to run.

    • Default value delay: number = 0

      Time in seconds to wait before starting timer.

    Returns Timer

Properties

dead

dead: boolean

Used by core loop to remove the object when dead.

visible

visible: boolean

Used by core loop to skip rendering. False, unless changed by user.

Methods

update

  • update(dt: number): void
  • Called by core loop each tick.

    Updates internal state and calls onTick or onDone functions as needed.

    Parameters

    • dt: number

      Delta time since last update.

    Returns void