Phaser.Physics.Arcade
GetCollidesWith
<static> GetCollidesWith(categories)
Description:
Combines one or more category bitfields using bitwise OR and returns the resulting collision mask. This mask can be assigned to an Arcade Physics body to define which categories of bodies it should collide with.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| categories | number | Array.<number> | No | A unique category bitfield, or an array of them. |
Returns: number - A bitmask representing the combined set of categories that should trigger collisions.
Source: src/physics/arcade/GetCollidesWith.js#L7
Since: 3.70.0
GetOverlapX
<static> GetOverlapX(body1, body2, overlapOnly, bias)
Description:
Calculates and returns the horizontal overlap between two arcade physics bodies and sets their properties accordingly, including: touching.left, touching.right, touching.none and overlapX.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| body1 | Phaser.Physics.Arcade.Body | No | The first Body to separate. |
| body2 | Phaser.Physics.Arcade.Body | No | The second Body to separate. |
| overlapOnly | boolean | No | Is this an overlap only check, or part of separation? |
| bias | number | No | A value added to the delta values during collision checks. Increase it to prevent sprite tunneling (sprites passing through another instead of colliding). |
Returns: number - The amount of overlap.
Source: src/physics/arcade/GetOverlapX.js#L9
Since: 3.0.0
GetOverlapY
<static> GetOverlapY(body1, body2, overlapOnly, bias)
Description:
Calculates and returns the vertical overlap between two arcade physics bodies and sets their properties accordingly, including: touching.up, touching.down, touching.none, blocked.up, blocked.down and overlapY.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| body1 | Phaser.Physics.Arcade.Body | No | The first Body to separate. |
| body2 | Phaser.Physics.Arcade.Body | No | The second Body to separate. |
| overlapOnly | boolean | No | Is this an overlap only check, or part of separation? |
| bias | number | No | A value added to the delta values during collision checks. Increase it to prevent sprite tunneling (sprites passing through another instead of colliding). |
Returns: number - The amount of overlap.
Source: src/physics/arcade/GetOverlapY.js#L9
Since: 3.0.0
SeparateX
<static> SeparateX(body1, body2, overlapOnly, bias, [overlap])
Description:
Separates two overlapping bodies on the X-axis (horizontally).
Separation involves moving two overlapping bodies so they don't overlap anymore and adjusting their velocities based on their mass. This is a core part of collision detection.
The bodies won't be separated if there is no horizontal overlap between them, if both are immovable, or if either one uses custom separation logic via customSeparateX.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| body1 | Phaser.Physics.Arcade.Body | No | The first Body to separate. |
| body2 | Phaser.Physics.Arcade.Body | No | The second Body to separate. |
| overlapOnly | boolean | No | If true, the bodies will only have their overlap data set and no separation will take place. |
| bias | number | No | A value to add to the delta value during overlap checking. Used to prevent sprite tunneling. |
| overlap | number | Yes | If given then this value will be used as the overlap and no check will be run. |
Returns: boolean - true if the two bodies overlap horizontally, otherwise false.
Source: src/physics/arcade/SeparateX.js#L10
Since: 3.0.0
SeparateY
<static> SeparateY(body1, body2, overlapOnly, bias, [overlap])
Description:
Separates two overlapping bodies on the Y-axis (vertically).
Separation involves moving two overlapping bodies so they don't overlap anymore and adjusting their velocities based on their mass. This is a core part of collision detection.
The bodies won't be separated if there is no vertical overlap between them, if they are static, or if either one uses custom logic for its separation.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| body1 | Phaser.Physics.Arcade.Body | No | The first Body to separate. |
| body2 | Phaser.Physics.Arcade.Body | No | The second Body to separate. |
| overlapOnly | boolean | No | If true, the bodies will only have their overlap data set and no separation will take place. |
| bias | number | No | A value to add to the delta value during overlap checking. Used to prevent sprite tunneling. |
| overlap | number | Yes | If given then this value will be used as the overlap and no check will be run. |
Returns: boolean - true if the two bodies overlap vertically, otherwise false.
Source: src/physics/arcade/SeparateY.js#L10
Since: 3.0.0
SetCollisionObject
<static> SetCollisionObject(noneFlip, [data])
Description:
Either sets or creates the Arcade Body Collision object.
Sets the none property to the value of noneFlip. When noneFlip is false, all four directional flags (up, down, left, right) are set to true, indicating collision on all sides. When noneFlip is true, all directional flags are set to false.
Mostly only used internally.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| noneFlip | boolean | No | The value to assign to the none property. When false, all directional collision flags are enabled. |
| data | Phaser.Types.Physics.Arcade.ArcadeBodyCollision | Yes | The collision data object to populate, or create if not given. |
Returns: Phaser.Types.Physics.Arcade.ArcadeBodyCollision - The collision data.
Source: src/physics/arcade/SetCollisionObject.js#L7
Since: 3.70.0
Phaser.Physics.Arcade.ProcessX
Set
<static> Set(b1, b2, ov)
Description:
Sets all of the local processing values and calculates the velocity exchanges.
Then runs BlockCheck and returns the value from it.
This method is called by Phaser.Physics.Arcade.SeparateX and should not be called directly.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| b1 | Phaser.Physics.Arcade.Body | No | The first Body to separate. |
| b2 | Phaser.Physics.Arcade.Body | No | The second Body to separate. |
| ov | number | No | The overlap value. |
Returns: number - The BlockCheck result. 0 = not blocked. 1 = Body 1 blocked. 2 = Body 2 blocked.
Source: src/physics/arcade/ProcessX.js#L25
Since: 3.50.0
BlockCheck
<static> BlockCheck()
Description:
Checks whether either body is blocked in the direction of travel and, if so, applies the full impact velocity to the moving body and returns the blocked state. A body that is blocked cannot be separated further regardless of whether it is pushable.
Returns: number - The BlockCheck result. 0 = not blocked. 1 = Body 1 blocked. 2 = Body 2 blocked.
Source: src/physics/arcade/ProcessX.js#L71
Since: 3.50.0
Check
<static> Check()
Description:
Calculates the mass-adjusted impact velocities for both bodies, then determines which of the four horizontal collision scenarios applies (body1 or body2 moving left or right into the other) and delegates to Run with the corresponding side value.
Returns: boolean - true if a check passed, otherwise false.
Source: src/physics/arcade/ProcessX.js#L119
Since: 3.50.0
Run
<static> Run(side)
Description:
Executes the horizontal separation and velocity exchange for the two bodies based on the collision side determined by Check. Handles all combinations of pushable and non-pushable bodies: both pushable (equal mass-based rebound), only one pushable (full impact applied to the pushable body), or neither pushable (overlap split based on movement direction and relative velocity).
Parameters:
| name | type | optional | description |
|---|---|---|---|
| side | number | No | The side to test. As passed in by the Check function. |
Returns: boolean - Always returns true.
Source: src/physics/arcade/ProcessX.js#L172
Since: 3.50.0
RunImmovableBody1
<static> RunImmovableBody1(blockedState)
Description:
Handles horizontal separation when Body1 is immovable and Body2 is not. Pushes Body2 out of the overlap and applies the full impact velocity to it. If Body1 is a moving platform (i.e. body1.moves is true), Body2's vertical position is also adjusted using Body1's vertical friction, allowing Body2 to ride along with the platform.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| blockedState | number | No | The block state value. |
Source: src/physics/arcade/ProcessX.js#L338
Since: 3.50.0
RunImmovableBody2
<static> RunImmovableBody2(blockedState)
Description:
Handles horizontal separation when Body2 is immovable and Body1 is not. Pushes Body1 out of the overlap and applies the full impact velocity to it. If Body2 is a moving platform (i.e. body2.moves is true), Body1's vertical position is also adjusted using Body2's vertical friction, allowing Body1 to ride along with the platform.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| blockedState | number | No | The block state value. |
Source: src/physics/arcade/ProcessX.js#L378
Since: 3.50.0
Phaser.Physics.Arcade.ProcessY
Set
<static> Set(b1, b2, ov)
Description:
Sets all of the local processing values and calculates the velocity exchanges.
Then runs BlockCheck and returns the value from it.
This method is called by Phaser.Physics.Arcade.SeparateY and should not be called directly.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| b1 | Phaser.Physics.Arcade.Body | No | The first Body to separate. |
| b2 | Phaser.Physics.Arcade.Body | No | The second Body to separate. |
| ov | number | No | The overlap value. |
Returns: number - The BlockCheck result. 0 = not blocked. 1 = Body 1 blocked. 2 = Body 2 blocked.
Source: src/physics/arcade/ProcessY.js#L25
Since: 3.50.0
BlockCheck
<static> BlockCheck()
Description:
Blocked Direction checks, because it doesn't matter if an object can be pushed or not, blocked is blocked.
Returns: number - The BlockCheck result. 0 = not blocked. 1 = Body 1 blocked. 2 = Body 2 blocked.
Source: src/physics/arcade/ProcessY.js#L71
Since: 3.50.0
Check
<static> Check()
Description:
The main check function. Runs through one of the four possible tests and returns the results.
Returns: boolean - true if a check passed, otherwise false.
Source: src/physics/arcade/ProcessY.js#L118
Since: 3.50.0
Run
<static> Run(side)
Description:
Executes the vertical separation and velocity exchange for the two bodies, based on the collision side determined by the Check function. Handles all combinations of pushable and non-pushable bodies, distributing overlap and recalculating post-collision velocities accordingly.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| side | number | No | The side to test. As passed in by the Check function. |
Returns: boolean - Always returns true.
Source: src/physics/arcade/ProcessY.js#L169
Since: 3.50.0
RunImmovableBody1
<static> RunImmovableBody1(blockedState)
Description:
This function is run when Body1 is Immovable and Body2 is not.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| blockedState | number | No | The block state value. |
Source: src/physics/arcade/ProcessY.js#L334
Since: 3.50.0
RunImmovableBody2
<static> RunImmovableBody2(blockedState)
Description:
This function is run when Body2 is Immovable and Body1 is not.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| blockedState | number | No | The block state value. |
Source: src/physics/arcade/ProcessY.js#L370
Since: 3.50.0
Phaser.Physics.Arcade.Components
OverlapCirc
<static> OverlapCirc(world, x, y, radius, [includeDynamic], [includeStatic])
Description:
This method will search the given circular area and return an array of all physics bodies that overlap with it. It can return either Dynamic, Static bodies or a mixture of both.
A body only has to intersect with the search area to be considered, it doesn't have to be fully contained within it.
If Arcade Physics is set to use the RTree (which it is by default) then the search is rather fast, otherwise the search is O(N) for Dynamic Bodies.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| world | Phaser.Physics.Arcade.World | No | The Arcade Physics World. | |
| x | number | No | The x coordinate of the center of the area to search within, in pixels. | |
| y | number | No | The y coordinate of the center of the area to search within, in pixels. | |
| radius | number | No | The radius of the area to search within, in pixels. | |
| includeDynamic | boolean | Yes | true | Should the search include Dynamic Bodies? |
| includeStatic | boolean | Yes | false | Should the search include Static Bodies? |
Returns: Array.<Phaser.Physics.Arcade.Body>, Array.<Phaser.Physics.Arcade.StaticBody> - An array of bodies that overlap with the given area.
Source: src/physics/arcade/components/OverlapCirc.js#L6
Since: 3.21.0
OverlapRect
<static> OverlapRect(world, x, y, width, height, [includeDynamic], [includeStatic])
Description:
This method will search the given rectangular area and return an array of all physics bodies that overlap with it. It can return either Dynamic, Static bodies or a mixture of both.
A body only has to intersect with the search area to be considered, it doesn't have to be fully contained within it.
If Arcade Physics is set to use the RTree (which it is by default) then the search is extremely fast, otherwise the search is O(N) for Dynamic Bodies.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| world | Phaser.Physics.Arcade.World | No | The Arcade Physics World. | |
| x | number | No | The top-left x coordinate of the area to search within. | |
| y | number | No | The top-left y coordinate of the area to search within. | |
| width | number | No | The width of the area to search within. | |
| height | number | No | The height of the area to search within. | |
| includeDynamic | boolean | Yes | true | Should the search include Dynamic Bodies? |
| includeStatic | boolean | Yes | false | Should the search include Static Bodies? |
Returns: Array.<Phaser.Physics.Arcade.Body>, Array.<Phaser.Physics.Arcade.StaticBody> - An array of bodies that overlap with the given area.
Source: src/physics/arcade/components/OverlapRect.js#L1
Since: 3.17.0
Phaser.Physics.Arcade.Tilemap
ProcessTileCallbacks
<static> ProcessTileCallbacks(tile, sprite)
Description:
Checks whether a per-tile or per-tile-index collision callback has been registered for the given tile and, if so, invokes it with the colliding Game Object. Tile-level callbacks (set directly on the tile) take priority over layer-level callbacks (set on the tile layer by tile index). If the callback returns true the collision is vetoed and this function returns false to skip further processing of this pair. If no callback is registered, this function returns true so that normal Arcade Physics collision resolution continues.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tile | Phaser.Tilemaps.Tile | No | The Tile to process. |
| sprite | Phaser.GameObjects.Sprite | No | The Game Object to process with the Tile. |
Returns: boolean - true if collision processing should continue for this tile/sprite pair, or false if a callback vetoed the collision and it should be skipped.
Source: src/physics/arcade/tilemap/ProcessTileCallbacks.js#L7
Since: 3.0.0
ProcessTileSeparationX
<static> ProcessTileSeparationX(body, x)
Description:
Internal function to process the horizontal separation of a physics body from a tile. It updates the body's left or right blocked flags based on the direction of separation, moves the body by the separation amount along the x-axis, updates its center, and then either zeroes the horizontal velocity or applies a bounce depending on the body's bounce coefficient.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| body | Phaser.Physics.Arcade.Body | No | The Body object to separate. |
| x | number | No | The x-axis separation distance, in pixels. A negative value indicates the body is blocked on the left; a positive value indicates it is blocked on the right. |
Source: src/physics/arcade/tilemap/ProcessTileSeparationX.js#L7
Since: 3.0.0
ProcessTileSeparationY
<static> ProcessTileSeparationY(body, y)
Description:
Internal function to process the vertical separation of a physics body from a tile.
Updates the body's blocked flags based on the direction of separation, adjusts the body's vertical position by the separation amount, and then either zeroes the vertical velocity or applies the body's bounce factor to reverse it.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| body | Phaser.Physics.Arcade.Body | No | The Body object to separate. |
| y | number | No | The vertical separation amount, in pixels. A negative value indicates the body was blocked from above; a positive value indicates it was blocked from below. |
Source: src/physics/arcade/tilemap/ProcessTileSeparationY.js#L7
Since: 3.0.0
SeparateTile
<static> SeparateTile(i, body, tile, tileWorldRect, tilemapLayer, tileBias, isLayer)
Description:
The core separation function to separate a physics body from a tile, resolving any overlap between them. It determines which axis to process first based on the body's current velocity: if the body is moving faster horizontally the X axis is checked first, and vice versa. When moving diagonally into a tile with colliding faces on both axes, the axis of least overlap is prioritized. Separation is performed by calling TileCheckX and/or TileCheckY as appropriate, and the check short-circuits early if the first axis separation is sufficient to fully resolve the intersection.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| i | number | No | The index of the tile within the map data. |
| body | Phaser.Physics.Arcade.Body | No | The Body object to separate. |
| tile | Phaser.Tilemaps.Tile | No | The tile to collide against. |
| tileWorldRect | Phaser.Geom.Rectangle | No | A rectangle-like object defining the dimensions of the tile. |
| tilemapLayer | Phaser.Tilemaps.TilemapLayer | No | The tilemapLayer to collide against. |
| tileBias | number | No | The tile bias value, defined by the World.TILE_BIAS constant. Used to prevent fast-moving bodies from tunneling through thin tiles. |
| isLayer | boolean | No | Is this check coming from a TilemapLayer or an array of tiles? |
Returns: boolean - true if the body was separated, otherwise false.
Source: src/physics/arcade/tilemap/SeparateTile.js#L11
Since: 3.0.0
TileCheckX
<static> TileCheckX(body, tile, tileLeft, tileRight, tileBias, isLayer)
Description:
Checks the given physics body against a tile on the X axis, calculating the overlap and applying separation if a collision is detected. Respects the tile's face and collision flags when the check originates from a TilemapLayer, and dispatches to ProcessTileSeparationX (or sets body.overlapX if customSeparateX is enabled). Used internally by the SeparateTile function.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| body | Phaser.Physics.Arcade.Body | No | The Body object to separate. |
| tile | Phaser.Tilemaps.Tile | No | The tile to check. |
| tileLeft | number | No | The left edge of the tile in world coordinates, in pixels. |
| tileRight | number | No | The right edge of the tile in world coordinates, in pixels. |
| tileBias | number | No | The tile bias value. Overlaps greater than this threshold are ignored to prevent tunneling. Typically set to World.TILE_BIAS. |
| isLayer | boolean | No | Is this check coming from a TilemapLayer or an array of tiles? |
Returns: number - The amount of separation that occurred.
Source: src/physics/arcade/tilemap/TileCheckX.js#L9
Since: 3.0.0
TileCheckY
<static> TileCheckY(body, tile, tileTop, tileBottom, tileBias, isLayer)
Description:
Checks for overlap between a physics body and a tile along the Y axis and resolves any collision that is found. If the body has a custom separator set, the overlap value is stored on body.overlapY for the caller to handle; otherwise ProcessTileSeparationY is called to resolve the collision immediately. Used internally by the SeparateTile function.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| body | Phaser.Physics.Arcade.Body | No | The Body object to separate. |
| tile | Phaser.Tilemaps.Tile | No | The tile to check. |
| tileTop | number | No | The top position of the tile in world space, in pixels. |
| tileBottom | number | No | The bottom position of the tile in world space, in pixels. |
| tileBias | number | No | The tile bias value, as defined by the World.TILE_BIAS constant. |
| isLayer | boolean | No | Is this check coming from a TilemapLayer or an array of tiles? |
Returns: number - The amount of vertical separation that occurred, in pixels.
Source: src/physics/arcade/tilemap/TileCheckY.js#L9
Since: 3.0.0
TileIntersectsBody
<static> TileIntersectsBody(tileWorldRect, body)
Description:
Checks for intersection between the given tile rectangle-like object and an Arcade Physics body.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileWorldRect | Object | No | A rectangle object that defines the tile placement in the world. |
| body | Phaser.Physics.Arcade.Body | No | The body to check for intersection against. |
Returns: boolean - Returns true if the tile intersects with the body, otherwise false.
Source: src/physics/arcade/tilemap/TileIntersectsBody.js#L7
Since: 3.0.0
Phaser.Physics.Matter
MatterGameObject
<static> MatterGameObject(world, gameObject, [options], [addToWorld])
Description:
A factory function that mixes all Matter.js physics components into any existing Phaser Game Object, including those you have extended or created yourself. This enables you to give any Game Object full Matter physics capabilities without requiring it to extend a specific class.
The following components are mixed directly onto the Game Object: Bounce, Collision, Force, Friction, Gravity, Mass, Sensor, SetBody, Sleep, Static, Transform, and Velocity. This means methods such as setVelocity, setFriction, and isSensor become available directly on the Game Object after this function is called.
If options is an existing Matter Body instance (i.e. its type property equals 'body'), that body is attached via setExistingBody. Otherwise, options is treated as a MatterBodyConfig and a new body is created via setBody, defaulting to a rectangle shape if no shape property is provided.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| world | Phaser.Physics.Matter.World | No | The Matter world to add the body to. | |
| gameObject | Phaser.GameObjects.GameObject | No | The Game Object that will have the Matter body applied to it. | |
| options | Phaser.Types.Physics.Matter.MatterBodyConfig | MatterJS.Body | Yes | A Matter Body configuration object, or an instance of a Matter Body. | |
| addToWorld | boolean | Yes | true | Should the newly created body be immediately added to the World? |
Returns: Phaser.GameObjects.GameObject - The Game Object that was passed in, now enhanced with Matter physics components.
Source: src/physics/matter-js/MatterGameObject.js#L26
Since: 3.3.0
Phaser.Physics.Matter.PhysicsEditorParser
parseBody
<static> parseBody(x, y, config, [options])
Description:
Parses a body configuration exported by PhysicsEditor and creates a compound Matter.js body from it. Each fixture definition in the configuration is parsed and converted into a child body (either a circle or a convex polygon), and all child bodies are combined into a single compound body positioned at the given world coordinates. Additional Matter.js body properties can be supplied via the options argument and will be merged into the body configuration.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| x | number | No | The horizontal world location of the body. |
| y | number | No | The vertical world location of the body. |
| config | object | No | The body configuration and fixture (child body) definitions, as exported by PhysicsEditor. |
| options | Phaser.Types.Physics.Matter.MatterBodyConfig | Yes | An optional Body configuration object that is used to set initial Body properties on creation. |
Returns: MatterJS.BodyType - A compound Matter JS Body.
Source: src/physics/matter-js/PhysicsEditorParser.js#L29
Since: 3.10.0
parseFixture
<static> parseFixture(fixtureConfig)
Description:
Parses a single fixture entry from the "fixtures" list exported by PhysicsEditor. A fixture can describe either a circle (defined by a centre position and radius) or a set of convex polygon vertex lists. The appropriate Matter.js body or bodies are created and returned as an array so they can be combined into a compound body by the caller.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| fixtureConfig | object | No | The fixture object to parse. |
Returns: Array.<MatterJS.BodyType> - - An array of Matter JS Bodies.
Source: src/physics/matter-js/PhysicsEditorParser.js#L79
Since: 3.10.0
parseVertices
<static> parseVertices(vertexSets, [options])
Description:
Parses one or more vertex sets exported by PhysicsEditor and creates a Matter.js body for each set. Before creating each body, the vertices are sorted into clockwise winding order and the body is positioned at the centroid of the vertex set. After all bodies are created, coincident edges between adjacent parts are flagged so that Matter.js can handle them correctly during collision detection.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| vertexSets | array | No | The vertex lists to parse. |
| options | Phaser.Types.Physics.Matter.MatterBodyConfig | Yes | An optional Body configuration object that is used to set initial Body properties on creation. |
Returns: Array.<MatterJS.BodyType> - - An array of Matter JS Bodies.
Source: src/physics/matter-js/PhysicsEditorParser.js#L116
Since: 3.10.0
Phaser.Physics.Matter.PhysicsJSONParser
parseBody
<static> parseBody(x, y, config, [options])
Description:
Parses a body element from the given JSON data.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| x | number | No | The horizontal world location of the body. |
| y | number | No | The vertical world location of the body. |
| config | object | No | The body configuration data. |
| options | Phaser.Types.Physics.Matter.MatterBodyConfig | Yes | An optional Body configuration object that is used to set initial Body properties on creation. |
Returns: MatterJS.BodyType - A Matter JS Body.
Source: src/physics/matter-js/PhysicsJSONParser.js#L53
Since: 3.22.0