new World(scene, config)
Parameters:
| Name | Type | Description |
|---|---|---|
scene |
Phaser.Scene | The Scene to which this Matter World instance belongs. |
config |
Phaser.Types.Physics.Matter.MatterWorldConfig | The Matter World configuration object. |
- Since: 3.0.0
- Source: src/physics/matter-js/World.js (Line 23)
Extends
Members
-
autoUpdate :boolean
-
Automatically call Engine.update every time the game steps. If you disable this then you are responsible for calling
World.stepdirectly from your game. If you callset60Hzorset30HzthenautoUpdateis reset totrue.Type:
- boolean
- Since: 3.4.0
- Default Value:
-
- true
- Source: src/physics/matter-js/World.js (Line 198)
-
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 is 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 113)
-
debugConfig :Phaser.Types.Physics.Matter.MatterDebugConfig
-
The debug configuration object.
The values stored in this object are read from the Matter World Config
debugproperty.When a new Body or Constraint is added to the World, they are given the values stored in this object, unless they have their own
renderobject set that will override them.Note that while you can modify the values of properties in this object at run-time, it will not change any of the Matter objects already added. It will only impact objects newly added to the world, or one that is removed and then re-added at a later time.
Type:
- Since: 3.22.0
- Source: src/physics/matter-js/World.js (Line 231)
-
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 222)
-
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 212)
-
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 103)
-
engine :MatterJS.Engine
-
An instance of the MatterJS Engine.
Type:
- MatterJS.Engine
- Since: 3.0.0
- Source: src/physics/matter-js/World.js (Line 65)
-
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:
timeanddelta, 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.updateas many times as required. Each call will trigger thegetDeltafunction. If you wish to have full control over when the Engine updates then see the propertyautoUpdate.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 127)
-
localWorld :MatterJS.World
-
A
Worldcomposite object that will contain all simulated bodies and constraints.Type:
- MatterJS.World
- Since: 3.0.0
- Source: src/physics/matter-js/World.js (Line 74)
-
runner :Phaser.Types.Physics.Matter.MatterRunnerConfig
-
The Matter JS Runner Configuration object.
This object is populated via the Matter Configuration object's
runnerproperty and is updated constantly during the game step.Type:
- Since: 3.22.0
- Source: src/physics/matter-js/World.js (Line 172)
-
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 56)
-
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 94)
Methods
-
add(object)
-
Adds a Matter JS object, or array of objects, to the world.
The objects should be valid Matter JS entities, such as a Body, Composite or Constraint.
Triggers
beforeAddandafterAddevents.Parameters:
Name Type Description objectobject | Array.<object> Can be single object, or an array, and can be a body, composite or constraint.
- Since: 3.0.0
- Source: src/physics/matter-js/World.js (Line 900)
Returns:
This Matter World object.
-
addListener(event, fn [, context])
-
Add a listener for a given event.
Parameters:
Name Type Argument Default Description eventstring | symbol The event name.
fnfunction 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. -
convertTilemapLayer(tilemapLayer [, options])
-
Adds
MatterTileBodyinstances 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 tilemapLayerPhaser.Tilemaps.TilemapLayer An array of tiles.
optionsobject <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 975)
Returns:
This Matter World object.
-
convertTiles(tiles [, options])
-
Adds
MatterTileBodyinstances for the given tiles. This adds bodies regardless of whether the tiles are set to collide or not.Parameters:
Name Type Argument Description tilesArray.<Phaser.Tilemaps.Tile> An array of tiles.
optionsobject <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 998)
Returns:
This Matter World object.
-
create(x, y, width, height, options)
-
Creates a rectangle Matter body and adds it to the world.
Parameters:
Name Type Description xnumber The horizontal position of the body in the world.
ynumber The vertical position of the body in the world.
widthnumber The width of the body.
heightnumber The height of the body.
optionsobject Optional Matter configuration object.
- Since: 3.0.0
- Source: src/physics/matter-js/World.js (Line 877)
Returns:
The Matter.js body that was created.
- Type
- MatterJS.BodyType
-
createDebugGraphic()
-
Creates a Phaser.GameObjects.Graphics object that is used to render all of the debug bodies and joints to.
This method is called automatically by the constructor, if debugging has been enabled.
The created Graphics object is automatically added to the Scene at 0x0 and given a depth of
Number.MAX_VALUE, so it renders above all else in the Scene.The Graphics object is assigned to the
debugGraphicproperty of this class anddrawDebugis enabled.- Since: 3.0.0
- Source: src/physics/matter-js/World.js (Line 802)
Returns:
The newly created Graphics object.
-
destroy()
-
Will remove all Matter physics event listeners and clear the matter physics world, engine and any debug graphics, if any.
After destroying the world it cannot be re-used again.
- Since: 3.0.0
- Overrides:
- Source: src/physics/matter-js/World.js (Line 2198)
-
disableGravity()
-
Sets the world gravity and gravity scale to 0.
- Since: 3.0.0
- Source: src/physics/matter-js/World.js (Line 830)
Returns:
This Matter World object.
-
emit(event [, args])
-
Calls each of the listeners registered for a given event.
Parameters:
Name Type Argument Description eventstring | 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:
trueif the event had listeners, elsefalse.- 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.<(string|symbol)>
-
getAllBodies()
-
Returns all the bodies in the Matter World, including all bodies in children, recursively.
- Since: 3.22.0
- Source: src/physics/matter-js/World.js (Line 1255)
Returns:
An array of all the Matter JS Bodies in this World.
- Type
- Array.<MatterJS.BodyType>
-
getAllComposites()
-
Returns all the composites in the Matter World, including all composites in children, recursively.
- Since: 3.22.0
- Source: src/physics/matter-js/World.js (Line 1281)
Returns:
An array of all the Matter JS Composites in this World.
- Type
- Array.<MatterJS.CompositeType>
-
getAllConstraints()
-
Returns all the constraints in the Matter World, including all constraints in children, recursively.
- Since: 3.22.0
- Source: src/physics/matter-js/World.js (Line 1268)
Returns:
An array of all the Matter JS Constraints in this World.
- Type
- Array.<MatterJS.ConstraintType>
-
has(body)
-
Returns
trueif the given body can be found within the World.Parameters:
Name Type Description bodyMatterJS.Body | Phaser.GameObjects.GameObject The Matter Body, or Game Object, to search for within the world.
- Since: 3.22.0
- Source: src/physics/matter-js/World.js (Line 1238)
Returns:
An array of all the Matter JS Bodies in this World.
- Type
- Array.<MatterJS.BodyType>
-
listenerCount(event)
-
Return the number of listeners listening to a given event.
Parameters:
Name Type Description eventstring | 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 eventstring | symbol The event name.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 64)
Returns:
The registered listeners.
- Type
- Array.<function()>
-
nextCategory()
-
Returns the next unique category bitfield (starting after the initial default category 0x0001). There are 32 available.
- Since: 3.0.0
- Source: src/physics/matter-js/World.js (Line 1041)
Returns:
Unique category bitfield
- Type
- number
-
nextGroup( [isNonColliding])
-
Returns the next unique group index for which bodies will collide. If
isNonCollidingistrue, returns the next unique group index for which bodies will not collide.Parameters:
Name Type Argument Default Description isNonCollidingboolean <optional>
false If
true, returns the next unique group index for which bodies will not collide.- Since: 3.0.0
- Source: src/physics/matter-js/World.js (Line 1025)
Returns:
Unique category bitfield
- Type
- number
-
off(event [, fn] [, context] [, once])
-
Remove the listeners of a given event.
Parameters:
Name Type Argument Description eventstring | symbol The event name.
fnfunction <optional>
Only remove the listeners that match this function.
context* <optional>
Only remove the listeners that have this context.
onceboolean <optional>
Only remove one-time listeners.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 151)
Returns:
this. -
on(event, fn [, context])
-
Add a listener for a given event.
Parameters:
Name Type Argument Default Description eventstring | symbol The event name.
fnfunction 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. -
once(event, fn [, context])
-
Add a one-time listener for a given event.
Parameters:
Name Type Argument Default Description eventstring | symbol The event name.
fnfunction 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. -
pause()
-
Pauses this Matter World instance and sets
enabledtofalse.A paused world will not run any simulations for the duration it is paused.
- Since: 3.0.0
- Source: src/physics/matter-js/World.js (Line 1055)
Fires:
Returns:
This Matter World object.
-
remove(object [, deep])
-
Removes a Matter JS object, or array of objects, from the world.
The objects should be valid Matter JS entities, such as a Body, Composite or Constraint.
Triggers
beforeRemoveandafterRemoveevents.Parameters:
Name Type Argument Default Description objectobject | Array.<object> Can be single object, or an array, and can be a body, composite or constraint.
deepboolean <optional>
false Optionally search the objects children and recursively remove those as well.
- Since: 3.0.0
- Source: src/physics/matter-js/World.js (Line 921)
Returns:
This Matter World object.
-
removeAllListeners( [event])
-
Remove all listeners, or those of the specified event.
Parameters:
Name Type Argument Description eventstring | symbol <optional>
The event name.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 165)
Returns:
this. -
removeConstraint(constraint [, deep])
-
Removes a Matter JS constraint, or array of constraints, from the world.
Triggers
beforeRemoveandafterRemoveevents.Parameters:
Name Type Argument Default Description constraintMatterJS.ConstraintType | Array.<MatterJS.ConstraintType> A Matter JS Constraint, or an array of constraints, to be removed.
deepboolean <optional>
false Optionally search the objects children and recursively remove those as well.
- Since: 3.0.0
- Source: src/physics/matter-js/World.js (Line 955)
Returns:
This Matter World object.
-
removeListener(event [, fn] [, context] [, once])
-
Remove the listeners of a given event.
Parameters:
Name Type Argument Description eventstring | symbol The event name.
fnfunction <optional>
Only remove the listeners that match this function.
context* <optional>
Only remove the listeners that have this context.
onceboolean <optional>
Only remove one-time listeners.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 137)
Returns:
this. -
renderBody(body, graphics, showInternalEdges [, lineColor] [, lineOpacity] [, lineThickness] [, fillColor] [, fillOpacity])
-
Renders a single Matter Body to the given Phaser Graphics Game Object.
This method is used internally by the Matter Debug Renderer, but is also exposed publically should you wish to render a Body to your own Graphics instance.
If you don't wish to render a line around the body, set the
lineColorparameter tonull. Equally, if you don't wish to render a fill, set thefillColorparameter tonull.Parameters:
Name Type Argument Default Description bodyMatterJS.BodyType The Matter Body to be rendered.
graphicsPhaser.GameObjects.Graphics The Graphics object to render to.
showInternalEdgesboolean Render internal edges of the polygon?
lineColornumber <optional>
The line color.
lineOpacitynumber <optional>
The line opacity, between 0 and 1.
lineThicknessnumber <optional>
1 The line thickness.
fillColornumber <optional>
The fill color.
fillOpacitynumber <optional>
The fill opacity, between 0 and 1.
- Since: 3.22.0
- Source: src/physics/matter-js/World.js (Line 1841)
Returns:
This Matter World instance for method chaining.
-
renderBodyAxes(bodies, graphics, showAxes, lineColor, lineOpacity)
-
Renders either all axes, or a single axis indicator, for an array of Bodies, to the given Graphics instance.
The debug renderer calls this method if the
showAxesorshowAngleIndicatorconfig values are set.This method is used internally by the Matter Debug Renderer, but is also exposed publically should you wish to render bounds to your own Graphics instance.
Parameters:
Name Type Description bodiesarray An array of bodies from the localWorld.
graphicsPhaser.GameObjects.Graphics The Graphics object to render to.
showAxesboolean If
trueit will render all body axes. Iffalseit will render a single axis indicator.lineColornumber The line color.
lineOpacitynumber The line opacity, between 0 and 1.
- Since: 3.22.0
- Source: src/physics/matter-js/World.js (Line 1632)
-
renderBodyBounds(bodies, graphics, lineColor, lineOpacity)
-
Renders the bounds of an array of Bodies to the given Graphics instance.
If the body is a compound body, it will render the bounds for the parent compound.
The debug renderer calls this method if the
showBoundsconfig value is set.This method is used internally by the Matter Debug Renderer, but is also exposed publically should you wish to render bounds to your own Graphics instance.
Parameters:
Name Type Description bodiesarray An array of bodies from the localWorld.
graphicsPhaser.GameObjects.Graphics The Graphics object to render to.
lineColornumber The line color.
lineOpacitynumber The line opacity, between 0 and 1.
- Since: 3.22.0
- Source: src/physics/matter-js/World.js (Line 1568)
-
renderBodyVelocity(bodies, graphics, lineColor, lineOpacity, lineThickness)
-
Renders a velocity indicator for an array of Bodies, to the given Graphics instance.
The debug renderer calls this method if the
showVelocityconfig value is set.This method is used internally by the Matter Debug Renderer, but is also exposed publically should you wish to render bounds to your own Graphics instance.
Parameters:
Name Type Description bodiesarray An array of bodies from the localWorld.
graphicsPhaser.GameObjects.Graphics The Graphics object to render to.
lineColornumber The line color.
lineOpacitynumber The line opacity, between 0 and 1.
lineThicknessnumber The line thickness.
- Since: 3.22.0
- Source: src/physics/matter-js/World.js (Line 1709)
-
renderCollisions(pairs, graphics, lineColor)
-
Renders the list of collision points and normals to the given Graphics instance.
The debug renderer calls this method if the
showCollisionsconfig value is set.This method is used internally by the Matter Debug Renderer, but is also exposed publically should you wish to render the Grid to your own Graphics instance.
Parameters:
Name Type Description pairsArray.<MatterJS.Pair> An array of Matter Pairs to be rendered.
graphicsPhaser.GameObjects.Graphics The Graphics object to render to.
lineColornumber The line color.
- Since: 3.22.0
- Source: src/physics/matter-js/World.js (Line 1474)
Returns:
This Matter World instance for method chaining.
-
renderConstraint(constraint, graphics, lineColor, lineOpacity, lineThickness, pinSize, anchorColor, anchorSize)
-
Renders a single Matter Constraint, such as a Pin or a Spring, to the given Phaser Graphics Game Object.
This method is used internally by the Matter Debug Renderer, but is also exposed publically should you wish to render a Constraint to your own Graphics instance.
Parameters:
Name Type Description constraintMatterJS.ConstraintType The Matter Constraint to render.
graphicsPhaser.GameObjects.Graphics The Graphics object to render to.
lineColornumber The line color.
lineOpacitynumber The line opacity, between 0 and 1.
lineThicknessnumber The line thickness.
pinSizenumber If this constraint is a pin, this sets the size of the pin circle.
anchorColornumber The color used when rendering this constraints anchors. Set to
nullto not render anchors.anchorSizenumber The size of the anchor circle, if this constraint has anchors and is rendering them.
- Since: 3.22.0
- Source: src/physics/matter-js/World.js (Line 2059)
Returns:
This Matter World instance for method chaining.
-
renderConvexHull(body, graphics, hullColor [, lineThickness])
-
Renders the Convex Hull for a single Matter Body to the given Phaser Graphics Game Object.
This method is used internally by the Matter Debug Renderer, but is also exposed publically should you wish to render a Body hull to your own Graphics instance.
Parameters:
Name Type Argument Default Description bodyMatterJS.BodyType The Matter Body to be rendered.
graphicsPhaser.GameObjects.Graphics The Graphics object to render to.
hullColornumber The color used to render the hull.
lineThicknessnumber <optional>
1 The hull line thickness.
- Since: 3.22.0
- Source: src/physics/matter-js/World.js (Line 1981)
Returns:
This Matter World instance for method chaining.
-
renderGrid(grid, graphics, lineColor, lineOpacity)
-
Renders the Engine Broadphase Controller Grid to the given Graphics instance.
The debug renderer calls this method if the
showBroadphaseconfig value is set.This method is used internally by the Matter Debug Renderer, but is also exposed publically should you wish to render the Grid to your own Graphics instance.
Parameters:
Name Type Description gridMatterJS.Grid The Matter Grid to be rendered.
graphicsPhaser.GameObjects.Graphics The Graphics object to render to.
lineColornumber The line color.
lineOpacitynumber The line opacity, between 0 and 1.
- Since: 3.22.0
- Source: src/physics/matter-js/World.js (Line 1359)
Returns:
This Matter World instance for method chaining.
-
renderSeparations(pairs, graphics, lineColor)
-
Renders the list of Pair separations to the given Graphics instance.
The debug renderer calls this method if the
showSeparationsconfig value is set.This method is used internally by the Matter Debug Renderer, but is also exposed publically should you wish to render the Grid to your own Graphics instance.
Parameters:
Name Type Description pairsArray.<MatterJS.Pair> An array of Matter Pairs to be rendered.
graphicsPhaser.GameObjects.Graphics The Graphics object to render to.
lineColornumber The line color.
- Since: 3.22.0
- Source: src/physics/matter-js/World.js (Line 1405)
Returns:
This Matter World instance for method chaining.
-
resetCollisionIDs()
-
Resets the internal collision IDs that Matter.JS uses for Body collision groups.
You should call this before destroying your game if you need to restart the game again on the same page, without first reloading the page. Or, if you wish to consistently destroy a Scene that contains Matter.js and then run it again later in the same game.
- Since: 3.17.0
- Source: src/physics/matter-js/World.js (Line 2155)
-
resume()
-
Resumes this Matter World instance from a paused state and sets
enabledtotrue.- Since: 3.0.0
- Source: src/physics/matter-js/World.js (Line 1075)
Fires:
Returns:
This Matter World object.
-
setBodyRenderStyle(body [, lineColor] [, lineOpacity] [, lineThickness] [, fillColor] [, fillOpacity])
-
Sets the debug render style for the given Matter Body.
If you are using this on a Phaser Game Object, such as a Matter Sprite, then pass in the body property to this method, not the Game Object itself.
If you wish to skip a parameter, so it retains its current value, pass
falsefor it.If you wish to reset the Body render colors to the defaults found in the World Debug Config, then call this method with just the
bodyparameter provided and no others.Parameters:
Name Type Argument Description bodyMatterJS.BodyType The Matter Body to set the render style on.
lineColornumber <optional>
The line color. If
nullit will use the World Debug Config value.lineOpacitynumber <optional>
The line opacity, between 0 and 1. If
nullit will use the World Debug Config value.lineThicknessnumber <optional>
The line thickness. If
nullit will use the World Debug Config value.fillColornumber <optional>
The fill color. If
nullit will use the World Debug Config value.fillOpacitynumber <optional>
The fill opacity, between 0 and 1. If
nullit will use the World Debug Config value.- Since: 3.22.0
- Source: src/physics/matter-js/World.js (Line 397)
Returns:
This Matter World instance for method chaining.
-
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 xnumber <optional>
0 The x coordinate of the top-left corner of the bounds.
ynumber <optional>
0 The y coordinate of the top-left corner of the bounds.
widthnumber <optional>
The width of the bounds.
heightnumber <optional>
The height of the bounds.
thicknessnumber <optional>
64 The thickness of each wall, in pixels.
leftboolean <optional>
true If true will create the left bounds wall.
rightboolean <optional>
true If true will create the right bounds wall.
topboolean <optional>
true If true will create the top bounds wall.
bottomboolean <optional>
true If true will create the bottom bounds wall.
- Since: 3.0.0
- Source: src/physics/matter-js/World.js (Line 717)
Returns:
This Matter World object.
-
setCompositeRenderStyle(composite)
-
Sets the debug render style for the children of the given Matter Composite.
Composites themselves do not render, but they can contain bodies, constraints and other composites that may do. So the children of this composite are passed to the
setBodyRenderStyle,setCompositeRenderStyleandsetConstraintRenderStylemethods accordingly.Parameters:
Name Type Description compositeMatterJS.CompositeType The Matter Composite to set the render style on.
- Since: 3.22.0
- Source: src/physics/matter-js/World.js (Line 347)
Returns:
This Matter World instance for method chaining.
-
setConstraintRenderStyle(constraint [, lineColor] [, lineOpacity] [, lineThickness] [, pinSize] [, anchorColor] [, anchorSize])
-
Sets the debug render style for the given Matter Constraint.
If you are using this on a Phaser Game Object, then pass in the body property to this method, not the Game Object itself.
If you wish to skip a parameter, so it retains its current value, pass
falsefor it.If you wish to reset the Constraint render colors to the defaults found in the World Debug Config, then call this method with just the
constraintparameter provided and no others.Parameters:
Name Type Argument Description constraintMatterJS.ConstraintType The Matter Constraint to set the render style on.
lineColornumber <optional>
The line color. If
nullit will use the World Debug Config value.lineOpacitynumber <optional>
The line opacity, between 0 and 1. If
nullit will use the World Debug Config value.lineThicknessnumber <optional>
The line thickness. If
nullit will use the World Debug Config value.pinSizenumber <optional>
If this constraint is a pin, this sets the size of the pin circle. If
nullit will use the World Debug Config value.anchorColornumber <optional>
The color used when rendering this constraints anchors. If
nullit will use the World Debug Config value.anchorSizenumber <optional>
The size of the anchor circle, if this constraint has anchors. If
nullit will use the World Debug Config value.- Since: 3.22.0
- Source: src/physics/matter-js/World.js (Line 483)
Returns:
This Matter World instance for method chaining.
-
setEventsProxy()
-
This internal method acts as a proxy between all of the Matter JS events and then re-emits them via this class.
- Since: 3.0.0
- Source: src/physics/matter-js/World.js (Line 594)
-
setGravity( [x] [, y] [, scale])
-
Sets the worlds gravity to the values given.
Gravity effects all bodies in the world, unless they have the
ignoreGravityflag set.Parameters:
Name Type Argument Default Description xnumber <optional>
0 The world gravity x component.
ynumber <optional>
1 The world gravity y component.
scalenumber <optional>
0.001 The gravity scale factor.
- Since: 3.0.0
- Source: src/physics/matter-js/World.js (Line 847)
Returns:
This Matter World object.
-
shutdown()
-
Will remove all Matter physics event listeners and clear the matter physics world, engine and any debug graphics, if any.
- Since: 3.0.0
- Overrides:
- Source: src/physics/matter-js/World.js (Line 2175)
-
step( [delta] [, correction])
-
Manually advances the physics simulation by one iteration.
You can optionally pass in the
deltaandcorrectionvalues to be used by Engine.update. If undefined they use the Matter defaults of 60Hz and no correction.Calling
stepdirectly bypasses any checks ofenabledorautoUpdate.It also ignores any custom
getDeltafunctions, 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 deltanumber <optional>
16.666 The delta value.
correctionnumber <optional>
1 Optional delta correction value.
- Since: 3.4.0
- Source: src/physics/matter-js/World.js (Line 1180)
-
update(time, delta)
-
The internal update method. This is called automatically by the parent Scene.
Moves the simulation forward in time by delta ms. Uses
World.correctionvalue as 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 asdelta / lastDelta, i.e. the percentage change of delta over the last step. Therefore the value is always 1 (no correction) when delta is constant (or when no correction is desired, which is the default). See the paper on Time Corrected Verlet for more information.Triggers
beforeUpdateandafterUpdateevents. TriggerscollisionStart,collisionActiveandcollisionEndevents.If the World is paused,
updateis still run, but exits early and does not update the Matter Engine.Parameters:
Name Type Description timenumber The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout.
deltanumber 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 1093)
-
update30Hz()
-
Runs the Matter Engine.update at a fixed timestep of 30Hz.
- Since: 3.4.0
- Source: src/physics/matter-js/World.js (Line 1225)
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 1212)
Returns:
The delta value to be passed to Engine.update.
- Type
- number
-
updateWall(add [, position] [, x] [, y] [, width] [, height])
-
Updates the 4 rectangle bodies that were created, if
setBoundswas set in the Matter config, to use the new positions and sizes. This method is usually only called internally via thesetBoundsmethod.Parameters:
Name Type Argument Description addboolean trueif the walls are being added or updated,falseto remove them from the world.positionstring <optional>
Either
left,right,toporbottom. Only optional ifaddisfalse.xnumber <optional>
The horizontal position to place the walls at. Only optional if
addisfalse.ynumber <optional>
The vertical position to place the walls at. Only optional if
addisfalse.widthnumber <optional>
The width of the walls, in pixels. Only optional if
addisfalse.heightnumber <optional>
The height of the walls, in pixels. Only optional if
addisfalse.- Since: 3.0.0
- Source: src/physics/matter-js/World.js (Line 760)
