Matter.Runner
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
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
Continuously ticks a Matter.Engine
by calling Runner.tick
on the requestAnimationFrame
event.
Parameters
-
engine
Engine
Matter.Runner.start
Alias for Runner.run
.
Matter.Runner.stop
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
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.
Properties / Options
The following properties if specified below are for objects created by Matter.Runner.create
and may be passed to it as options
.
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
A flag that specifies whether the runner is running or not.
Default: true
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
Events.on(Runner, "beforeTick
", callback)
Fired at the start of a tick, before any updates to the engine or timing
Callback Parameters
Events.on(Runner, "tick
", callback)
Fired after engine timing updated, but just before update