Class: BoundingBox

BoundingBox(x, y, width, height)

Defines a rectanglular region in 2D space that can collide and detect collision Implements an Axis Aligned Bounding Box (AABB)

Constructor

new BoundingBox(x, y, width, height)

Creates a new bounding box
Parameters:
Name Type Description
x number The x position of the top left corner
y number The y position of the top left corner
width number The width of the box
height number The height of the box
Source:

Extends

Members

height

Get the height value
Source:

width

Get the width value
Source:

x

Gets the x coordinate of this point
Overrides:
Source:

y

Gets the x coordinate of this point
Overrides:
Source:

Methods

collides(box) → {boolean}

Performs a simple collision check on another boundingBox.
Parameters:
Name Type Description
box Object The BoundingBox to check for intersection
Source:
Returns:
true if colliding
Type
boolean

contains(box) → {boolean}

Checks the entire boundingBox passed is inside this one.
Parameters:
Name Type Description
box Object The box to check
Source:
Returns:
True/False whether the box passed is contained within this one
Type
boolean

copy(box)

Copies the values of another BoundingBox to this one
Parameters:
Name Type Description
box Object the BoundingBox to copy
Overrides:
Source:

distanceTo(point) → {number}

Calculates the distance between two points
Parameters:
Name Type Description
point Object The point to measure distance to
Overrides:
Source:
Returns:
The distance between this point and the one passed
Type
number

inBounds(x, y) → {boolean}

Checks whether the x,y coordinate passed is within the box boundary
Parameters:
Name Type Description
x number The x coordinate
y number The y coordinate
Source:
Returns:
true if the point is inside this box, otherwise false
Type
boolean

intersects(box) → {Object}

Performs a comprehensive collision test that checks where the two boxes are overlapping and indicates the closest point to move them out of collision.
Parameters:
Name Type Description
box Object The BoundingBox to check for intersection
Source:
Returns:
a dictionary with side: axis of intersection and pos: closest point of non-intersection
Type
Object

pointInBounds(point) → {boolean}

Checks whether the point is within the box boundary
Parameters:
Name Type Description
point Object The Point2D cordinates to check
Source:
Returns:
true if the point is inside this box, otherwise false
Type
boolean