Class: BodyBounds

Phaser.Physics.Matter. BodyBounds

The Body Bounds class contains methods to help you extract the world coordinates from various points around the bounds of a Matter Body. Because Matter bodies are positioned based on their center of mass, and not a dimension based center, you often need to get the bounds coordinates in order to properly align them in the world.

You can access this class via the MatterPhysics class from a Scene, i.e.:

this.matter.bodyBounds.getTopLeft(body);

See also the MatterPhysics.alignBody method.


new BodyBounds()

Since: 3.22.0
Source: src/physics/matter-js/BodyBounds.js (Line 10)

Members


boundsCenter :Phaser.Math.Vector2

A Vector2 that stores the temporary bounds center value during calculations by methods in this class.

Type:
Since: 3.22.0
Source: src/physics/matter-js/BodyBounds.js (Line 36)

centerDiff :Phaser.Math.Vector2

A Vector2 that stores the temporary center diff values during calculations by methods in this class.

Type:
Since: 3.22.0
Source: src/physics/matter-js/BodyBounds.js (Line 45)

Methods


getBottomCenter(body [, x] [, y])

Takes a Body and returns the world coordinates of the bottom-center of its bounds.

Body bounds are updated by Matter each step and factor in scale and rotation. This will return the world coordinate based on the bodies current position and bounds.

Parameters:
Name Type Argument Default Description
body Phaser.Types.Physics.Matter.MatterBody

The Body to get the position from.

x number <optional>
0

Optional horizontal offset to add to the returned coordinates.

y number <optional>
0

Optional vertical offset to add to the returned coordinates.

Since: 3.22.0
Source: src/physics/matter-js/BodyBounds.js (Line 330)
Returns:

A Vector2 containing the coordinates, or false if it was unable to parse the body.

Type
Phaser.Math.Vector2 | false

getBottomLeft(body [, x] [, y])

Takes a Body and returns the world coordinates of the bottom-left of its bounds.

Body bounds are updated by Matter each step and factor in scale and rotation. This will return the world coordinate based on the bodies current position and bounds.

Parameters:
Name Type Argument Default Description
body Phaser.Types.Physics.Matter.MatterBody

The Body to get the position from.

x number <optional>
0

Optional horizontal offset to add to the returned coordinates.

y number <optional>
0

Optional vertical offset to add to the returned coordinates.

Since: 3.22.0
Source: src/physics/matter-js/BodyBounds.js (Line 296)
Returns:

A Vector2 containing the coordinates, or false if it was unable to parse the body.

Type
Phaser.Math.Vector2 | false

getBottomRight(body [, x] [, y])

Takes a Body and returns the world coordinates of the bottom-right of its bounds.

Body bounds are updated by Matter each step and factor in scale and rotation. This will return the world coordinate based on the bodies current position and bounds.

Parameters:
Name Type Argument Default Description
body Phaser.Types.Physics.Matter.MatterBody

The Body to get the position from.

x number <optional>
0

Optional horizontal offset to add to the returned coordinates.

y number <optional>
0

Optional vertical offset to add to the returned coordinates.

Since: 3.22.0
Source: src/physics/matter-js/BodyBounds.js (Line 364)
Returns:

A Vector2 containing the coordinates, or false if it was unable to parse the body.

Type
Phaser.Math.Vector2 | false

getCenter(body [, x] [, y])

Takes a Body and returns the world coordinates of the center of its bounds.

Body bounds are updated by Matter each step and factor in scale and rotation. This will return the world coordinate based on the bodies current position and bounds.

Parameters:
Name Type Argument Default Description
body Phaser.Types.Physics.Matter.MatterBody

The Body to get the position from.

x number <optional>
0

Optional horizontal offset to add to the returned coordinates.

y number <optional>
0

Optional vertical offset to add to the returned coordinates.

Since: 3.22.0
Source: src/physics/matter-js/BodyBounds.js (Line 229)
Returns:

A Vector2 containing the coordinates, or false if it was unable to parse the body.

Type
Phaser.Math.Vector2 | false

getLeftCenter(body [, x] [, y])

Takes a Body and returns the world coordinates of the left-center of its bounds.

Body bounds are updated by Matter each step and factor in scale and rotation. This will return the world coordinate based on the bodies current position and bounds.

Parameters:
Name Type Argument Default Description
body Phaser.Types.Physics.Matter.MatterBody

The Body to get the position from.

x number <optional>
0

Optional horizontal offset to add to the returned coordinates.

y number <optional>
0

Optional vertical offset to add to the returned coordinates.

Since: 3.22.0
Source: src/physics/matter-js/BodyBounds.js (Line 195)
Returns:

A Vector2 containing the coordinates, or false if it was unable to parse the body.

Type
Phaser.Math.Vector2 | false

getRightCenter(body [, x] [, y])

Takes a Body and returns the world coordinates of the right-center of its bounds.

Body bounds are updated by Matter each step and factor in scale and rotation. This will return the world coordinate based on the bodies current position and bounds.

Parameters:
Name Type Argument Default Description
body Phaser.Types.Physics.Matter.MatterBody

The Body to get the position from.

x number <optional>
0

Optional horizontal offset to add to the returned coordinates.

y number <optional>
0

Optional vertical offset to add to the returned coordinates.

Since: 3.22.0
Source: src/physics/matter-js/BodyBounds.js (Line 262)
Returns:

A Vector2 containing the coordinates, or false if it was unable to parse the body.

Type
Phaser.Math.Vector2 | false

getTopCenter(body [, x] [, y])

Takes a Body and returns the world coordinates of the top-center of its bounds.

Body bounds are updated by Matter each step and factor in scale and rotation. This will return the world coordinate based on the bodies current position and bounds.

Parameters:
Name Type Argument Default Description
body Phaser.Types.Physics.Matter.MatterBody

The Body to get the position from.

x number <optional>
0

Optional horizontal offset to add to the returned coordinates.

y number <optional>
0

Optional vertical offset to add to the returned coordinates.

Since: 3.22.0
Source: src/physics/matter-js/BodyBounds.js (Line 127)
Returns:

A Vector2 containing the coordinates, or false if it was unable to parse the body.

Type
Phaser.Math.Vector2 | false

getTopLeft(body [, x] [, y])

Takes a Body and returns the world coordinates of the top-left of its bounds.

Body bounds are updated by Matter each step and factor in scale and rotation. This will return the world coordinate based on the bodies current position and bounds.

Parameters:
Name Type Argument Default Description
body Phaser.Types.Physics.Matter.MatterBody

The Body to get the position from.

x number <optional>
0

Optional horizontal offset to add to the returned coordinates.

y number <optional>
0

Optional vertical offset to add to the returned coordinates.

Since: 3.22.0
Source: src/physics/matter-js/BodyBounds.js (Line 93)
Returns:

A Vector2 containing the coordinates, or false if it was unable to parse the body.

Type
Phaser.Math.Vector2 | false

getTopRight(body [, x] [, y])

Takes a Body and returns the world coordinates of the top-right of its bounds.

Body bounds are updated by Matter each step and factor in scale and rotation. This will return the world coordinate based on the bodies current position and bounds.

Parameters:
Name Type Argument Default Description
body Phaser.Types.Physics.Matter.MatterBody

The Body to get the position from.

x number <optional>
0

Optional horizontal offset to add to the returned coordinates.

y number <optional>
0

Optional vertical offset to add to the returned coordinates.

Since: 3.22.0
Source: src/physics/matter-js/BodyBounds.js (Line 161)
Returns:

A Vector2 containing the coordinates, or false if it was unable to parse the body.

Type
Phaser.Math.Vector2 | false

parseBody(body)

Parses the given body to get the bounds diff values from it.

They're stored in this class in the temporary properties boundsCenter and centerDiff.

This method is called automatically by all other methods in this class.

Parameters:
Name Type Description
body Phaser.Types.Physics.Matter.MatterBody

The Body to get the bounds position from.

Since: 3.22.0
Source: src/physics/matter-js/BodyBounds.js (Line 55)
Returns:

true if it was able to get the bounds, otherwise false.

Type
boolean