Rectangle.js
Rectangle ⇐ Impacto.GameObjects.GameObject2D
The Rectangle Shape is a 2D Game Object that can be added to a Scene. Its possible to set a rounder corner radius.
Kind: global class
Extends: Impacto.GameObjects.GameObject2D
Constructors:
- Rectangle ⇐
Impacto.GameObjects.GameObject2D
- new Rectangle(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) ⇒
Rectangle
- .setHeight(height) ⇒
Rectangle
- .setSize(width, height) ⇒
Rectangle
- .refresh(x, y, width, height) ⇒
Rectangle
- .setRound(topLeft, topRight, bottomLeft, bottomRight) ⇒
Rectangle
- .getBounds() ⇒
Object
- .getArea() ⇒
number
- .getPerimeter() ⇒
number
- .getVertices() ⇒
Array
new Rectangle(x, y, [width], [height], [fillColor], [strokeColor])
Param | Type | Default | Description |
---|---|---|---|
x | number | The horizontal position of this Rectangle in the world. | |
y | number | The vertical position of this Rectangle in the world. | |
[width] | number | 100 | The width of the rectangle. |
[height] | number | 100 | The height of the rectangle. |
[fillColor] | number | string | 0xffffff | The color the rectangle will be filled with, i.e. 0xff0000 for red. |
[strokeColor] | number | string | 0x000000 | The color of the border of the rectangle, i.e. 0x00ff00 for green. |
Example
const rect = new Impacto.GameObjects.Rectangle(400, 300, 75, 50, "#ff0000", 0x00ff00);
Rectangle.x
Sets the X position of the rectangle.
Kind: static property of Rectangle
Param | Type | Description |
---|---|---|
x | number | The horizontal position of this Rectangle in the world. |
Rectangle.y
Gets the Y position of the rectangle.
Kind: static property of Rectangle
Param | Type | Description |
---|---|---|
y | number | The vertical position of this Rectangle in the world. |
Rectangle.x ⇒ number
Kind: static property of Rectangle
Returns: number
-
The horizontal position of this Rectangle in the world relative to the origin.
Rectangle.y ⇒ number
Kind: static property of Rectangle
Returns: number
-
The vertical position of this Rectangle in the world relative to the origin.
Rectangle.getTop() ⇒ number
Returns the top side position of the rectangle.
Kind: static method of Rectangle
Returns: number
-
The vertical position of this Rectangle in the world relative to the origin.
Rectangle.getBottom() ⇒ number
Returns the bottom side position of the rectangle.
Kind: static method of Rectangle
Returns: number
-
The vertical position of this Rectangle in the world relative to the origin.
Rectangle.getLeft() ⇒ number
Returns the left side position of the rectangle.
Kind: static method of Rectangle
Returns: number
-
The horizontal position of this Rectangle in the world relative to the origin.
Rectangle.getRight() ⇒ number
Returns the right side position of the rectangle.
Kind: static method of Rectangle
Returns: number
-
The horizontal position of this Rectangle in the world relative to the origin.
Rectangle.getCenterX() ⇒ number
Returns the center X position of the rectangle.
Kind: static method of Rectangle
Returns: number
-
The horizontal position of this Rectangle in the world relative to the origin.
Example
new Impacto.GameObjects.Rectangle(10, 10, 100, 100).setOrigin(0.5).getCenterX(); // 27.5
Rectangle.getCenterY() ⇒ number
Returns the center Y position of the rectangle.
Kind: static method of Rectangle
Returns: number
-
The vertical position of this Rectangle in the world relative to the origin.
Example
new Impacto.GameObjects.Rectangle(10, 10, 100, 100).setOrigin(0.5).getCenterY(); // 27.5
Rectangle.getRealTop() ⇒ number
Returns the real top side position of the rectangle. (Not relative to the origin)
Kind: static method of Rectangle
Returns: number
-
The real vertical position of this Rectangle in the world.
Example
new Impacto.GameObjects.Rectangle(10, 10, 100, 100).getRealTop(); // 10
Rectangle.getRealBottom() ⇒ number
Returns the real bottom side position of the rectangle. (Not relative to the origin)
Kind: static method of Rectangle
Returns: number
-
The real vertical position of this Rectangle in the world.
Example
new Impacto.GameObjects.Rectangle(10, 10, 100, 100).getRealBottom(); // 110
Rectangle.getRealLeft() ⇒ number
Returns the real left side position of the rectangle. (Not relative to the origin)
Kind: static method of Rectangle
Returns: number
-
The real horizontal position of this Rectangle in the world.
Example
new Impacto.GameObjects.Rectangle(10, 10, 100, 100).getRealLeft(); // 10
Rectangle.getRealRight() ⇒ number
Returns the real right side position of the rectangle. (Not relative to the origin)
Kind: static method of Rectangle
Returns: number
-
The real horizontal position of this Rectangle in the world.
Example
new Impacto.GameObjects.Rectangle(10, 10, 100, 100).getRealRight(); // 110
Rectangle.getRealCenterX() ⇒ number
Returns the real center X position of the rectangle. (Not relative to the origin)
Kind: static method of Rectangle
Returns: number
-
The real horizontal position of this Rectangle in the world.
Example
new Impacto.GameObjects.Rectangle(10, 10, 100, 100).getRealCenterX(); // 55
Rectangle.getRealCenterY() ⇒ number
Returns the real center Y position of the rectangle. (Not relative to the origin)
Kind: static method of Rectangle
Returns: number
-
The real vertical position of this Rectangle in the world.
Example
new Impacto.GameObjects.Rectangle(10, 10, 100, 100).getRealCenterY(); // 55
Rectangle.setWidth(width) ⇒ Rectangle
Sets the width of the rectangle.
Kind: static method of Rectangle
Returns: Rectangle
-
This Rectangle.
Param | Type | Description |
---|---|---|
width | number | The new width of this Rectangle. |
Example
new Impacto.GameObjects.Rectangle(10, 10, 100, 100).setWidth(200);
Rectangle.setHeight(height) ⇒ Rectangle
Sets the height of the rectangle.
Kind: static method of Rectangle
Returns: Rectangle
-
This Rectangle.
Param | Type | Description |
---|---|---|
height | number | The new height of this Rectangle. |
Example
new Impacto.GameObjects.Rectangle(10, 10, 100, 100).setHeight(200);
Rectangle.setSize(width, height) ⇒ Rectangle
Sets the size of the rectangle.
Kind: static method of Rectangle
Returns: Rectangle
-
This Rectangle.
Param | Type | Description |
---|---|---|
width | number | The new width of this Rectangle. |
height | number | The new height of this Rectangle. |
Example
new Impacto.GameObjects.Rectangle(10, 10, 100, 100).setSize(50, 50);
Rectangle.refresh(x, y, width, height) ⇒ Rectangle
Sets the position and size of the rectangle.
Kind: static method of Rectangle
Returns: Rectangle
-
This Rectangle.
Param | Type | Description |
---|---|---|
x | number | The new horizontal position of this Rectangle. |
y | number | The new vertical position of this Rectangle. |
width | number | The new width of this Rectangle. |
height | number | The new height of this Rectangle. |
Example
new Impacto.GameObjects.Rectangle(10, 10, 100, 100).setPositionAndSize(20, 30, 50, 75);
Rectangle.setRound(topLeft, topRight, bottomLeft, bottomRight) ⇒ Rectangle
Sets the roundedness of the rectangle.
Kind: static method of Rectangle
Returns: Rectangle
-
This Rectangle.
Param | Type | Default | Description |
---|---|---|---|
topLeft | number | 0 | The new roundedness of the top left corner. |
topRight | number | The new roundedness of the top right corner. | |
bottomLeft | number | The new roundedness of the bottom left corner. | |
bottomRight | number | The new roundedness of the bottom right corner. |
Example
new Impacto.GameObjects.Rectangle(10, 10).setRoundedness(10);
Rectangle.getBounds() ⇒ Object
Gets the bounding box of this Rectangle.
Kind: static method of Rectangle
Returns: Object
-
The bounding box of this Rectangle.
Example
new Impacto.GameObjects.Rectangle(0, 0).getBoundingBox(); // { x: 0, y: 0, width: 100, height: 100 }
Rectangle.getArea() ⇒ number
Gets the area of this Rectangle.
Kind: static method of Rectangle
Returns: number
-
The area of this Rectangle.
Read only: true
Example
new Impacto.GameObjects.Rectangle(0, 0, 100, 100).getArea(); // 10000
Rectangle.getPerimeter() ⇒ number
Gets the perimeter of this Rectangle.
Kind: static method of Rectangle
Returns: number
-
The perimeter of this Rectangle.
Read only: true
Example
new Impacto.GameObjects.Rectangle(0, 0, 100, 100).getPerimeter(); // 200
Rectangle.getVertices() ⇒ Array
Gets the point of all vertices of this Rectangle.
Kind: static method of Rectangle
Returns: Array
-
All vertices of this Rectangle.
Read only: true
Example
new Impacto.GameObjects.Rectangle(0, 0, 100, 100).getVertices(); // [{ x: 0, y: 0 }, { x: 100, y: 0 }, { x: 100, y: 100 }, { x: 0, y: 100 }]