Docs updated Builds updated
This commit is contained in:
parent
b1b2e417a3
commit
69b3be322e
93 changed files with 6214 additions and 1190 deletions
|
@ -53,12 +53,16 @@
|
|||
|
||||
<li><a href="../classes/CanvasRenderer.html">CanvasRenderer</a></li>
|
||||
|
||||
<li><a href="../classes/Circle.html">Circle</a></li>
|
||||
|
||||
<li><a href="../classes/CustomRenderable.html">CustomRenderable</a></li>
|
||||
|
||||
<li><a href="../classes/DisplayObject.html">DisplayObject</a></li>
|
||||
|
||||
<li><a href="../classes/DisplayObjectContainer.html">DisplayObjectContainer</a></li>
|
||||
|
||||
<li><a href="../classes/Ellipse.html">Ellipse</a></li>
|
||||
|
||||
<li><a href="../classes/Graphics.html">Graphics</a></li>
|
||||
|
||||
<li><a href="../classes/ImageLoader.html">ImageLoader</a></li>
|
||||
|
@ -149,10 +153,23 @@
|
|||
/**
|
||||
* @class Polygon
|
||||
* @constructor
|
||||
* @param points {Array}
|
||||
* @param points {Array<Point>|Array<Number>} This cna be an array of Points or a flat array of numbers
|
||||
* that will be interpreted as [x,y, x,y, ...]
|
||||
*/
|
||||
PIXI.Polygon = function(points)
|
||||
{
|
||||
//if this is a flat array of numbers, convert it to points
|
||||
if(typeof points[0] === 'number') {
|
||||
var p = [];
|
||||
for(var i = 0, il = points.length; i < il; i+=2) {
|
||||
p.push(
|
||||
new PIXI.Point(points[i], points[i + 1])
|
||||
);
|
||||
}
|
||||
|
||||
points = p;
|
||||
}
|
||||
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
|
@ -160,7 +177,7 @@ PIXI.Polygon = function(points)
|
|||
* @method clone
|
||||
* @return a copy of the polygon
|
||||
*/
|
||||
PIXI.Polygon.clone = function()
|
||||
PIXI.Polygon.prototype.clone = function()
|
||||
{
|
||||
var points = [];
|
||||
for (var i=0; i<this.points.length; i++) {
|
||||
|
@ -170,6 +187,29 @@ PIXI.Polygon.clone = function()
|
|||
return new PIXI.Polygon(points);
|
||||
}
|
||||
|
||||
/**
|
||||
* @method contains
|
||||
* @param x {Number} The X coord of the point to test
|
||||
* @param y {Number} The Y coord of the point to test
|
||||
* @return if the x/y coords are within this polygon
|
||||
*/
|
||||
PIXI.Polygon.prototype.contains = function(x, y)
|
||||
{
|
||||
var inside = false;
|
||||
|
||||
// use some raycasting to test hits
|
||||
// https://github.com/substack/point-in-polygon/blob/master/index.js
|
||||
for(var i = 0, j = this.points.length - 1; i < this.points.length; j = i++) {
|
||||
var xi = this.points[i].x, yi = this.points[i].y,
|
||||
xj = this.points[j].x, yj = this.points[j].y,
|
||||
intersect = ((yi > y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
|
||||
|
||||
if(intersect) inside = !inside;
|
||||
}
|
||||
|
||||
return inside;
|
||||
}
|
||||
|
||||
PIXI.Polygon.constructor = PIXI.Polygon;
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue