Skip to content

davidfig/pixi-intersects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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/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

new Circle(article, [options])

Param Type Description
article Article that uses this shape
[options] object @see Circle.set

circle.set(options)

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

circle.update()

update AABB

Kind: instance method of Circle

circle.collidesCircle(circle) ⇒ boolean

Does Circle collide with Circle?

Kind: instance method of Circle

Param Type
circle Circle

circle.collidesPoint(point) ⇒ boolean

Does Circle collide with point?

Kind: instance method of Circle

Param Type
point Point

circle.collidesLine(p1, p2) ⇒ boolean

Does Circle collide with a line? from http://stackoverflow.com/a/10392860/1955997

Kind: instance method of Circle

Param Type
p1 Point
p2 Point

circle.collidesRectangle(rectangle)

Does circle collide with Rectangle?

Kind: instance method of Circle

Param Type
rectangle Rectangle

Polygon

Polygon

Kind: global class

new Polygon(article, points, [options])

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

polygon.set(options)

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

polygon.update()

based on http://www.willperone.net/Code/coderr.php

Kind: instance method of Polygon

polygon.collidesRectangle(rectangle) ⇒ boolean

Does Rectangle collide Rectangle?

Kind: instance method of Polygon

Param Type
rectangle Rectangle

polygon.collidesCircle(circle) ⇒ boolean

Does Rectangle collide Circle?

Kind: instance method of Polygon

Param Type
circle Circle

Rectangle

Kind: global class

new Rectangle(article, [options])

Param Type Description
article object that uses this shape
[options] object @see Rectangle.set

rectangle.width

width of rectangle

Kind: instance property of Rectangle

rectangle.height

height of rectangle

Kind: instance property of Rectangle

rectangle.vertices

sets vertices Array[8]

Kind: instance property of Rectangle

rectangle.set(options)

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)

rectangle.update()

based on http://www.willperone.net/Code/coderr.php update AABB and sets vertices to dirty

Kind: instance method of Rectangle

rectangle.updateVertices()

updates vertices automatically when dirty

Kind: instance method of Rectangle

rectangle.collidesRectangle(rectangle) ⇒ boolean

Does Rectangle collide Rectangle?

Kind: instance method of Rectangle

Param Type
rectangle Rectangle

rectangle.collidesCircle(circle) ⇒ boolean

Does Rectangle collide Circle?

Kind: instance method of Rectangle

Param Type
circle Circle

Shape

base class of all shapes

Kind: global class

new Shape([article])

Param Type Description
[article] object that uses this shape

shape.AABBs(AABB)

collides with this shape's AABB box

Kind: instance method of Shape

Param Type
AABB object

shape.collidesPoint(point) ⇒ boolean

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

shape.collidesPolygon(polygon, isAABB) ⇒ boolean

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

shape.collidesLine(p1, p2) ⇒ boolean

Does polygon collide Line?

Kind: instance method of Shape

Param Type
p1 Point
p2 Point

shape.collides()

catch all for automatic collision checking

Kind: instance method of Shape

Shape.lineLine(p1, p2, p3, p4) ⇒ boolean

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

About

shape collision / intersects library for pixi.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published