Class: World

Phaser.Physics.Matter. World

[description]


new World(scene, config)

Parameters:
Name Type Description
scene Phaser.Scene

The Scene to which this Matter World instance belongs.

config object

[description]

Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 21)

Extends

Members


autoUpdate :boolean

Automatically call Engine.update every time the game steps.
If you disable this then you are responsible for calling World.step directly from your game.
If you call set60Hz or set30Hz then autoUpdate is reset to true.

Type:
  • boolean
Since: 3.4.0
Default Value:
  • true
Source: src/physics/matter-js/World.js (Line 165)

correction :number

The correction argument is an optional Number that specifies the time correction factor to apply to the update.
This can help improve the accuracy of the simulation in cases where delta is changing between updates.
The value of correction is defined as delta / lastDelta, i.e. the percentage change of delta over the last step.
Therefore the value is always 1 (no correction) when delta constant (or when no correction is desired, which is the default).
See the paper on Time Corrected Verlet for more information.

Type:
  • number
Since: 3.4.0
Default Value:
  • 1
Source: src/physics/matter-js/World.js (Line 121)

debugGraphic :Phaser.GameObjects.Graphics

An instance of the Graphics object the debug bodies are drawn to, if enabled.

Type:
Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 187)

defaults :object

The default configuration values.

Type:
  • object
Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 196)

drawDebug :boolean

A flag that controls if the debug graphics will be drawn to or not.

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/physics/matter-js/World.js (Line 177)

enabled :boolean

A flag that toggles if the world is enabled or not.

Type:
  • boolean
Since: 3.0.0
Default Value:
  • true
Source: src/physics/matter-js/World.js (Line 111)

engine :MatterJS.Engine

An instance of the MatterJS Engine.

Type:
Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 53)

getDelta :function

This function is called every time the core game loop steps, which is bound to the
Request Animation Frame frequency unless otherwise modified.

The function is passed two values: time and delta, both of which come from the game step values.

It must return a number. This number is used as the delta value passed to Matter.Engine.update.

You can override this function with your own to define your own timestep.

If you need to update the Engine multiple times in a single game step then call
World.update as many times as required. Each call will trigger the getDelta function.
If you wish to have full control over when the Engine updates then see the property autoUpdate.

You can also adjust the number of iterations that Engine.update performs.
Use the Scene Matter Physics config object to set the following properties:

positionIterations (defaults to 6)
velocityIterations (defaults to 4)
constraintIterations (defaults to 2)

Adjusting these values can help performance in certain situations, depending on the physics requirements
of your game.

Type:
  • function
Since: 3.4.0
Source: src/physics/matter-js/World.js (Line 135)

localWorld :MatterJS.World

A World composite object that will contain all simulated bodies and constraints.

Type:
Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 62)

scene :Phaser.Scene

The Scene to which this Matter World instance belongs.

Type:
Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 44)

walls :object

An object containing the 4 wall bodies that bound the physics world.

Type:
  • object
Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 78)

Methods


add(object)

[description]

Parameters:
Name Type Description
object object | Array.<object>

Can be single or an array, and can be a body, composite or constraint

Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 469)
Returns:

This Matter World object.

Type
Phaser.Physics.Matter.World

addListener(event, fn [, context])

Add a listener for a given event.

Parameters:
Name Type Argument Default Description
event string | symbol

The event name.

fn function

The listener function.

context * <optional>
this

The context to invoke the listener with.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 111)
Returns:

this.

Type
Phaser.Events.EventEmitter

convertTilemapLayer(tilemapLayer [, options])

Adds MatterTileBody instances for all the colliding tiles within the given tilemap layer. Set
the appropriate tiles in your layer to collide before calling this method!

Parameters:
Name Type Argument Description
tilemapLayer Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer

An array of tiles.

options object <optional>

Options to be passed to the MatterTileBody constructor. {@ee Phaser.Physics.Matter.TileBody}

Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 524)
Returns:

This Matter World object.

Type
Phaser.Physics.Matter.World

convertTiles(tiles [, options])

Adds MatterTileBody instances for the given tiles. This adds bodies regardless of whether the
tiles are set to collide or not.

Parameters:
Name Type Argument Description
tiles Array.<Phaser.Tilemaps.Tile>

An array of tiles.

options object <optional>

Options to be passed to the MatterTileBody constructor. {@see Phaser.Physics.Matter.TileBody}

Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 547)
Returns:

This Matter World object.

Type
Phaser.Physics.Matter.World

create(x, y, width, height, options)

Creates a rectangle Matter body and adds it to the world.

Parameters:
Name Type Description
x number

The horizontal position of the body in the world.

y number

The vertical position of the body in the world.

width number

The width of the body.

height number

The height of the body.

options object

Optional Matter configuration object.

Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 446)
Returns:

The Matter.js body that was created.

Type
MatterJS.Body

createDebugGraphic()

[description]

Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 380)
Returns:

[description]

Type
Phaser.GameObjects.Graphics

destroy()

[description]

Since: 3.0.0
Overrides:
Source: src/physics/matter-js/World.js (Line 1098)

disableGravity()

[description]

Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 401)
Returns:

This Matter World object.

Type
Phaser.Physics.Matter.World

emit(event [, args])

Calls each of the listeners registered for a given event.

Parameters:
Name Type Argument Description
event string | symbol

The event name.

args * <optional>
<repeatable>

Additional arguments that will be passed to the event handler.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 86)
Returns:

true if the event had listeners, else false.

Type
boolean

eventNames()

Return an array listing the events for which the emitter has registered listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 55)
Returns:
Type
array

fromPath(path, points)

[description]

Parameters:
Name Type Description
path string

[description]

points array

[description]

Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 1048)
Returns:

[description]

Type
array

listenerCount(event)

Return the number of listeners listening to a given event.

Parameters:
Name Type Description
event string | symbol

The event name.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 75)
Returns:

The number of listeners.

Type
number

listeners(event)

Return the listeners registered for a given event.

Parameters:
Name Type Description
event string | symbol

The event name.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 64)
Returns:

The registered listeners.

Type
array

nextCategory()

[description]

Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 589)
Returns:

[description]

Type
number

nextGroup(isNonColliding)

[description]

Parameters:
Name Type Description
isNonColliding boolean

[description]

Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 574)
Returns:

[description]

Type
number

off(event, fn, context, once)

Remove the listeners of a given event.

Parameters:
Name Type Description
event string | symbol

The event name.

fn function

Only remove the listeners that match this function.

context *

Only remove the listeners that have this context.

once boolean

Only remove one-time listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 151)
Returns:

this.

Type
Phaser.Events.EventEmitter

on(event, fn [, context])

Add a listener for a given event.

Parameters:
Name Type Argument Default Description
event string | symbol

The event name.

fn function

The listener function.

context * <optional>
this

The context to invoke the listener with.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 98)
Returns:

this.

Type
Phaser.Events.EventEmitter

once(event, fn [, context])

Add a one-time listener for a given event.

Parameters:
Name Type Argument Default Description
event string | symbol

The event name.

fn function

The listener function.

context * <optional>
this

The context to invoke the listener with.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 124)
Returns:

this.

Type
Phaser.Events.EventEmitter

pause()

[description]

Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 602)
Returns:

This Matter World object.

Type
Phaser.Physics.Matter.World

remove(object, deep)

[description]

Parameters:
Name Type Description
object object

The object to be removed from the world.

deep boolean

[description]

Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 486)
Returns:

This Matter World object.

Type
Phaser.Physics.Matter.World

removeAllListeners( [event])

Remove all listeners, or those of the specified event.

Parameters:
Name Type Argument Description
event string | symbol <optional>

The event name.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 165)
Returns:

this.

Type
Phaser.Events.EventEmitter

removeConstraint(constraint, deep)

[description]

Parameters:
Name Type Description
constraint MatterJS.Constraint

[description]

deep boolean

[description]

Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 506)
Returns:

This Matter World object.

Type
Phaser.Physics.Matter.World

removeListener(event, fn, context, once)

Remove the listeners of a given event.

Parameters:
Name Type Description
event string | symbol

The event name.

fn function

Only remove the listeners that match this function.

context *

Only remove the listeners that have this context.

once boolean

Only remove one-time listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 137)
Returns:

this.

Type
Phaser.Events.EventEmitter

resume()

[description]

Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 619)
Returns:

This Matter World object.

Type
Phaser.Physics.Matter.World

setBounds( [x] [, y] [, width] [, height] [, thickness] [, left] [, right] [, top] [, bottom])

Sets the bounds of the Physics world to match the given world pixel dimensions.
You can optionally set which 'walls' to create: left, right, top or bottom.
If none of the walls are given it will default to use the walls settings it had previously.
I.e. if you previously told it to not have the left or right walls, and you then adjust the world size
the newly created bounds will also not have the left and right walls.
Explicitly state them in the parameters to override this.

Parameters:
Name Type Argument Default Description
x number <optional>
0

The x coordinate of the top-left corner of the bounds.

y number <optional>
0

The y coordinate of the top-left corner of the bounds.

width number <optional>

The width of the bounds.

height number <optional>

The height of the bounds.

thickness number <optional>
128

The thickness of each wall, in pixels.

left boolean <optional>
true

If true will create the left bounds wall.

right boolean <optional>
true

If true will create the right bounds wall.

top boolean <optional>
true

If true will create the top bounds wall.

bottom boolean <optional>
true

If true will create the bottom bounds wall.

Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 295)
Returns:

This Matter World object.

Type
Phaser.Physics.Matter.World

setEventsProxy()

[description]

Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 228)

setGravity( [x] [, y] [, scale])

[description]

Parameters:
Name Type Argument Default Description
x number <optional>
0

[description]

y number <optional>
1

[description]

scale number <optional>

[description]

Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 418)
Returns:

This Matter World object.

Type
Phaser.Physics.Matter.World

shutdown()

[description]

Since: 3.0.0
Overrides:
Source: src/physics/matter-js/World.js (Line 1076)

step( [delta] [, correction])

Manually advances the physics simulation by one iteration.

You can optionally pass in the delta and correction values to be used by Engine.update.
If undefined they use the Matter defaults of 60Hz and no correction.

Calling step directly bypasses any checks of enabled or autoUpdate.

It also ignores any custom getDelta functions, as you should be passing the delta
value in to this call.

You can adjust the number of iterations that Engine.update performs internally.
Use the Scene Matter Physics config object to set the following properties:

positionIterations (defaults to 6)
velocityIterations (defaults to 4)
constraintIterations (defaults to 2)

Adjusting these values can help performance in certain situations, depending on the physics requirements
of your game.

Parameters:
Name Type Argument Default Description
delta number <optional>
16.666

[description]

correction number <optional>
1

[description]

Since: 3.4.0
Source: src/physics/matter-js/World.js (Line 653)

update(time, delta)

[description]

Parameters:
Name Type Description
time number

The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout.

delta number

The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate.

Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 636)

update30Hz()

Runs the Matter Engine.update at a fixed timestep of 30Hz.

Since: 3.4.0
Source: src/physics/matter-js/World.js (Line 698)
Returns:

The delta value to be passed to Engine.update.

Type
number

update60Hz()

Runs the Matter Engine.update at a fixed timestep of 60Hz.

Since: 3.4.0
Source: src/physics/matter-js/World.js (Line 685)
Returns:

The delta value to be passed to Engine.update.

Type
number

updateWall(add, position, x, y, width, height)

[description]

Parameters:
Name Type Description
add boolean

[description]

position string

[description]

x number

[description]

y number

[description]

width number

[description]

height number

[description]

Since: 3.0.0
Source: src/physics/matter-js/World.js (Line 339)