PolygonOptions to initialize the polygon with
used for state() and returnState(), builds states that are returnable. Stacking two states is destructive.
List of objects that block this object
List of objects that this object blocks
reference to the physics body (matter.js). Empty if physics is not enabled
how the object is bounded in the scene (set with scene.setBoundaries())
are the bounds active on this object?
true if the polygon is convex, false otherwise
coordinates of the polygon, or the top left most point of the polygon
Game object options of the game object (for serialization and recreation)
hitbox of the polygon, if the polygon is a square
unique ID for each object
True if the object is the local player, false otherwise
Meta data of the object
boolean if physics is enabled on the object
options for the physics engine
Reference point to pin the object to (only applies if the object is pinned)
does nothing!
points of the polygon
true if the polygon is a square, false otherwise
type of the object, either "gameObject", "sprite", or "polygon"
Applies a force to the object (only works if physics enabled)
The force vector to apply to the object
Checks for a collision with another object
The object to check for a collision with
Boolean, true of the object is colliding with the other object, false otherwise
Checks for a collision with a polygon
The polygon (lower case, not type Polygon) to check for a collision with
Boolean, true of the object is colliding with the other object, false otherwise
Draws the polygon onto the provided drawing context. This is handled automatically with scene and scene managers
The DrawOptions for the object
Draws the object's label on top of the object The label is the objects meta label (eg: object.meta.label = "...")
The DrawOptions for the object
Moves the polygon
The vector to move the polygon by
Boolean, true if the move was successful, false if it was not (if it was out of bounds, it will not move)
Moves an object that has physics enabled by a vector (no forces pr boundaries involved)
The vector to move the object by
Whether the object was moved or not (if it was out of bounds, it will not move)
Moves the polygon to a point as apposed to moving it by a vector
The point in space to move the polygon to
True
Modifies pin to a game object
The game object to pin to
The reference point to pin to (either "center" or "coordinates")
Returns the object as a JSON object
The object as a JSON object
Sets the hitbox of the polygon. Useful if the polygon is concave and you need more reliable collision detection.
The width of the hitbox
The height of the hitbox
const polygon = new Polygon({
points: [[0, 0], [0, 100], [100, 100], [100, 0]],
backgroundColor: "red"
});
polygon.setHitBox(polygon.getWidth(), polygon.getHeight());
Static
FromGenerated using TypeDoc
Classdesc
Polygon class, used for rendering polygons
Example