shape collision / intersects library for pixi.js
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.
// 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');
}
https://davidfig.github.io/intersects/
npm i yy-intersects
circle shape
Kind: global class
Param | Type | Description |
---|---|---|
article | Article |
that uses this shape |
[options] | object |
@see Circle.set |
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 |
update AABB
Kind: instance method of Circle
Does Circle collide with Circle?
Kind: instance method of Circle
Param | Type |
---|---|
circle | Circle |
Does Circle collide with point?
Kind: instance method of Circle
Param | Type |
---|---|
point | Point |
Does Circle collide with a line? from http://stackoverflow.com/a/10392860/1955997
Kind: instance method of Circle
Param | Type |
---|---|
p1 | Point |
p2 | Point |
Does circle collide with Rectangle?
Kind: instance method of Circle
Param | Type |
---|---|
rectangle | Rectangle |
Polygon
Kind: global class
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 |
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 |
based on http://www.willperone.net/Code/coderr.php
Kind: instance method of Polygon
Does Rectangle collide Rectangle?
Kind: instance method of Polygon
Param | Type |
---|---|
rectangle | Rectangle |
Does Rectangle collide Circle?
Kind: instance method of Polygon
Param | Type |
---|---|
circle | Circle |
Kind: global class
Param | Type | Description |
---|---|---|
article | object |
that uses this shape |
[options] | object |
@see Rectangle.set |
width of rectangle
Kind: instance property of Rectangle
height of rectangle
Kind: instance property of Rectangle
sets vertices Array[8]
Kind: instance property of Rectangle
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) |
based on http://www.willperone.net/Code/coderr.php update AABB and sets vertices to dirty
Kind: instance method of Rectangle
updates vertices automatically when dirty
Kind: instance method of Rectangle
Does Rectangle collide Rectangle?
Kind: instance method of Rectangle
Param | Type |
---|---|
rectangle | Rectangle |
Does Rectangle collide Circle?
Kind: instance method of Rectangle
Param | Type |
---|---|
circle | Circle |
base class of all shapes
Kind: global class
- Shape
- new Shape([article])
- instance
- .AABBs(AABB)
- .collidesPoint(point) ⇒
boolean
- .collidesPolygon(polygon, isAABB) ⇒
boolean
- .collidesLine(p1, p2) ⇒
boolean
- .collides()
- static
- .lineLine(p1, p2, p3, p4) ⇒
boolean
- .lineLine(p1, p2, p3, p4) ⇒
Param | Type | Description |
---|---|---|
[article] | object |
that uses this shape |
collides with this shape's AABB box
Kind: instance method of Shape
Param | Type |
---|---|
AABB | object |
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 |
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 |
Does polygon collide Line?
Kind: instance method of Shape
Param | Type |
---|---|
p1 | Point |
p2 | Point |
catch all for automatic collision checking
Kind: instance method of Shape
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