Phaser API Documentation

  Version: 
Filter
This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord
Namespace: SetBody
Phaser.Physics.Matter.Components.SetBody

Methods

setRectangle(width, height, [options])
Focus
Focus

Description:

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 arguments 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.

Returns:
Description:

This Game Object.

Examples:
Since: 3.0.0
Focus
Focus
setCircle(radius, [options])
Focus
Focus

Description:

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 arguments 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.

Returns:
Description:

This Game Object.

Examples:
Since: 3.0.0
Focus
Focus
setPolygon(radius, sides, [options])
Focus
Focus

Description:

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 arguments description
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.

sides number

The number of sides the polygon will have.

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

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

Returns:
Description:

This Game Object.

Examples:
Since: 3.0.0
Focus
Focus
setTrapezoid(width, height, slope, [options])
Focus
Focus

Description:

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 arguments 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.

Returns:
Description:

This Game Object.

Examples:
Since: 3.0.0
Focus
Focus
setExistingBody(body, [addToWorld])
Focus
Focus

Description:

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 arguments 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?

Returns:
Description:

This Game Object.

Examples:
Since: 3.0.0
Focus
Focus
setBody(config, [options])
Focus
Focus

Description:

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 arguments 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.

Returns:
Description:

This Game Object.

Examples:
Since: 3.0.0
Focus
Focus