1.0.8 • Published 3 years ago

yy-intersects v1.0.8

Weekly downloads
28
License
MIT
Repository
github
Last release
3 years ago

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

Kind: global class

new Circle(article, options)

ParamTypeDescription
articleArticlethat uses this shape
optionsobject@see Circle.set

circle.set(options)

Kind: instance method of Circle

ParamTypeDefaultDescription
optionsobject
options.positionObjectobjectthis.articleuse this to update position
options.radiusnumberotherwise 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

ParamType
circleCircle

circle.collidesPoint(point) ⇒ boolean

Does Circle collide with point?

Kind: instance method of Circle

ParamType
pointPoint

circle.collidesLine(p1, p2) ⇒ boolean

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

Kind: instance method of Circle

ParamType
p1Point
p2Point

circle.collidesRectangle(rectangle)

Does circle collide with Rectangle?

Kind: instance method of Circle

ParamType
rectangleRectangle

Polygon

Polygon

Kind: global class

new Polygon(article, points, options)

ParamTypeDescription
articleArticlethat uses this shape
pointsarrayin the form of x, y, x2, y2, x3, y3, . . .
optionsobject@see Polygon.set

polygon.set(options)

Kind: instance method of Polygon

ParamTypeDescription
optionsobject
options.pointsArray.<PIXI.Point>
options.centerPIXI.DisplayObjectobject to use for position (and rotation, unless separately defined)
options.rotationPIXI.DisplayObjectobject 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

ParamType
rectangleRectangle

polygon.collidesCircle(circle) ⇒ boolean

Does Rectangle collide Circle?

Kind: instance method of Polygon

ParamType
circleCircle

Rectangle

Kind: global class

new Rectangle(article, options)

ParamTypeDescription
articleobjectthat uses this shape
optionsobject@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 Array8

Kind: instance property of Rectangle

rectangle.set(options)

Kind: instance method of Rectangle

ParamTypeDescription
optionsobject
options.widthnumberwidth of object when aligned
options.heightnumberheight of object when aligned
options.squarenumberside size of a square
options.centerobjectobject to use for position (and rotation, unless separately defined)
options.rotationobjectobject to use for rotation instead of options.center or article
options.noRotatebooleanobject 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

ParamType
rectangleRectangle

rectangle.collidesCircle(circle) ⇒ boolean

Does Rectangle collide Circle?

Kind: instance method of Rectangle

ParamType
circleCircle

Shape

base class of all shapes

Kind: global class

new Shape(article)

ParamTypeDescription
articleobjectthat uses this shape

shape.AABBs(AABB)

collides with this shape's AABB box

Kind: instance method of Shape

ParamType
AABBobject

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

ParamType
pointPoint

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

ParamType
polygonArray
isAABBboolean

shape.collidesLine(p1, p2) ⇒ boolean

Does polygon collide Line?

Kind: instance method of Shape

ParamType
p1Point
p2Point

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

ParamType
p1Point
p2Point
p3Point
p4Point

Copyright (c) 2016 YOPEY YOPEY LLC - MIT License - Documented by jsdoc-to-markdown

1.0.8

3 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago