CollisionSystem

CollisionSystem

wrapper for detect-collisions

Constructor

new CollisionSystem()

Source:
See:
Example
import { Box } from "detect-collisions";

let s = new CollisionSystem();

//inserting a new game object
let a = {pos: { x: 0, y: 0 }};
a.physicsBody = new Box(a.pos, 10, 10);
a.physicsBody.gameObj = a;

s.insert(a.physicsBody);

//handle and resolve collisions
s.handleCollisions();

Members

(readonly) bodies

Source:

Methods

addRectangle(r, collide_layers, collide_with) → {Body}

Source:

Add a rectangle

Parameters:
Name Type Description
r Rectangle
collide_layers Array.<Number>

Layers this body is a member of

collide_with Array.<Number>

layers this body collides with

Returns:
Type
Body

cleanup()

Source:

remove all bodies

getOverlapping(b, check_layersopt) → {Array.<Body>}

Source:

get all overlapping bodies

Parameters:
Name Type Attributes Default Description
b Body
check_layers boolean <optional>
false
Returns:
Type
Array.<Body>

handleCollisions()

Source:

check collisions in the system and resolve them.

This assumes the bodies have a gameObj property with a vector pos, a vector v

insert(body) → {Body}

Source:
Parameters:
Name Type Description
body Óbject

detect-collisions body

Returns:
Type
Body

update()

Source:

update the physics bodies and handle collisions