- Matter.Runner
- Methods
- Item Index
- Properties
- Events
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
options
Object
Matter.Runner.run
(engine)
Continuously ticks a Matter.Engine
by calling Runner.tick
on the requestAnimationFrame
event.
Parameters
engine
Engine
Matter.Runner.start
(runner, engine)
Alias for Runner.run
.
Parameters
runner
Runner
engine
Engine
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
runner
Runner
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
runner
Runner
engine
Engine
time
Number
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
- afterRenderdeprecated
- afterTick
- afterUpdate
- beforeRenderdeprecated
- beforeTick
- beforeUpdate
- tick
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
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
A flag that specifies whether the runner is running or not.
Default: true
Runner.isFixed
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 <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:
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, "afterTick", callback)
Fired at the end of a tick, after engine update and after rendering
Event Payload:
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
Event Payload:
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, "beforeRender", callback)
deprecated
Fired before rendering
Event Payload:
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
Event Payload:
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
Event Payload:
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
Event Payload:
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