Constructor
new Rectangle(x, y, width, height)
| Name | Type | Description |
|---|---|---|
x | number | The x position |
y | number | The y position |
width | number | The rectangle width |
height | number | The rectangle height |
- Source
Extends
Members
copy
Create a copy of the shape
- Overrides
- Source
fillColor :String
The fill color when this shape is drawn
- String
- Overrides
- Source
height :Number
The height of the rectangle (alias of Rectangle.size.y)
- Number
- Source
position :gameify.Vector2d
The position of the shape, often locked to the position of a sprite that it represents
- Overrides
- Source
size :gameify.Vector2d
The size (width and height) of the rectangle
- Source
strokeColor :String
The stroke color when this shape is drawn
- String
- Overrides
- Source
(readonly) type :String
A string represeting the type of shape, eg "Circle"
- String
- Overrides
- Source
width :Number
The width of the rectangle (alias of Rectangle.size.x)
- Number
- Source
Methods
collidesWith(obj, recursionopt) → {Boolean}
Check if this shape collides with another shape
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
obj | shapes. | The object to check for collision | ||
recursion | Boolean | <optional> | false | If this is a recursive call |
- Overrides
- Source
- Type:
- Boolean
contains(point) → {Boolean}
Check if a point (Vector2d) is inside this shape
| Name | Type | Description |
|---|---|---|
point | gameify. | The point to check |
- Overrides
- Source
- Type:
- Boolean
draw(context)
Draw a hitbox for debugging
| Name | Type | Description |
|---|---|---|
context | CanvasRenderingContext2D | The rendering context to draw to |
- Overrides
- Source
fromJSON(data) → {gameify.Tileset}
Creates a object from JSON data
| Name | Type | Description |
|---|---|---|
data | Object | | Serialized object data (from object.toJSON) |
- Overrides
- Source
- Type:
- gameify.
Tileset
rotated(angle, pointopt) → {gameify.shapes.Polygon}
Create a copy of this shape, rotated around a point, in radians (counterclockwise)
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
angle | Number | The angle to rotate by, in radians | ||
point | gameify. | <optional> | <0, 0> | The point to rotate around |
- Overrides
- Source
Because Rectangles must be axis-aligned
- Type:
- gameify.
shapes. Polygon
scaled(scale) → {gameify.shapes.Rectangle}
Create a copy of this shape, scaled by a factor
| Name | Type | Description |
|---|---|---|
scale | Number | The scale factor |
- Overrides
- Source
- Type:
- gameify.
shapes. Rectangle
toJSON()
Convert the object to JSON
- Overrides
- Source