Polygon.js
Polygon ⇐ Impacto.GameObjects.GameObject2D
This class will draw a polygon on the canvas.
Kind: global class
Extends: Impacto.GameObjects.GameObject2D
Constructors:
- Polygon ⇐
Impacto.GameObjects.GameObject2D- new Polygon(x, y, vertices, [fillColor], [strokeColor])
- .x
- .y
- .x ⇒
number - .y ⇒
number - .width ⇒
number - .height ⇒
number - .getTop() ⇒
number - .getBottom() ⇒
number - .getLeft() ⇒
number - .getRight() ⇒
number - .getCenterX() ⇒
number - .getCenterY() ⇒
number - .getCenter() ⇒
Object - .add(x, y) ⇒
Polygon - .remove(x, y) ⇒
Polygon - .removePoint(point) ⇒
Polygon - .removeIndex(index) ⇒
Polygon - .setClose(close) ⇒
Polygon - .getBounds() ⇒
Object - .getVertices() ⇒
Array.<Object>
new Polygon(x, y, vertices, [fillColor], [strokeColor])
| Param | Type | Default | Description |
|---|---|---|---|
| x | number | The horizontal position of this Polygon in the world. | |
| y | number | The vertical position of this Polygon in the world. | |
| vertices | vertices | The vertices of this Polygon. | |
| [fillColor] | number | string | 0xffffff | The color the Polygon will be filled with, i.e. 0xff0000 for red. |
| [strokeColor] | number | string | 0x000000 | The color of the border of the Polygon, i.e. 0x00ff00 for green. |
Example
const myPolygon = new Impacto.GameObjects.Polygon(400, 300, [10, 10, 20, 20, 10, 20], "#ff0000", 0x00ff00);
Polygon.x
Sets the X position of the Polygon.
Kind: static property of Polygon
| Param | Type | Description |
|---|---|---|
| x | number | The horizontal position of this Polygon in the world. |
Polygon.y
Sets the Y position of the Polygon.
Kind: static property of Polygon
| Param | Type | Description |
|---|---|---|
| y | number | The vertical position of this Polygon in the world. |
Polygon.x ⇒ number
Kind: static property of Polygon
Returns: number -
The horizontal position of this Polygon in the world relative to the origin.
Polygon.y ⇒ number
Kind: static property of Polygon
Returns: number -
The vertical position of this Polygon in the world relative to the origin.
Polygon.width ⇒ number
Kind: static property of Polygon
Returns: number -
The width of this Polygon.
Polygon.height ⇒ number
Kind: static property of Polygon
Returns: number -
The height of this Polygon.
Polygon.getTop() ⇒ number
Returns the topmost point of the polygon
Kind: static method of Polygon
Returns: number -
The topmost point of the polygon
Example
new Impacto.GameObjects.Polygon(400, 300, [10, 10, 20, 20, 10, 20]).getTop(); // 10
Polygon.getBottom() ⇒ number
Returns the bottommost point of the polygon
Kind: static method of Polygon
Returns: number -
The bottommost point of the polygon
Example
new Impacto.GameObjects.Polygon(400, 300, [10, 10, 20, 20, 10, 20]).getBottom(); // 20
Polygon.getLeft() ⇒ number
Returns the leftmost point of the polygon
Kind: static method of Polygon
Returns: number -
The leftmost point of the polygon
Example
new Impacto.GameObjects.Polygon(400, 300, [10, 10, 20, 20, 10, 20]).getLeft(); // 10
Polygon.getRight() ⇒ number
Returns the rightmost point of the polygon
Kind: static method of Polygon
Returns: number -
The rightmost point of the polygon
Example
new Impacto.GameObjects.Polygon(400, 300, [10, 10, 20, 20, 10, 20]).getRight(); // 20
Polygon.getCenterX() ⇒ number
Returns the horizontal center of the polygon
Kind: static method of Polygon
Returns: number -
The horizontal center of the polygon
Example
new Impacto.GameObjects.Polygon(400, 300, [10, 10, 20, 20, 10, 20]).getCenterX(); // 15
Polygon.getCenterY() ⇒ number
Returns the vertical center of the polygon
Kind: static method of Polygon
Returns: number -
The vertical center of the polygon
Example
new Impacto.GameObjects.Polygon(400, 300, [10, 10, 20, 20, 10, 20]).getCenterY(); // 15
Polygon.getCenter() ⇒ Object
Returns the center of the polygon
Kind: static method of Polygon
Returns: Object -
The center of the polygon
Example
new Impacto.GameObjects.Polygon(400, 300, [10, 10, 20, 20, 10, 20]).getCenter(); // {x: 15, y: 15}
Polygon.add(x, y) ⇒ Polygon
Add a new point to the polygon
Kind: static method of Polygon
Returns: Polygon -
The polygon itself
| Param | Type | Description |
|---|---|---|
| x | number | The x coordinate of the point |
| y | number | The y coordinate of the point |
Example
new Impacto.GameObjects.Polygon(400, 300, [10, 10, 20, 20, 10, 20]).addPoint(0, 0);
Polygon.remove(x, y) ⇒ Polygon
Remove a point from the polygon based in the coordinates
Kind: static method of Polygon
Returns: Polygon -
The polygon itself
| Param | Type | Description |
|---|---|---|
| x | number | The x coordinate of the point |
| y | number | The y coordinate of the point |
Example
new Impacto.GameObjects.Polygon(400, 300, [10, 10, 20, 20, 10, 20]).removePoint(10, 10);
Polygon.removePoint(point) ⇒ Polygon
Remove a point from the polygon based in the object
Kind: static method of Polygon
Returns: Polygon -
The polygon itself
| Param | Type | Description |
|---|---|---|
| point | Object | The point to be removed |
Example
new Impacto.GameObjects.Polygon(400, 300, [10, 10, 20, 20, 10, 20]).removePoint({x: 10, y: 10});
Polygon.removeIndex(index) ⇒ Polygon
Remove a point from the polygon based in the index
Kind: static method of Polygon
Returns: Polygon -
The polygon itself
| Param | Type | Description |
|---|---|---|
| index | number | The index of the point |
Example
new Impacto.GameObjects.Polygon(400, 300, [10, 10, 20, 20, 10, 20]).removeIndex(0);
Polygon.setClose(close) ⇒ Polygon
Close the last point to the first point
Kind: static method of Polygon
Returns: Polygon -
The polygon itself
| Param | Type | Description |
|---|---|---|
| close | boolean | Whether the polygon should be closed or not |
Example
new Impacto.GameObjects.Polygon(400, 300, [10, 10, 20, 20, 10, 20]).setClose(true);
Polygon.getBounds() ⇒ Object
Returns bounds of the polygon (the most top left and the most bottom right points)
Kind: static method of Polygon
Returns: Object -
The bounds of the polygon
Example
new Impacto.GameObjects.Polygon(400, 300, [10, 10, 20, 20, 10, 20]).getBounds(); // {x: 10, y: 10, width: 20, height: 20}
Polygon.getVertices() ⇒ Array.<Object>
Returns the vertices of the polygon
Kind: static method of Polygon
Returns: Array.<Object> -
The vertices of the polygon
Example
new Impacto.GameObjects.Polygon(400, 300, [10, 10, 20, 20, 10, 20]).getVertices(); // [{x: 10, y: 10}, {x: 20, y: 20}, {x: 10, y: 20}]