Skip to main content
Version: Phaser v3.90.0

Phaser.Physics.Arcade

GetCollidesWith

<static> GetCollidesWith(categories)

Description:

Calculates and returns the bitmask needed to determine if the given

categories will collide with each other or not.

Parameters:

nametypeoptionaldescription
categoriesnumber | Array.<number>NoA unique category bitfield, or an array of them.

Returns: number - The collision mask.

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:

nametypeoptionaldescription
body1Phaser.Physics.Arcade.BodyNoThe first Body to separate.
body2Phaser.Physics.Arcade.BodyNoThe second Body to separate.
overlapOnlybooleanNoIs this an overlap only check, or part of separation?
biasnumberNoA 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 and `overlapY'.

Parameters:

nametypeoptionaldescription
body1Phaser.Physics.Arcade.BodyNoThe first Body to separate.
body2Phaser.Physics.Arcade.BodyNoThe second Body to separate.
overlapOnlybooleanNoIs this an overlap only check, or part of separation?
biasnumberNoA 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 they are static, or if either one uses custom logic for its separation.

Parameters:

nametypeoptionaldescription
body1Phaser.Physics.Arcade.BodyNoThe first Body to separate.
body2Phaser.Physics.Arcade.BodyNoThe second Body to separate.
overlapOnlybooleanNoIf true, the bodies will only have their overlap data set and no separation will take place.
biasnumberNoA value to add to the delta value during overlap checking. Used to prevent sprite tunneling.
overlapnumberYesIf 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/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:

nametypeoptionaldescription
body1Phaser.Physics.Arcade.BodyNoThe first Body to separate.
body2Phaser.Physics.Arcade.BodyNoThe second Body to separate.
overlapOnlybooleanNoIf true, the bodies will only have their overlap data set and no separation will take place.
biasnumberNoA value to add to the delta value during overlap checking. Used to prevent sprite tunneling.
overlapnumberYesIf 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.

Mostly only used internally.

Parameters:

nametypeoptionaldescription
noneFlipbooleanNoIs none true or false?
dataPhaser.Types.Physics.Arcade.ArcadeBodyCollisionYesThe 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:

nametypeoptionaldescription
b1Phaser.Physics.Arcade.BodyNoThe first Body to separate.
b2Phaser.Physics.Arcade.BodyNoThe second Body to separate.
ovnumberNoThe 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:

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/ProcessX.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/ProcessX.js#L118
Since: 3.50.0

Run

<static> Run(side)

Description:

The main check function. Runs through one of the four possible tests and returns the results.

Parameters:

nametypeoptionaldescription
sidenumberNoThe side to test. As passed in by the Check function.

Returns: boolean - Always returns true.

Source: src/physics/arcade/ProcessX.js#L169
Since: 3.50.0

RunImmovableBody1

<static> RunImmovableBody1(blockedState)

Description:

This function is run when Body1 is Immovable and Body2 is not.

Parameters:

nametypeoptionaldescription
blockedStatenumberNoThe block state value.

Source: src/physics/arcade/ProcessX.js#L331
Since: 3.50.0

RunImmovableBody2

<static> RunImmovableBody2(blockedState)

Description:

This function is run when Body2 is Immovable and Body1 is not.

Parameters:

nametypeoptionaldescription
blockedStatenumberNoThe block state value.

Source: src/physics/arcade/ProcessX.js#L367
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:

nametypeoptionaldescription
b1Phaser.Physics.Arcade.BodyNoThe first Body to separate.
b2Phaser.Physics.Arcade.BodyNoThe second Body to separate.
ovnumberNoThe 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:

The main check function. Runs through one of the four possible tests and returns the results.

Parameters:

nametypeoptionaldescription
sidenumberNoThe 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:

nametypeoptionaldescription
blockedStatenumberNoThe block state value.

Source: src/physics/arcade/ProcessY.js#L331
Since: 3.50.0

RunImmovableBody2

<static> RunImmovableBody2(blockedState)

Description:

This function is run when Body2 is Immovable and Body1 is not.

Parameters:

nametypeoptionaldescription
blockedStatenumberNoThe block state value.

Source: src/physics/arcade/ProcessY.js#L367
Since: 3.50.0

Phaser.Physics.Arcade.Components

OverlapCirc

<static> OverlapCirc(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:

nametypeoptionaldefaultdescription
xnumberNoThe x coordinate of the center of the area to search within.
ynumberNoThe y coordinate of the center of the area to search within.
radiusnumberNoThe radius of the area to search within.
includeDynamicbooleanYestrueShould the search include Dynamic Bodies?
includeStaticbooleanYesfalseShould 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(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 for is extremely fast,

otherwise the search is O(N) for Dynamic Bodies.

Parameters:

nametypeoptionaldefaultdescription
xnumberNoThe top-left x coordinate of the area to search within.
ynumberNoThe top-left y coordinate of the area to search within.
widthnumberNoThe width of the area to search within.
heightnumberNoThe height of the area to search within.
includeDynamicbooleanYestrueShould the search include Dynamic Bodies?
includeStaticbooleanYesfalseShould 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:

A function to process the collision callbacks between a single tile and an Arcade Physics enabled Game Object.

Parameters:

nametypeoptionaldescription
tilePhaser.Tilemaps.TileNoThe Tile to process.
spritePhaser.GameObjects.SpriteNoThe Game Object to process with the Tile.

Returns: boolean - The result of the callback, true for further processing, or false to skip this pair.

Source: src/physics/arcade/tilemap/ProcessTileCallbacks.js#L7
Since: 3.0.0

ProcessTileSeparationX

<static> ProcessTileSeparationX(body, x)

Description:

Internal function to process the separation of a physics body from a tile.

Parameters:

nametypeoptionaldescription
bodyPhaser.Physics.Arcade.BodyNoThe Body object to separate.
xnumberNoThe x separation amount.

Source: src/physics/arcade/tilemap/ProcessTileSeparationX.js#L7
Since: 3.0.0

ProcessTileSeparationY

<static> ProcessTileSeparationY(body, y)

Description:

Internal function to process the separation of a physics body from a tile.

Parameters:

nametypeoptionaldescription
bodyPhaser.Physics.Arcade.BodyNoThe Body object to separate.
ynumberNoThe y separation amount.

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 and a tile.

Parameters:

nametypeoptionaldescription
inumberNoThe index of the tile within the map data.
bodyPhaser.Physics.Arcade.BodyNoThe Body object to separate.
tilePhaser.Tilemaps.TileNoThe tile to collide against.
tileWorldRectPhaser.Geom.RectangleNoA rectangle-like object defining the dimensions of the tile.
tilemapLayerPhaser.Tilemaps.TilemapLayerNoThe tilemapLayer to collide against.
tileBiasnumberNoThe tile bias value. Populated by the World.TILE_BIAS constant.
isLayerbooleanNoIs 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:

Check the body against the given tile on the X axis.

Used internally by the SeparateTile function.

Parameters:

nametypeoptionaldescription
bodyPhaser.Physics.Arcade.BodyNoThe Body object to separate.
tilePhaser.Tilemaps.TileNoThe tile to check.
tileLeftnumberNoThe left position of the tile within the tile world.
tileRightnumberNoThe right position of the tile within the tile world.
tileBiasnumberNoThe tile bias value. Populated by the World.TILE_BIAS constant.
isLayerbooleanNoIs 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:

Check the body against the given tile on the Y axis.

Used internally by the SeparateTile function.

Parameters:

nametypeoptionaldescription
bodyPhaser.Physics.Arcade.BodyNoThe Body object to separate.
tilePhaser.Tilemaps.TileNoThe tile to check.
tileTopnumberNoThe top position of the tile within the tile world.
tileBottomnumberNoThe bottom position of the tile within the tile world.
tileBiasnumberNoThe tile bias value. Populated by the World.TILE_BIAS constant.
isLayerbooleanNoIs this check coming from a TilemapLayer or an array of tiles?

Returns: number - The amount of separation that occurred.

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:

nametypeoptionaldescription
tileWorldRectObjectNoA rectangle object that defines the tile placement in the world.
bodyPhaser.Physics.Arcade.BodyNoThe body to check for intersection against.

Returns: boolean - Returns true of 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 Matter Game Object is a generic object that allows you to combine any Phaser Game Object,

including those you have extended or created yourself, with all of the Matter Components.

This enables you to use component methods such as setVelocity or isSensor directly from

this Game Object.

Parameters:

nametypeoptionaldefaultdescription
worldPhaser.Physics.Matter.WorldNoThe Matter world to add the body to.
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object that will have the Matter body applied to it.
optionsPhaser.Types.Physics.Matter.MatterBodyConfig | MatterJS.BodyYesA Matter Body configuration object, or an instance of a Matter Body.
addToWorldbooleanYestrueShould the newly created body be immediately added to the World?

Returns: Phaser.GameObjects.GameObject - The Game Object that was created with the Matter body.

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 element exported by PhysicsEditor.

Parameters:

nametypeoptionaldescription
xnumberNoThe horizontal world location of the body.
ynumberNoThe vertical world location of the body.
configobjectNoThe body configuration and fixture (child body) definitions, as exported by PhysicsEditor.
optionsPhaser.Types.Physics.Matter.MatterBodyConfigYesAn 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#L24
Since: 3.10.0

parseFixture

<static> parseFixture(fixtureConfig)

Description:

Parses an element of the "fixtures" list exported by PhysicsEditor

Parameters:

nametypeoptionaldescription
fixtureConfigobjectNoThe fixture object to parse.

Returns: Array.<MatterJS.BodyType> - - An array of Matter JS Bodies.

Source: src/physics/matter-js/PhysicsEditorParser.js#L70
Since: 3.10.0

parseVertices

<static> parseVertices(vertexSets, [options])

Description:

Parses the "vertices" lists exported by PhysicsEditor.

Parameters:

nametypeoptionaldescription
vertexSetsarrayNoThe vertex lists to parse.
optionsPhaser.Types.Physics.Matter.MatterBodyConfigYesAn 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#L104
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:

nametypeoptionaldescription
xnumberNoThe horizontal world location of the body.
ynumberNoThe vertical world location of the body.
configobjectNoThe body configuration data.
optionsPhaser.Types.Physics.Matter.MatterBodyConfigYesAn 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