intersects
shape collision / intersects library for pixi.js
rationale
this is a simple libary that i designed for use with my game engine. most of the better collision libraries were too large or too heavily invested in physics. i wanted something simple that worked well with pixi.js.
Code Example
// point-Rectangle intersection
var sprite = new PIXI.Sprite(texture);
sprite.shape = new Intersects.Rectangle(sprite);
sprite.position.set(5, 5);
if (sprite.shape.collidesPoint(new PIXI.Point(10, 10)))
{
console.log('intersected');
}
Live Example
https://davidfig.github.io/pixi-intersects/
Installation
npm i yy-intersects
API Reference
Classes
- Circle
circle shape
- Polygon
Polygon
- Rectangle
- Shape
base class of all shapes
Circle
circle shape
Kind: global class
*
Circle
* [new Circle(article, [options])](#new_Circle_new)
*
.set(options)
*
.update()
*
.collidesCircle(circle) ⇒
boolean
*
.collidesPoint(point) ⇒
boolean
*
.collidesLine(p1, p2) ⇒
boolean
*
.collidesRectangle(rectangle)
$3
| Param | Type | Description |
| --- | --- | --- |
| article |
Article | that uses this shape |
| [options] |
object | @see
Circle.set |
$3
Kind: instance method of
Circle
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| options |
object | | |
| [options.positionObject] |
object |
this.article | use this to update position |
| [options.radius] |
number | | otherwise article.width / 2 is used as radius |
$3
update AABB
Kind: instance method of
Circle
$3
Does Circle collide with Circle?
Kind: instance method of
Circle
| Param | Type |
| --- | --- |
| circle |
Circle |
$3
Does Circle collide with point?
Kind: instance method of
Circle
| Param | Type |
| --- | --- |
| point |
Point |
$3
Does Circle collide with a line?
from http://stackoverflow.com/a/10392860/1955997
Kind: instance method of
Circle
| Param | Type |
| --- | --- |
| p1 |
Point |
| p2 |
Point |
$3
Does circle collide with Rectangle?
Kind: instance method of
Circle
| Param | Type |
| --- | --- |
| rectangle |
Rectangle |
Polygon
Polygon
Kind: global class
*
Polygon
* [new Polygon(article, points, [options])](#new_Polygon_new)
*
.set(options)
*
.update()
*
.collidesRectangle(rectangle) ⇒
boolean
*
.collidesCircle(circle) ⇒
boolean
$3
| Param | Type | Description |
| --- | --- | --- |
| article |
Article | that uses this shape |
| points |
array | in the form of [x, y, x2, y2, x3, y3, . . .] |
| [options] |
object | @see
Polygon.set |
$3
Kind: instance method of
Polygon
| Param | Type | Description |
| --- | --- | --- |
| options |
object | |
| options.points |
Array.<PIXI.Point> | |
| [options.center] |
PIXI.DisplayObject | object to use for position (and rotation, unless separately defined) |
| [options.rotation] |
PIXI.DisplayObject | object to use for rotation instead of options.center or article |
$3
based on http://www.willperone.net/Code/coderr.php
Kind: instance method of
Polygon
$3
Does Rectangle collide Rectangle?
Kind: instance method of
Polygon
| Param | Type |
| --- | --- |
| rectangle |
Rectangle |
$3
Does Rectangle collide Circle?
Kind: instance method of
Polygon
| Param | Type |
| --- | --- |
| circle |
Circle |
Rectangle
Kind: global class
*
Rectangle
* [new Rectangle(article, [options])](#new_Rectangle_new)
*
.width
*
.height
*
.vertices
*
.set(options)
*
.update()
*
.updateVertices()
*
.collidesRectangle(rectangle) ⇒
boolean
*
.collidesCircle(circle) ⇒
boolean
$3
| Param | Type | Description |
| --- | --- | --- |
| article |
object | that uses this shape |
| [options] |
object | @see
Rectangle.set |
$3
width of rectangle
Kind: instance property of
Rectangle
$3
height of rectangle
Kind: instance property of
Rectangle
$3
sets vertices Array[8]
Kind: instance property of
Rectangle
$3
Kind: instance method of
Rectangle
| Param | Type | Description |
| --- | --- | --- |
| options |
object | |
| [options.width] |
number | width of object when aligned |
| [options.height] |
number | height of object when aligned |
| [options.square] |
number | side size of a square |
| [options.center] |
object | object to use for position (and rotation, unless separately defined) |
| [options.rotation] |
object | object to use for rotation instead of options.center or article |
| [options.noRotate] |
boolean | object does not rotate (simplifies math) |
$3
based on http://www.willperone.net/Code/coderr.php
update AABB and sets vertices to dirty
Kind: instance method of
Rectangle
$3
updates vertices automatically when dirty
Kind: instance method of
Rectangle
$3
Does Rectangle collide Rectangle?
Kind: instance method of
Rectangle
| Param | Type |
| --- | --- |
| rectangle |
Rectangle |
$3
Does Rectangle collide Circle?
Kind: instance method of
Rectangle
| Param | Type |
| --- | --- |
| circle |
Circle |
Shape
base class of all shapes
Kind: global class
*
Shape
* [new Shape([article])](#new_Shape_new)
* _instance_
*
.AABBs(AABB)
*
.collidesPoint(point) ⇒
boolean
*
.collidesPolygon(polygon, isAABB) ⇒
boolean
*
.collidesLine(p1, p2) ⇒
boolean
*
.collides()
* _static_
*
.lineLine(p1, p2, p3, p4) ⇒
boolean
$3
| Param | Type | Description |
| --- | --- | --- |
| [article] |
object | that uses this shape |
$3
collides with this shape's AABB box
Kind: instance method of
Shape
| Param | Type |
| --- | --- |
| AABB |
object |
$3
point-polygon collision test based on this.vertices
based on http://stackoverflow.com/questions/217578/how-can-i-determine-whether-a-2d-point-is-within-a-polygon/2922778#2922778
Kind: instance method of
Shape
| Param | Type |
| --- | --- |
| point |
Point |
$3
Does Polygon collide Polygon or AABB?
based on http://stackoverflow.com/questions/10962379/how-to-check-intersection-between-2-rotated-rectangles
Kind: instance method of
Shape
| Param | Type |
| --- | --- |
| polygon |
Array |
| isAABB |
boolean |
$3
Does polygon collide Line?
Kind: instance method of
Shape
| Param | Type |
| --- | --- |
| p1 |
Point |
| p2 |
Point |
$3
catch all for automatic collision checking
Kind: instance method of
Shape
$3
Do two lines intersect?
from http://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect
Kind: static method of
Shape
| Param | Type |
| --- | --- |
| p1 |
Point |
| p2 |
Point |
| p3 |
Point |
| p4 |
Point |
*
Copyright (c) 2016 YOPEY YOPEY LLC - MIT License - Documented by
jsdoc-to-markdown