Class: Rectangle

Rectangle(x, y, width, height)

A Rectangle has a size (width and height) and a position (x, y).
The position is stored as a Vector so it can easily be synchronized with the position of a Sprite.

Constructor

new Rectangle(x, y, width, height)

Set initial center position (x, y) and size (width and height).
Parameters:
Name Type Default Description
x number 0 x coordinate of the top-left corner
y number 0 y coordinate of the top-left corner
width number 0 width: the length in the x-direction
height number 0 height: the length in the y-direction
Source:

Methods

overlaps(other) → {boolean}

Determine if this rectangle overlaps another rectangle (includes overlapping edges).
Parameters:
Name Type Description
other Rectangle rectangle to check for overlap with
Source:
Returns:
true if this rectangle overlaps other rectangle, false otherwise
Type
boolean

setPosition(x, y)

Set new center position (x, y).
Parameters:
Name Type Description
x number x coordinate of the top-left corner
y number y coordinate of the top-left corner
Source:

setSize(width, height)

Set new size (width and height).
Parameters:
Name Type Description
width number width: the length in the x-direction
height number height: the length in the y-direction
Source:

setValues(x, y, width, height)

Set new center position (x, y) and new size (width and height).
Parameters:
Name Type Description
x number x coordinate of the top-left corner
y number y coordinate of the top-left corner
width number width: the length in the x-direction
height number height: the length in the y-direction
Source: