new MatterPhysics(scene)
Parameters:
| Name | Type | Description |
|---|---|---|
scene |
Phaser.Scene | The Phaser Scene that owns this Matter Physics instance. |
- Since: 3.0.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 41)
Members
-
add :Phaser.Physics.Matter.Factory
-
An instance of the Matter Factory. This class provides lots of functions for creating a wide variety of physics objects and adds them automatically to the Matter World.
You can use this class to cut-down on the amount of code required in your game, however, use of the Factory is entirely optional and should be seen as a development aid. It's perfectly possible to create and add components to the Matter world without using it.
Type:
- Since: 3.0.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 141)
-
axes :MatterJS.AxesFactory
-
A reference to the
Matter.Axesmodule.The
Matter.Axesmodule contains methods for creating and manipulating sets of axes.Type:
- MatterJS.AxesFactory
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 316)
-
bodies :MatterJS.BodiesFactory
-
A reference to the
Matter.Bodiesmodule.The
Matter.Bodiesmodule contains factory methods for creating rigid bodies with commonly used body configurations (such as rectangles, circles and other polygons).Type:
- MatterJS.BodiesFactory
- Since: 3.18.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 290)
-
body :MatterJS.BodyFactory
-
A reference to the
Matter.Bodymodule.The
Matter.Bodymodule contains methods for creating and manipulating body models. AMatter.Bodyis a rigid body that can be simulated by aMatter.Engine. Factories for commonly used body configurations (such as rectangles, circles and other polygons) can be found in theBodiesmodule.Type:
- MatterJS.BodyFactory
- Since: 3.18.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 167)
-
bodyBounds :Phaser.Physics.Matter.BodyBounds
-
An instance of the Body Bounds class. This class contains functions used for getting the world position from various points around the bounds of a physics body.
Type:
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 155)
-
bounds :MatterJS.BoundsFactory
-
A reference to the
Matter.Boundsmodule.The
Matter.Boundsmodule contains methods for creating and manipulating axis-aligned bounding boxes (AABB).Type:
- MatterJS.BoundsFactory
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 327)
-
composite :MatterJS.CompositeFactory
-
A reference to the
Matter.Compositemodule.The
Matter.Compositemodule contains methods for creating and manipulating composite bodies. A composite body is a collection ofMatter.Body,Matter.Constraintand otherMatter.Composite, therefore composites form a tree structure. It is important to use the functions in this module to modify composites, rather than directly modifying their properties. Note that theMatter.Worldobject is also a type ofMatter.Compositeand as such all composite methods here can also operate on aMatter.World.Type:
- MatterJS.CompositeFactory
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 180)
-
composites :MatterJS.CompositesFactory
-
A reference to the
Matter.Compositesmodule.The
Matter.Compositesmodule contains factory methods for creating composite bodies with commonly used configurations (such as stacks and chains).Type:
- MatterJS.CompositesFactory
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 302)
-
config :Phaser.Types.Physics.Matter.MatterWorldConfig
-
The parsed Matter Configuration object.
Type:
- Since: 3.0.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 122)
-
constraint :MatterJS.ConstraintFactory
-
A reference to the
Matter.Constraintmodule.The
Matter.Constraintmodule contains methods for creating and manipulating constraints. Constraints are used for specifying that a fixed distance must be maintained between two bodies (or a body and a fixed world-space position). The stiffness of constraints can be modified to create springs or elastic.Type:
- MatterJS.ConstraintFactory
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 275)
-
detector :MatterJS.DetectorFactory
-
A reference to the
Matter.Detectormodule.The
Matter.Detectormodule contains methods for detecting collisions given a set of pairs.Type:
- MatterJS.DetectorFactory
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 196)
-
grid :MatterJS.GridFactory
-
A reference to the
Matter.Gridmodule.The
Matter.Gridmodule contains methods for creating and manipulating collision broadphase grid structures.Type:
- MatterJS.GridFactory
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 207)
-
pair :MatterJS.PairFactory
-
A reference to the
Matter.Pairmodule.The
Matter.Pairmodule contains methods for creating and manipulating collision pairs.Type:
- MatterJS.PairFactory
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 218)
-
pairs :MatterJS.PairsFactory
-
A reference to the
Matter.Pairsmodule.The
Matter.Pairsmodule contains methods for creating and manipulating collision pair sets.Type:
- MatterJS.PairsFactory
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 229)
-
query :MatterJS.QueryFactory
-
A reference to the
Matter.Querymodule.The
Matter.Querymodule contains methods for performing collision queries.Type:
- MatterJS.QueryFactory
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 240)
-
resolver :MatterJS.ResolverFactory
-
A reference to the
Matter.Resolvermodule.The
Matter.Resolvermodule contains methods for resolving collision pairs.Type:
- MatterJS.ResolverFactory
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 251)
-
sat :MatterJS.SATFactory
-
A reference to the
Matter.SATmodule.The
Matter.SATmodule contains methods for detecting collisions using the Separating Axis Theorem.Type:
- MatterJS.SATFactory
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 262)
-
scene :Phaser.Scene
-
The Phaser Scene that owns this Matter Physics instance
Type:
- Since: 3.0.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 104)
-
svg :MatterJS.SvgFactory
-
A reference to the
Matter.Svgmodule.The
Matter.Svgmodule contains methods for converting SVG images into an array of vector points.To use this module you also need the SVGPathSeg polyfill: https://github.com/progers/pathseg
Type:
- MatterJS.SvgFactory
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 338)
-
systems :Phaser.Scenes.Systems
-
A reference to the Scene Systems that belong to the Scene owning this Matter Physics instance.
Type:
- Since: 3.0.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 113)
-
vector :MatterJS.VectorFactory
-
A reference to the
Matter.Vectormodule.The
Matter.Vectormodule contains methods for creating and manipulating vectors. Vectors are the basis of all the geometry related operations in the engine. AMatter.Vectorobject is of the form{ x: 0, y: 0 }.Type:
- MatterJS.VectorFactory
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 351)
-
vertices :MatterJS.VerticesFactory
-
A reference to the
Matter.Verticesmodule.The
Matter.Verticesmodule contains methods for creating and manipulating sets of vertices. A set of vertices is an array ofMatter.Vectorwith additional indexing properties inserted byVertices.create. AMatter.Bodymaintains a set of vertices to represent the shape of the object (its convex hull).Type:
- MatterJS.VerticesFactory
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 364)
-
verts :MatterJS.VerticesFactory
-
A reference to the
Matter.Verticesmodule.The
Matter.Verticesmodule contains methods for creating and manipulating sets of vertices. A set of vertices is an array ofMatter.Vectorwith additional indexing properties inserted byVertices.create. AMatter.Bodymaintains a set of vertices to represent the shape of the object (its convex hull).Type:
- MatterJS.VerticesFactory
- Since: 3.14.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 377)
-
world :Phaser.Physics.Matter.World
-
An instance of the Matter World class. This class is responsible for the updating of the Matter Physics world, as well as handling debug drawing functions.
Type:
- Since: 3.0.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 131)
Methods
-
alignBody(body, x, y, align)
-
Aligns a Body, or Matter Game Object, against the given coordinates.
The alignment takes place using the body bounds, which take into consideration things like body scale and rotation.
Although a Body has a
positionproperty, it is based on the center of mass for the body, not a dimension based center. This makes aligning bodies difficult, especially if they have rotated or scaled. This method will derive the correct position based on the body bounds and its center of mass offset, in order to align the body with the given coordinate.For example, if you wanted to align a body so it sat in the bottom-center of the Scene, and the world was 800 x 600 in size:
this.matter.alignBody(body, 400, 600, Phaser.Display.Align.BOTTOM_CENTER);You pass in 400 for the x coordinate, because that is the center of the world, and 600 for the y coordinate, as that is the base of the world.
Parameters:
Name Type Description bodyPhaser.Types.Physics.Matter.MatterBody The Body to align.
xnumber The horizontal position to align the body to.
ynumber The vertical position to align the body to.
alignnumber One of the
Phaser.Display.Alignconstants, such asPhaser.Display.Align.TOP_LEFT.- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 1319)
Returns:
This Matter Physics instance.
-
applyForce(bodies, force)
-
Applies a force to a body, at the bodies current position, including resulting torque.
Parameters:
Name Type Description bodiesPhaser.Types.Physics.Matter.MatterBody | Array.<Phaser.Types.Physics.Matter.MatterBody> Either a single Body, or an array of bodies to update. If falsey it will use all bodies in the world.
forcePhaser.Types.Math.Vector2Like A Vector that specifies the force to apply.
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 1184)
Returns:
This Matter Physics instance.
-
applyForceFromAngle(bodies, speed [, angle])
-
Apply a force to a body based on the given angle and speed. If no angle is given, the current body angle is used.
Use very small speed values, such as 0.1, depending on the mass and required velocity.
Parameters:
Name Type Argument Description bodiesPhaser.Types.Physics.Matter.MatterBody | Array.<Phaser.Types.Physics.Matter.MatterBody> Either a single Body, or an array of bodies to update. If falsey it will use all bodies in the world.
speednumber A speed value to be applied to a directional force.
anglenumber <optional>
The angle, in radians, to apply the force from. Leave undefined to use the current body angle.
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 1250)
Returns:
This Matter Physics instance.
-
applyForceFromPosition(bodies, position, speed [, angle])
-
Applies a force to a body, from the given world position, including resulting torque. If no angle is given, the current body angle is used.
Use very small speed values, such as 0.1, depending on the mass and required velocity.
Parameters:
Name Type Argument Description bodiesPhaser.Types.Physics.Matter.MatterBody | Array.<Phaser.Types.Physics.Matter.MatterBody> Either a single Body, or an array of bodies to update. If falsey it will use all bodies in the world.
positionPhaser.Types.Math.Vector2Like A Vector that specifies the world-space position to apply the force at.
speednumber A speed value to be applied to a directional force.
anglenumber <optional>
The angle, in radians, to apply the force from. Leave undefined to use the current body angle.
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 1212)
Returns:
This Matter Physics instance.
-
containsPoint(body, x, y)
-
Checks if the vertices of the given body, or an array of bodies, contains the given point, or not.
You can pass in either a single body, or an array of bodies to be checked. This method will return
trueif any of the bodies in the array contain the point. See theintersectPointmethod if you need to get a list of intersecting bodies.The point should be transformed into the Matter World coordinate system in advance. This happens by default with Input Pointers, but if you wish to use points from another system you may need to transform them before passing them.
Parameters:
Name Type Description bodyPhaser.Types.Physics.Matter.MatterBody | Array.<Phaser.Types.Physics.Matter.MatterBody> The body, or an array of bodies, to check against the point.
xnumber The horizontal coordinate of the point.
ynumber The vertical coordinate of the point.
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 672)
Returns:
trueif the point is within one of the bodies given, otherwisefalse.- Type
- boolean
-
enableAttractorPlugin()
-
Enables the Matter Attractors Plugin.
The attractors plugin that makes it easy to apply continual forces on bodies. It's possible to simulate effects such as wind, gravity and magnetism.
https://github.com/liabru/matter-attractors
This method is called automatically if
plugins.attractorsis set in the Matter World Config. However, you can also call it directly from within your game.- Since: 3.0.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 489)
Returns:
This Matter Physics instance.
-
enableCollisionEventsPlugin()
-
Enables the Matter Collision Events Plugin.
Note that this plugin is enabled by default. So you should only ever need to call this method if you have specifically disabled the plugin in your Matter World Config. You can disable it by setting
plugins.collisionevents: falsein your Matter World Config.This plugin triggers three new events on Matter.Body:
onCollideonCollideEndonCollideActive
These events correspond to the Matter.js events
collisionStart,collisionActiveandcollisionEnd, respectively. You can listen to these events via Matter.Events or they will also be emitted from the Matter World.This plugin also extends Matter.Body with three convenience functions:
Matter.Body.setOnCollide(callback)Matter.Body.setOnCollideEnd(callback)Matter.Body.setOnCollideActive(callback)You can register event callbacks by providing a function of type (pair: Matter.Pair) => void
https://github.com/dxu/matter-collision-events
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 538)
Returns:
This Matter Physics instance.
-
enableWrapPlugin()
-
Enables the Matter Wrap Plugin.
The coordinate wrapping plugin that automatically wraps the position of bodies such that they always stay within the given bounds. Upon crossing a boundary the body will appear on the opposite side of the bounds, while maintaining its velocity.
https://github.com/liabru/matter-wrap
This method is called automatically if
plugins.wrapis set in the Matter World Config. However, you can also call it directly from within your game.- Since: 3.0.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 513)
Returns:
This Matter Physics instance.
-
getConfig()
-
This internal method is called when this class starts and retrieves the final Matter World Config.
- Since: 3.0.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 468)
Returns:
The Matter World Config.
-
getConstraintLength(constraint)
-
Returns the length of the given constraint, which is the distance between the two points.
Parameters:
Name Type Description constraintMatterJS.ConstraintType The constraint to get the length from.
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 1287)
Returns:
The length of the constraint.
- Type
- number
-
getMatterBodies( [bodies])
-
Takes an array and returns a new array made from all of the Matter Bodies found in the original array.
For example, passing in Matter Game Objects, such as a bunch of Matter Sprites, to this method, would return an array containing all of their native Matter Body objects.
If the
bodiesargument is falsey, it will return all bodies in the world.Parameters:
Name Type Argument Description bodiesarray <optional>
An array of objects to extract the bodies from. If falsey, it will return all bodies in the world.
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 1034)
Returns:
An array of native Matter Body objects.
- Type
- Array.<MatterJS.BodyType>
-
intersectBody(body [, bodies])
-
Checks the given Matter Body to see if it intersects with any of the given bodies.
If no bodies are provided it will check against all bodies in the Matter World.
Parameters:
Name Type Argument Description bodyPhaser.Types.Physics.Matter.MatterBody The target body.
bodiesArray.<Phaser.Types.Physics.Matter.MatterBody> <optional>
An array of bodies to check the target body against. If not provided it will search all bodies in the world.
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 823)
Returns:
An array of bodies whos vertices intersect with target body.
- Type
- Array.<Phaser.Types.Physics.Matter.MatterBody>
-
intersectPoint(x, y [, bodies])
-
Checks the given coordinates to see if any vertices of the given bodies contain it.
If no bodies are provided it will search all bodies in the Matter World, including within Composites.
The coordinates should be transformed into the Matter World coordinate system in advance. This happens by default with Input Pointers, but if you wish to use coordinates from another system you may need to transform them before passing them.
Parameters:
Name Type Argument Description xnumber The horizontal coordinate of the point.
ynumber The vertical coordinate of the point.
bodiesArray.<Phaser.Types.Physics.Matter.MatterBody> <optional>
An array of bodies to check. If not provided it will search all bodies in the world.
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 703)
Returns:
An array of bodies which contain the given point.
- Type
- Array.<Phaser.Types.Physics.Matter.MatterBody>
-
intersectRay(x1, y1, x2, y2 [, rayWidth] [, bodies])
-
Checks the given ray segment to see if any vertices of the given bodies intersect with it.
If no bodies are provided it will search all bodies in the Matter World.
The width of the ray can be specified via the
rayWidthparameter.Parameters:
Name Type Argument Default Description x1number The horizontal coordinate of the start of the ray segment.
y1number The vertical coordinate of the start of the ray segment.
x2number The horizontal coordinate of the end of the ray segment.
y2number The vertical coordinate of the end of the ray segment.
rayWidthnumber <optional>
1 The width of the ray segment.
bodiesArray.<Phaser.Types.Physics.Matter.MatterBody> <optional>
An array of bodies to check. If not provided it will search all bodies in the world.
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 787)
Returns:
An array of bodies whos vertices intersect with the ray segment.
- Type
- Array.<Phaser.Types.Physics.Matter.MatterBody>
-
intersectRect(x, y, width, height [, outside] [, bodies])
-
Checks the given rectangular area to see if any vertices of the given bodies intersect with it. Or, if the
outsideparameter is set totrue, it checks to see which bodies do not intersect with it.If no bodies are provided it will search all bodies in the Matter World, including within Composites.
Parameters:
Name Type Argument Default Description xnumber The horizontal coordinate of the top-left of the area.
ynumber The vertical coordinate of the top-left of the area.
widthnumber The width of the area.
heightnumber The height of the area.
outsideboolean <optional>
false If
falseit checks for vertices inside the area, iftrueit checks for vertices outside the area.bodiesArray.<Phaser.Types.Physics.Matter.MatterBody> <optional>
An array of bodies to check. If not provided it will search all bodies in the world.
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 742)
Returns:
An array of bodies that intersect with the given area.
- Type
- Array.<Phaser.Types.Physics.Matter.MatterBody>
-
overlap(target [, bodies] [, overlapCallback] [, processCallback] [, callbackContext])
-
Checks to see if the target body, or an array of target bodies, intersects with any of the given bodies.
If intersection occurs this method will return
trueand, if provided, invoke the callbacks.If no bodies are provided for the second parameter the target will check again all bodies in the Matter World.
Note that bodies can only overlap if they are in non-colliding collision groups or categories.
If you provide a
processCallbackthen the two bodies that overlap are sent to it. This callback must return a boolean and is used to allow you to perform additional processing tests before a final outcome is decided. If it returnstruethen the bodies are finally passed to theoverlapCallback, if set.If you provide an
overlapCallbackthen the matching pairs of overlapping bodies will be sent to it.Both callbacks have the following signature:
function (bodyA, bodyB, collisionInfo)wherebodyAis always the target body. ThecollisionInfoobject contains additional data, such as the angle and depth of penetration.Parameters:
Name Type Argument Description targetPhaser.Types.Physics.Matter.MatterBody | Array.<Phaser.Types.Physics.Matter.MatterBody> The target body, or array of target bodies, to check.
bodiesArray.<Phaser.Types.Physics.Matter.MatterBody> <optional>
The second body, or array of bodies, to check. If falsey it will check against all bodies in the world.
overlapCallbackArcadePhysicsCallback <optional>
An optional callback function that is called if the bodies overlap.
processCallbackArcadePhysicsCallback <optional>
An optional callback function that lets you perform additional checks against the two bodies if they overlap. If this is set then
overlapCallbackwill only be invoked if this callback returnstrue.callbackContext* <optional>
The context, or scope, in which to run the callbacks.
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 860)
Returns:
trueif the target body intersects with any of the bodies given, otherwisefalse.- Type
- boolean
-
pause()
-
Pauses the 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/MatterPhysics.js (Line 577)
Fires:
Returns:
The Matter World object.
-
resume()
-
Resumes this Matter World instance from a paused state and sets
enabledtotrue.- Since: 3.0.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 593)
Returns:
The Matter World object.
-
set30Hz()
-
Sets the Matter Engine to run at fixed timestep of 30Hz and enables
autoUpdate. If you have set a customgetDeltafunction then this will override it.- Since: 3.4.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 623)
Returns:
This Matter Physics instance.
-
set60Hz()
-
Sets the Matter Engine to run at fixed timestep of 60Hz and enables
autoUpdate. If you have set a customgetDeltafunction then this will override it.- Since: 3.4.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 606)
Returns:
This Matter Physics instance.
-
setAngularVelocity(bodies, value)
-
Sets the angular velocity of the bodies instantly. Position, angle, force etc. are unchanged.
Parameters:
Name Type Description bodiesPhaser.Types.Physics.Matter.MatterBody | Array.<Phaser.Types.Physics.Matter.MatterBody> Either a single Body, or an array of bodies to update. If falsey it will use all bodies in the world.
valuenumber The angular velocity.
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 1160)
Returns:
This Matter Physics instance.
-
setCollidesWith(bodies, categories)
-
Sets the collision filter mask of all given Matter Bodies to the given value.
Two Matter Bodies with different collision groups will only collide if each one includes the others category in its mask based on a bitwise AND operation:
(categoryA & maskB) !== 0and(categoryB & maskA) !== 0are both true.Parameters:
Name Type Description bodiesArray.<Phaser.Types.Physics.Matter.MatterBody> An array of bodies to update. If falsey it will use all bodies in the world.
categoriesnumber | Array.<number> A unique category bitfield, or an array of them.
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 993)
Returns:
This Matter Physics instance.
-
setCollisionCategory(bodies, value)
-
Sets the collision filter category of all given Matter Bodies to the given value.
This number must be a power of two between 2^0 (= 1) and 2^31.
Bodies with different collision groups (see #setCollisionGroup) will only collide if their collision categories are included in their collision masks (see #setCollidesWith).
Parameters:
Name Type Description bodiesArray.<Phaser.Types.Physics.Matter.MatterBody> An array of bodies to update. If falsey it will use all bodies in the world.
valuenumber Unique category bitfield.
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 936)
Returns:
This Matter Physics instance.
-
setCollisionGroup(bodies, value)
-
Sets the collision filter group of all given Matter Bodies to the given value.
If the group value is zero, or if two Matter Bodies have different group values, they will collide according to the usual collision filter rules (see #setCollisionCategory and #setCollisionGroup).
If two Matter Bodies have the same positive group value, they will always collide; if they have the same negative group value they will never collide.
Parameters:
Name Type Description bodiesArray.<Phaser.Types.Physics.Matter.MatterBody> An array of bodies to update. If falsey it will use all bodies in the world.
valuenumber Unique group index.
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 964)
Returns:
This Matter Physics instance.
-
setVelocity(bodies, x, y)
-
Sets both the horizontal and vertical linear velocity of the physics bodies.
Parameters:
Name Type Description bodiesPhaser.Types.Physics.Matter.MatterBody | Array.<Phaser.Types.Physics.Matter.MatterBody> Either a single Body, or an array of bodies to update. If falsey it will use all bodies in the world.
xnumber The horizontal linear velocity value.
ynumber The vertical linear velocity value.
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 1073)
Returns:
This Matter Physics instance.
-
setVelocityX(bodies, x)
-
Sets just the horizontal linear velocity of the physics bodies. The vertical velocity of the body is unchanged.
Parameters:
Name Type Description bodiesPhaser.Types.Physics.Matter.MatterBody | Array.<Phaser.Types.Physics.Matter.MatterBody> Either a single Body, or an array of bodies to update. If falsey it will use all bodies in the world.
xnumber The horizontal linear velocity value.
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 1102)
Returns:
This Matter Physics instance.
-
setVelocityY(bodies, y)
-
Sets just the vertical linear velocity of the physics bodies. The horizontal velocity of the body is unchanged.
Parameters:
Name Type Description bodiesPhaser.Types.Physics.Matter.MatterBody | Array.<Phaser.Types.Physics.Matter.MatterBody> Either a single Body, or an array of bodies to update. If falsey it will use all bodies in the world.
ynumber The vertical linear velocity value.
- Since: 3.22.0
- Source: src/physics/matter-js/MatterPhysics.js (Line 1131)
Returns:
This Matter Physics instance.
-
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/MatterPhysics.js (Line 640)
