Collisions
A collision system used to track bodies in order to improve collision detection performance
Static Method Summary
| Static Public Methods | ||
| public static |
Creates a Result used to collect the detailed results of a collision test |
|
Constructor Summary
| Public Constructor | ||
| public |
|
|
Method Summary
| Public Methods | ||
| public |
Determines if two bodies are colliding |
|
| public |
Creates a Circle and inserts it into the collision system |
|
| public |
createPoint(x: Number, y: Number, padding: Number): Point Creates a Point and inserts it into the collision system |
|
| public |
createPolygon(x: Number, y: Number, points: Array<Number[]>, angle: Number, scale_x: Number, scale_y: Number, padding: Number): Polygon Creates a Polygon and inserts it into the collision system |
|
| public |
Creates a Result used to collect the detailed results of a collision test |
|
| public |
draw(context: CanvasRenderingContext2D) Draws the bodies within the system to a CanvasRenderingContext2D's current path |
|
| public |
drawBVH(context: CanvasRenderingContext2D) Draws the system's BVH to a CanvasRenderingContext2D's current path. |
|
| public |
Inserts bodies into the collision system |
|
| public |
Returns a list of potential collisions for a body |
|
| public |
Removes bodies from the collision system |
|
| public |
update() Updates the collision system. |
|
Static Public Methods
public static createResult() source
Creates a Result used to collect the detailed results of a collision test
Public Constructors
public constructor() source
Public Methods
public collides(target: Circle | Polygon | Point, result: Result, aabb: Boolean): Boolean source
Determines if two bodies are colliding
Params:
| Name | Type | Attribute | Description |
| target | Circle | Polygon | Point | The target body to test against |
|
| result | Result |
|
A Result object on which to store information about the collision |
| aabb | Boolean |
|
Set to false to skip the AABB test (useful if you use your own potential collision heuristic) |
public createCircle(x: Number, y: Number, radius: Number, scale: Number, padding: Number): Circle source
Creates a Circle and inserts it into the collision system
Params:
| Name | Type | Attribute | Description |
| x | Number |
|
The starting X coordinate |
| y | Number |
|
The starting Y coordinate |
| radius | Number |
|
The radius |
| scale | Number |
|
The scale |
| padding | Number |
|
The amount to pad the bounding volume when testing for potential collisions |
public createPoint(x: Number, y: Number, padding: Number): Point source
Creates a Point and inserts it into the collision system
public createPolygon(x: Number, y: Number, points: Array<Number[]>, angle: Number, scale_x: Number, scale_y: Number, padding: Number): Polygon source
Creates a Polygon and inserts it into the collision system
Params:
| Name | Type | Attribute | Description |
| x | Number |
|
The starting X coordinate |
| y | Number |
|
The starting Y coordinate |
| points | Array<Number[]> |
|
An array of coordinate pairs making up the polygon - [[x1, y1], [x2, y2], ...] |
| angle | Number |
|
The starting rotation in radians |
| scale_x | Number |
|
The starting scale along the X axis |
| scale_y | Number |
|
The starting scale long the Y axis |
| padding | Number |
|
The amount to pad the bounding volume when testing for potential collisions |
public createResult() source
Creates a Result used to collect the detailed results of a collision test
public draw(context: CanvasRenderingContext2D) source
Draws the bodies within the system to a CanvasRenderingContext2D's current path
Params:
| Name | Type | Attribute | Description |
| context | CanvasRenderingContext2D | The context to draw to |
public drawBVH(context: CanvasRenderingContext2D) source
Draws the system's BVH to a CanvasRenderingContext2D's current path. This is useful for testing out different padding values for bodies.
Params:
| Name | Type | Attribute | Description |
| context | CanvasRenderingContext2D | The context to draw to |
public insert(bodies: ...Circle | ...Polygon | ...Point) source
Inserts bodies into the collision system
public potentials(body: Circle | Polygon | Point): Array<Body> source
Returns a list of potential collisions for a body
public remove(bodies: ...Circle | ...Polygon | ...Point) source
Removes bodies from the collision system
public update() source
Updates the collision system. This should be called before any collisions are tested.
