Matter.Bodies
Defined in: src/factory/Bodies.js:1
The Matter.Bodies
module contains factory methods for creating rigid body models with commonly used body configurations (such as rectangles, circles and other polygons).
See the included usage examples.
Methods
Matter.Bodies.circle
(x, y, radius, [options], [maxSides])
→ Body
Creates a new rigid body model with a circle hull. The options parameter is an object that specifies any properties you wish to override the defaults. See the properties section of the Matter.Body
module for detailed information on what you can pass via the options
object.
Parameters
x
Number
y
Number
radius
Number
[options]
Objectoptional
[maxSides]
Numberoptional
Returns
BodyA new circle body
Matter.Bodies.fromVertices
(x, y, [[vector]], [options], [flagInternal=false], [removeCollinear=0.01], [minimumArea=10])
→ Body
Creates a body using the supplied vertices (or an array containing multiple sets of vertices). If the vertices are convex, they will pass through as supplied. Otherwise if the vertices are concave, they will be decomposed if poly-decomp.js is available. Note that this process is not guaranteed to support complex sets of vertices (e.g. those with holes may fail). By default the decomposition will discard collinear edges (to improve performance). It can also optionally discard any parts that have an area less than minimumArea
. If the vertices can not be decomposed, the result will fall back to using the convex hull. The options parameter is an object that specifies any Matter.Body
properties you wish to override the defaults. See the properties section of the Matter.Body
module for detailed information on what you can pass via the options
object.
Parameters
x
Number
y
Number
[[vector]]
Objectoptional
vertexSets
[options]
Objectoptional
[flagInternal=false]
Booloptional
[removeCollinear=0.01]
Numberoptional
[minimumArea=10]
Numberoptional
Returns
Matter.Bodies.polygon
(x, y, sides, radius, [options])
→ Body
Creates a new rigid body model with a regular polygon hull with the given number of sides. The options parameter is an object that specifies any properties you wish to override the defaults. See the properties section of the Matter.Body
module for detailed information on what you can pass via the options
object.
Parameters
x
Number
y
Number
sides
Number
radius
Number
[options]
Objectoptional
Returns
BodyA new regular polygon body
Matter.Bodies.rectangle
(x, y, width, height, [options])
→ Body
Creates a new rigid body model with a rectangle hull. The options parameter is an object that specifies any properties you wish to override the defaults. See the properties section of the Matter.Body
module for detailed information on what you can pass via the options
object.
Parameters
x
Number
y
Number
width
Number
height
Number
[options]
Objectoptional
Returns
BodyA new rectangle body
Matter.Bodies.trapezoid
(x, y, width, height, slope, [options])
→ Body
Creates a new rigid body model with a trapezoid hull. The options parameter is an object that specifies any properties you wish to override the defaults. See the properties section of the Matter.Body
module for detailed information on what you can pass via the options
object.
Parameters
x
Number
y
Number
width
Number
height
Number
slope
Number
[options]
Objectoptional
Returns
BodyA new trapezoid body