Triangle.js
Triangle ⇐ Impacto.GameObjects.GameObject2D
This class will draw a triangle on the canvas.
Kind: global class
Extends: Impacto.GameObjects.GameObject2D
Constructors:
- Triangle ⇐
Impacto.GameObjects.GameObject2D
- new Triangle(x, y, width, height, [fillColor], [strokeColor])
- .x
- .y
- .x ⇒
number
- .y ⇒
number
- .getTop() ⇒
number
- .getBottom() ⇒
number
- .getLeft() ⇒
number
- .getRight() ⇒
number
- .getCenterX() ⇒
number
- .getCenterY() ⇒
number
- .getRealTop() ⇒
number
- .getRealBottom() ⇒
number
- .getRealLeft() ⇒
number
- .getRealRight() ⇒
number
- .getRealCenterX() ⇒
number
- .getRealCenterY() ⇒
number
- .setWidth(width) ⇒
Triangle
- .setHeight(height) ⇒
Triangle
- .setSize(width, height) ⇒
Triangle
- .getArea() ⇒
number
- .getPerimeter() ⇒
number
- .getVertices() ⇒
Array.<Object>
new Triangle(x, y, width, height, [fillColor], [strokeColor])
Param | Type | Default | Description |
---|---|---|---|
x | number | The horizontal position of this Triangle in the world. | |
y | number | The vertical position of this Triangle in the world. | |
width | number | The width of this Triangle. | |
height | number | The height of this Triangle. | |
[fillColor] | number | string | 0xffffff | The color the Triangle will be filled with, i.e. 0xff0000 for red. |
[strokeColor] | number | string | 0x000000 | The color of the border of the Triangle, i.e. 0x00ff00 for green. |
Example
const myTriangle = new Impacto.GameObjects.Triangle(400, 300, 100, 100, "#ff0000", 0x00ff00);
Triangle.x
Sets the X position of the Triangle.
Kind: static property of Triangle
Param | Type | Description |
---|---|---|
x | number | The horizontal position of this Triangle in the world. |
Triangle.y
Sets the Y position of the Triangle.
Kind: static property of Triangle
Param | Type | Description |
---|---|---|
y | number | The vertical position of this Triangle in the world. |
Triangle.x ⇒ number
Kind: static property of Triangle
Returns: number
-
The horizontal position of this Triangle in the world relative to the origin.
Triangle.y ⇒ number
Kind: static property of Triangle
Returns: number
-
The vertical position of this Triangle in the world relative to the origin.
Triangle.getTop() ⇒ number
Returns the top side position of the triangle, based in the origin.
Kind: static method of Triangle
Returns: number
-
The topmost point of the triangle
Example
new Impacto.GameObjects.Triangle(400, 300, 100, 100).getTop(); // 300
Triangle.getBottom() ⇒ number
Returns the bottom side position of the triangle, based in the origin.
Kind: static method of Triangle
Returns: number
-
The bottommost point of the triangle
Example
new Impacto.GameObjects.Triangle(400, 300, 100, 100).getBottom(); // 400
Triangle.getLeft() ⇒ number
Returns the left side position of the triangle, based in the origin.
Kind: static method of Triangle
Returns: number
-
The leftmost point of the triangle
Example
new Impacto.GameObjects.Triangle(400, 300, 100, 100).getLeft(); // 400
Triangle.getRight() ⇒ number
Returns the right side position of the triangle, based in the origin.
Kind: static method of Triangle
Returns: number
-
The rightmost point of the triangle
Example
new Impacto.GameObjects.Triangle(400, 300, 100, 100).getRight(); // 500
Triangle.getCenterX() ⇒ number
Returns the center X position of the triangle, based in the origin.
Kind: static method of Triangle
Returns: number
-
The width of the triangle
Example
new Impacto.GameObjects.Triangle(400, 300, 100, 100).getCenterX(); // 450
Triangle.getCenterY() ⇒ number
Returns the center Y position of the triangle, based in the origin.
Kind: static method of Triangle
Returns: number
-
The height of the triangle
Example
new Impacto.GameObjects.Triangle(400, 300, 100, 100).getCenterY(); // 450
Triangle.getRealTop() ⇒ number
Returns the real top position of the triangle in the world.
Kind: static method of Triangle
Returns: number
-
The real top position of the triangle in the world
Example
new Impacto.GameObjects.Triangle(400, 300, 100, 100).getRealTop(); // 300
Triangle.getRealBottom() ⇒ number
Returns the real bottom position of the triangle in the world.
Kind: static method of Triangle
Returns: number
-
The real bottom position of the triangle in the world
Example
new Impacto.GameObjects.Triangle(400, 300, 100, 100).getRealBottom(); // 400
Triangle.getRealLeft() ⇒ number
Returns the real left position of the triangle in the world.
Kind: static method of Triangle
Returns: number
-
The real left position of the triangle in the world
Example
new Impacto.GameObjects.Triangle(400, 300, 100, 100).getRealLeft(); // 400
Triangle.getRealRight() ⇒ number
Returns the real right position of the triangle in the world.
Kind: static method of Triangle
Returns: number
-
The real right position of the triangle in the world
Example
new Impacto.GameObjects.Triangle(400, 300, 100, 100).getRealRight(); // 400
Triangle.getRealCenterX() ⇒ number
Returns the real center x position of the triangle in the world.
Kind: static method of Triangle
Returns: number
-
The real center position of the triangle in the world
Example
new Impacto.GameObjects.Triangle(400, 300, 100, 100).getRealCenterX(); // 450
Triangle.getRealCenterY() ⇒ number
Returns the real center y position of the triangle in the world.
Kind: static method of Triangle
Returns: number
-
The real center position of the triangle in the world
Example
new Impacto.GameObjects.Triangle(400, 300, 100, 100).getRealCenterY(); // 450
Triangle.setWidth(width) ⇒ Triangle
Change the width of the triangle.
Kind: static method of Triangle
Returns: Triangle
-
The triangle itself.
Param | Type | Description |
---|---|---|
width | number | The new width of the triangle. |
Example
new Impacto.GameObjects.Triangle(400, 300, 100, 100).setWidth(200); // 200
Triangle.setHeight(height) ⇒ Triangle
Change the height of the triangle.
Kind: static method of Triangle
Returns: Triangle
-
The triangle itself.
Param | Type | Description |
---|---|---|
height | number | The new height of the triangle. |
Example
new Impacto.GameObjects.Triangle(400, 300, 100, 100).setHeight(200); // 200
Triangle.setSize(width, height) ⇒ Triangle
Change the size of the triangle.
if the height is not defined, it will be the same as the width.
Kind: static method of Triangle
Returns: Triangle
-
The triangle itself.
Param | Type | Description |
---|---|---|
width | number | The new width of the triangle. |
height | number | The new height of the triangle. |
Example
new Impacto.GameObjects.Triangle(400, 300, 100, 100).setSize(200, 200); // 200, 200
Triangle.getArea() ⇒ number
Calculate the area of the triangle.
Kind: static method of Triangle
Returns: number
-
The area of the triangle.
Example
new Impacto.GameObjects.Triangle(400, 300, 100, 100).getArea(); // 5000
Triangle.getPerimeter() ⇒ number
Calculate the perimeter of the triangle.
Kind: static method of Triangle
Returns: number
-
The perimeter of the triangle.
Example
new Impacto.GameObjects.Triangle(400, 300, 100, 100).getPerimeter(); // 300
Triangle.getVertices() ⇒ Array.<Object>
Returns the triangle's vertices.
Kind: static method of Triangle
Returns: Array.<Object>
-
The triangle's vertices.
Example
new Impacto.GameObjects.Triangle(400, 300, 100, 100).getVertices(); // [
{"x": 100,"y": 100},
{"x": 200,"y": 100},
{"x": 150,"y": 200}]