Namespace: SetBody

Phaser.Physics.Matter.Components. SetBody

Enables a Matter-enabled Game Object to set its Body. Should be used as a mixin and not directly.

Since: 3.0.0
Source: src/physics/matter-js/components/SetBody.js (Line 15)

Methods


setBody(config [, options])

Set this Game Object to create and use a new Body based on the configuration object given.

Calling this method resets previous properties you may have set on the body, including plugins, mass, friction, etc. So be sure to re-apply these in the options object if needed.

Parameters:
Name Type Argument Description
config string | Phaser.Types.Physics.Matter.MatterSetBodyConfig

Either a string, such as circle, or a Matter Set Body Configuration object.

options Phaser.Types.Physics.Matter.MatterBodyConfig <optional>

An optional Body configuration object that is used to set initial Body properties on creation.

Since: 3.0.0
Source: src/physics/matter-js/components/SetBody.js (Line 175)
Returns:

This Game Object.

Type
Phaser.GameObjects.GameObject

setCircle(radius [, options])

Set the body on a Game Object to a circle.

Calling this methods resets previous properties you may have set on the body, including plugins, mass, friction, etc. So be sure to re-apply these in the options object if needed.

Parameters:
Name Type Argument Description
radius number

The radius of the circle.

options Phaser.Types.Physics.Matter.MatterBodyConfig <optional>

An optional Body configuration object that is used to set initial Body properties on creation.

Since: 3.0.0
Source: src/physics/matter-js/components/SetBody.js (Line 43)
Returns:

This Game Object.

Type
Phaser.GameObjects.GameObject

setExistingBody(body [, addToWorld])

Set this Game Object to use the given existing Matter Body.

The body is first removed from the world before being added to this Game Object.

Parameters:
Name Type Argument Default Description
body MatterJS.BodyType

The Body this Game Object should use.

addToWorld boolean <optional>
true

Should the body be immediately added to the World?

Since: 3.0.0
Source: src/physics/matter-js/components/SetBody.js (Line 103)
Returns:

This Game Object.

Type
Phaser.GameObjects.GameObject

setPolygon(sides, radius [, options])

Set the body on the Game Object to a polygon shape.

Calling this methods resets previous properties you may have set on the body, including plugins, mass, friction, etc. So be sure to re-apply these in the options object if needed.

Parameters:
Name Type Argument Description
sides number

The number of sides the polygon will have.

radius number

The "radius" of the polygon, i.e. the distance from its center to any vertex. This is also the radius of its circumcircle.

options Phaser.Types.Physics.Matter.MatterBodyConfig <optional>

An optional Body configuration object that is used to set initial Body properties on creation.

Since: 3.0.0
Source: src/physics/matter-js/components/SetBody.js (Line 62)
Returns:

This Game Object.

Type
Phaser.GameObjects.GameObject

setRectangle(width, height [, options])

Set the body on a Game Object to a rectangle.

Calling this methods resets previous properties you may have set on the body, including plugins, mass, friction, etc. So be sure to re-apply these in the options object if needed.

Parameters:
Name Type Argument Description
width number

Width of the rectangle.

height number

Height of the rectangle.

options Phaser.Types.Physics.Matter.MatterBodyConfig <optional>

An optional Body configuration object that is used to set initial Body properties on creation.

Since: 3.0.0
Source: src/physics/matter-js/components/SetBody.js (Line 23)
Returns:

This Game Object.

Type
Phaser.GameObjects.GameObject

setTrapezoid(width, height, slope [, options])

Set the body on the Game Object to a trapezoid shape.

Calling this methods resets previous properties you may have set on the body, including plugins, mass, friction, etc. So be sure to re-apply these in the options object if needed.

Parameters:
Name Type Argument Description
width number

The width of the trapezoid Body.

height number

The height of the trapezoid Body.

slope number

The slope of the trapezoid. 0 creates a rectangle, while 1 creates a triangle. Positive values make the top side shorter, while negative values make the bottom side shorter.

options Phaser.Types.Physics.Matter.MatterBodyConfig <optional>

An optional Body configuration object that is used to set initial Body properties on creation.

Since: 3.0.0
Source: src/physics/matter-js/components/SetBody.js (Line 82)
Returns:

This Game Object.

Type
Phaser.GameObjects.GameObject