Rectangle

A rectangle shape

Constructor

new Rectangle(x, y, width, height)

Parameters:
NameTypeDescription
xnumber

The x position

ynumber

The y position

widthnumber

The rectangle width

heightnumber

The rectangle height

Extends

Members

copy

Create a copy of the shape

fillColor :String

The fill color when this shape is drawn

Type:
  • String

height :Number

The height of the rectangle (alias of Rectangle.size.y)

Type:
  • Number

position :gameify.Vector2d

The position of the shape, often locked to the position of a sprite that it represents

size :gameify.Vector2d

The size (width and height) of the rectangle

strokeColor :String

The stroke color when this shape is drawn

Type:
  • String

(readonly) type :String

A string represeting the type of shape, eg "Circle"

Type:
  • String

width :Number

The width of the rectangle (alias of Rectangle.size.x)

Type:
  • Number

Methods

collidesWith(obj, recursionopt) → {Boolean}

Check if this shape collides with another shape

Parameters:
NameTypeAttributesDefaultDescription
objshapes.Shape

The object to check for collision

recursionBoolean<optional>
false

If this is a recursive call

Returns:
Type: 
Boolean

contains(point) → {Boolean}

Check if a point (Vector2d) is inside this shape

Parameters:
NameTypeDescription
pointgameify.Vector2d

The point to check

Returns:
Type: 
Boolean

draw(context)

Draw a hitbox for debugging

Parameters:
NameTypeDescription
contextCanvasRenderingContext2D

The rendering context to draw to

fromJSON(data) → {gameify.Tileset}

Creates a object from JSON data

Parameters:
NameTypeDescription
dataObject | Array

Serialized object data (from object.toJSON)

Returns:
Type: 
gameify.Tileset

rotated(angle, pointopt) → {gameify.shapes.Polygon}

Create a copy of this shape, rotated around a point, in radians (counterclockwise)

Parameters:
NameTypeAttributesDefaultDescription
angleNumber

The angle to rotate by, in radians

pointgameify.Vector2d<optional>
<0, 0>

The point to rotate around

Returns:

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

Parameters:
NameTypeDescription
scaleNumber

The scale factor

toJSON()

Convert the object to JSON