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

@ src/core/Runner.js:48

Matter.Runner.run

(engine)

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

Parameters

@ src/core/Runner.js:78

Matter.Runner.start

(runner, engine)

Alias for Runner.run.

Parameters

@ src/core/Runner.js:208

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

@ src/core/Runner.js:198

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. Triggers beforeTick, tick and afterTick events on the engine. Consider just Engine.update(engine, delta) if you're using your own loop.

Parameters

@ src/core/Runner.js:101

Item Index

Methods

Properties

The following properties are specified for objects created by <span class="prefix">Matter.</span>.create and for objects passed to it via the options argument.

Events

Properties

The following properties are specified for objects created by Matter.Runner.create and for objects passed to it via the options argument.

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

@ src/core/Runner.js:320

Runner.enabled

Boolean

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

Default: true

@ src/core/Runner.js:302

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

@ src/core/Runner.js:310

Events

The following events are emitted by objects created by <span class="prefix">Matter.</span>Runner.create to objects that have subscribed using Matter.Events.on.

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

deprecated

Fired after rendering

Event Payload:

An event object

The engine.timing.timestamp of the event

  • source

The source object of the event

  • name

The name of the event

@ src/core/Runner.js:285

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

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

Event Payload:

An event object

The engine.timing.timestamp of the event

  • source

The source object of the event

  • name

The name of the event

@ src/core/Runner.js:244

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

Fired after update

Event Payload:

An event object

The engine.timing.timestamp of the event

  • source

The source object of the event

  • name

The name of the event

@ src/core/Runner.js:264

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

deprecated

Fired before rendering

Event Payload:

An event object

The engine.timing.timestamp of the event

  • source

The source object of the event

  • name

The name of the event

@ src/core/Runner.js:274

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

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

Event Payload:

An event object

The engine.timing.timestamp of the event

  • source

The source object of the event

  • name

The name of the event

@ src/core/Runner.js:224

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

Fired before update

Event Payload:

An event object

The engine.timing.timestamp of the event

  • source

The source object of the event

  • name

The name of the event

@ src/core/Runner.js:254

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

Fired after engine timing updated, but just before update

Event Payload:

An event object

The engine.timing.timestamp of the event

  • source

The source object of the event

  • name

The name of the event

@ src/core/Runner.js:234