Show:
API

Matter.Runner

Defined in: src/core/Runner.js:1

The Matter.Runner module is an optional utility which provides a game loop, that handles continuously updating a Matter.Engine for you within a browser. It is intended for development and debugging purposes, but may also be suitable for simple games. If you are using your own game loop instead, then you do not need the Matter.Runner module. Instead just call Engine.update(engine, delta) in your own loop.

See the included usage examples.

Methods

Matter.Runner.create

(options)

Creates a new Runner. The options parameter is an object that specifies any properties you wish to override the defaults.

Parameters

Matter.Runner.run

(engine)

Continuously ticks a Matter.Engine by calling Runner.tick on the requestAnimationFrame event.

Parameters

Matter.Runner.start

(runner, engine)

Alias for Runner.run.

Parameters

Matter.Runner.stop

(runner)

Ends execution of Runner.run on the given runner, by canceling the animation frame request event loop. If you wish to only temporarily pause the engine, see engine.enabled instead.

Parameters

Matter.Runner.tick

(runner, engine, time)

A game loop utility that updates the engine and renderer by one step (a 'tick'). Features delta smoothing, time correction and fixed or dynamic timing. Consider just Engine.update(engine, delta) if you're using your own loop.

Parameters

Properties / Options

The following properties if specified below are for objects created by Matter.Runner.create and may be passed to it as options.

Runner.delta

Number

A Number that specifies the time step between updates in milliseconds. If engine.timing.isFixed is set to true, then delta is fixed. If it is false, then delta can dynamically change to maintain the correct apparent simulation speed.

Default: 1000 / 60

Runner.enabled

Boolean

A flag that specifies whether the runner is running or not.

Default: true

Runner.isFixed

Boolean

A Boolean that specifies if the runner should use a fixed timestep (otherwise it is variable). If timing is fixed, then the apparent simulation speed will change depending on the frame rate (but behaviour will be deterministic). If the timing is variable, then the apparent simulation speed will be constant (approximately, but at the cost of determininism).

Default: false

Events

The following events are emitted by objects created by Matter.Runner.create and received by objects that have subscribed using Matter.Events.on.

Events.on(Runner, "afterTick", callback)

Fired at the end of a tick, after engine update and after rendering

Callback Parameters

  • event Object

    An event object

    • timestamp Number

      The engine.timing.timestamp of the event

    • source

      The source object of the event

    • name

      The name of the event

Events.on(Runner, "afterUpdate", callback)

Fired after update

Callback Parameters

  • event Object

    An event object

    • timestamp Number

      The engine.timing.timestamp of the event

    • source

      The source object of the event

    • name

      The name of the event

Events.on(Runner, "beforeTick", callback)

Fired at the start of a tick, before any updates to the engine or timing

Callback Parameters

  • event Object

    An event object

    • timestamp Number

      The engine.timing.timestamp of the event

    • source

      The source object of the event

    • name

      The name of the event

Events.on(Runner, "beforeUpdate", callback)

Fired before update

Callback Parameters

  • event Object

    An event object

    • timestamp Number

      The engine.timing.timestamp of the event

    • source

      The source object of the event

    • name

      The name of the event

Events.on(Runner, "tick", callback)

Fired after engine timing updated, but just before update

Callback Parameters

  • event Object

    An event object

    • timestamp Number

      The engine.timing.timestamp of the event

    • source

      The source object of the event

    • name

      The name of the event