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 configstring | Phaser.Types.Physics.Matter.MatterSetBodyConfig Either a string, such as
circle, or a Matter Set Body Configuration object.optionsPhaser.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.
-
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 radiusnumber The radius of the circle.
optionsPhaser.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.
-
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 bodyMatterJS.BodyType The Body this Game Object should use.
addToWorldboolean <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.
-
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 sidesnumber The number of sides the polygon will have.
radiusnumber The "radius" of the polygon, i.e. the distance from its center to any vertex. This is also the radius of its circumcircle.
optionsPhaser.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.
-
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 widthnumber Width of the rectangle.
heightnumber Height of the rectangle.
optionsPhaser.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.
-
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 widthnumber The width of the trapezoid Body.
heightnumber The height of the trapezoid Body.
slopenumber 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.
optionsPhaser.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.
