Constructor
# new PolygonFromPoints(world, attributes, optionsopt)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
world |
world | The Matter.js world object | |
attributes |
object | Visual properties e.g. position, points and color | |
options |
object |
<optional> |
Defines the behaviour e.g. mass, bouncyness or whether it can move |
- Source:
- Tutorials:
-
- Tutorial: XX - Benno Step 7 Open example , open code
Example
const points = [
{ x: 0, y: 0 },
{ x: 20, y: 10 },
{ x: 200, y: 30 },
{ x: 220, y: 50 },
{ x: 10, y: 20 }
]
const attributes = {
x: 600,
y: 580,
points: points,
color: "olive"
}
const options = {
isStatic: true
}
let polygonBlock = new PolygonFromPoints(world, attributes, options)
Extends
Members
# constraints :Array.<Matter.Constraint>
Type:
- Array.<Matter.Constraint>
- Overrides:
Methods
# collideWith(block)
Adds a block to an internal collisions array, to check whether this block colides with another block
Parameters:
Name | Type | Description |
---|---|---|
block |
Block |
- Overrides:
# constrainTo(block, optionsopt) → {Matter.Constraint}
Constrains this block to another block.
Constraints are used for specifying that a fixed distance must be maintained between two blocks (or a block and a fixed world-space position).
The stiffness of constraints can be modified via the options to create springs or elastic.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
block |
Block | ||
options |
Matter.IConstraintDefinition |
<optional> |
- Overrides:
Returns:
- Type
- Matter.Constraint
# draw()
Draws the matter body to the p5 canvas
- Overrides:
- Source:
# drawSprite()
Draw an image "sprite" instead of the shape of the block.
Make sure to set attributes.image so that there is an image to draw.
- Overrides:
# drawVertices(vertices)
Parameters:
Name | Type | Description |
---|---|---|
vertices |
Array.<Matter.Vector> |
- Overrides:
- Source:
# offsetMassCentre(block, offset)
Sets the mass centre of the block to a specific offset
the offset is relative to the current mass centre
Parameters:
Name | Type | Description |
---|---|---|
block |
Block | |
offset |
Matter.Vector |
- Overrides:
# removeConstraint(constraint)
Remove a constraint of this block to another block.
Parameters:
Name | Type | Description |
---|---|---|
constraint |
Matter.Constraint |
- Overrides:
# rotate(rotation, pointopt, updateVelocityopt)
Rotates the block to a specific angle (absolute)
set the angle of the block to the given angle
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
rotation |
number | The angle in radians | |
point |
Matter.Vector |
<optional> |
The point to rotate around |
updateVelocity |
boolean |
<optional> |
Whether to update the velocity of the block |
- Overrides:
Example
// Rotate the block to 45 degrees
block.rotate(PI / 4)
// Rotate the block to 45 degrees around a specific point
block.rotate(PI / 4, { x: 100, y: 100 })
// Rotate the block to 45 degrees around a specific point and update the velocity
block.rotate(PI / 4, { x: 100, y: 100 }, true)
// Rotate the block to 45 degrees around a specific point and update the velocity
block.rotate(PI / 4, { x: 100, y: 100 }, true)
# rotateBy(rotation, pointopt, updateVelocityopt)
Rotates the block by a specific angle (relative)
adds the angle to the current angle of the block
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
rotation |
number | The angle in radians | |
point |
Matter.Vector |
<optional> |
The point to rotate around |
updateVelocity |
boolean |
<optional> |
Whether to update the velocity of the block |
- Overrides:
Example
// Increments the rotation of the block by 1 degrees
block.rotateBy(PI / 180)
// Increments the rotation of the block by 1 degrees around a specific point
block.rotateBy(PI / 180, { x: 100, y: 100 })