Skip to content

Commit

Permalink
Phaser 2.1.3 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
photonstorm committed Oct 22, 2014
1 parent 1e1d1b9 commit 0e2378d
Show file tree
Hide file tree
Showing 13 changed files with 793 additions and 249 deletions.
181 changes: 145 additions & 36 deletions build/custom/phaser-arcade-physics.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* Phaser - http://phaser.io
*
* v2.1.3 "Ravinda" - Built: Wed Oct 22 2014 22:48:37
* v2.1.3 "Ravinda" - Built: Wed Oct 22 2014 23:49:48
*
* By Richard Davey http://www.photonstorm.com @photonstorm
*
Expand Down Expand Up @@ -153,6 +153,83 @@ PIXI.sayHello = function (type)
PIXI.dontSayHello = true;
};

/**
* @author Adrien Brault <[email protected]>
*/

/**
* @class Polygon
* @constructor
* @param points* {Array<Point>|Array<Number>|Point...|Number...} This can be an array of Points that form the polygon,
* a flat array of numbers that will be interpreted as [x,y, x,y, ...], or the arguments passed can be
* all the points of the polygon e.g. `new PIXI.Polygon(new PIXI.Point(), new PIXI.Point(), ...)`, or the
* arguments passed can be flat x,y values e.g. `new PIXI.Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are
* Numbers.
*/
PIXI.Polygon = function(points)
{
//if points isn't an array, use arguments as the array
if(!(points instanceof Array))points = Array.prototype.slice.call(arguments);

//if this is a flat array of numbers, convert it to points
if(points[0] instanceof PIXI.Point)
{
var p = [];
for(var i = 0, il = points.length; i < il; i++)
{
p.push(points[i].x, points[i].y);
}

points = p;
}

this.closed = true;
this.points = points;
};

/**
* Creates a clone of this polygon
*
* @method clone
* @return {Polygon} a copy of the polygon
*/
PIXI.Polygon.prototype.clone = function()
{
var points = this.points.slice();
return new PIXI.Polygon(points);
};

/**
* Checks whether the x and y coordinates passed to this function are contained within this polygon
*
* @method contains
* @param x {Number} The X coordinate of the point to test
* @param y {Number} The Y coordinate of the point to test
* @return {Boolean} Whether the x/y coordinates 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
var length = this.points.length / 2;

for(var i = 0, j = length - 1; i < length; j = i++)
{
var xi = this.points[i * 2], yi = this.points[i * 2 + 1],
xj = this.points[j * 2], yj = this.points[j * 2 + 1],
intersect = ((yi > y) !== (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);

if(intersect) inside = !inside;
}

return inside;
};

// constructor
PIXI.Polygon.prototype.constructor = PIXI.Polygon;

/**
* @author Mat Groves http://matgroves.com/ @Doormat23
*/
Expand Down Expand Up @@ -11477,7 +11554,7 @@ PIXI.AbstractFilter.prototype.apply = function(frameBuffer)
*
* Phaser - http://phaser.io
*
* v2.1.3 "Ravinda" - Built: Wed Oct 22 2014 22:48:37
* v2.1.3 "Ravinda" - Built: Wed Oct 22 2014 23:49:48
*
* By Richard Davey http://www.photonstorm.com @photonstorm
*
Expand Down Expand Up @@ -15272,13 +15349,39 @@ Phaser.Polygon = function (points) {
*/
this.type = Phaser.POLYGON;

// If points isn't an array, use arguments as the array
if (!(points instanceof Array))
{
points = Array.prototype.slice.call(arguments);
}

// If this is a flat array of numbers, convert it to points
if (points[0] instanceof Phaser.Point)
{
var p = [];

for (var i = 0, il = points.length; i < il; i++)
{
p.push(points[i].x, points[i].y);
}

points = p;
}

/**
* @property {array} points - An array of Points that make up this Polygon.
*/
this.points = points;

/**
* @property {boolean} closed - Is the Polygon closed or not?
*/
this.closed = true;

};

Phaser.Polygon.prototype = {

type: null,

/**
* Creates a copy of the given Polygon.
* This is a deep clone, the resulting copy contains new Phaser.Point objects
Expand All @@ -15289,12 +15392,7 @@ Phaser.Polygon.prototype = {
*/
clone: function (output) {

var points = [];

for (var i=0; i < this.points.length; i++)
{
points.push(this.points[i].clone());
}
var points = this.points.slice();

if (typeof output === "undefined" || output === null)
{
Expand Down Expand Up @@ -15322,12 +15420,15 @@ Phaser.Polygon.prototype = {
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 length = this.points.length / 2;

for (var i = 0, j = length - 1; i < length; j = i++)
{
var xi = this.points[i].x;
var yi = this.points[i].y;
var xj = this.points[j].x;
var yj = this.points[j].y;
var xi = this.points[i * 2].x;
var yi = this.points[i * 2 + 1].y;
var xj = this.points[j * 2].x;
var yj = this.points[j * 2 + 1].y;

var intersect = ((yi > y) !== (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);

Expand All @@ -15341,7 +15442,33 @@ Phaser.Polygon.prototype = {

},

setTo : function(points) {
/**
* Sets this Polygon to the given points.
*
* @method Phaser.Polygon#setTo
* @param {Phaser.Point[]|number[]} points - The array of Points.
* @return {boolean} True if the coordinates are within this polygon, otherwise false.
*/
setTo: function (points) {

// If points isn't an array, use arguments as the array
if (!(points instanceof Array))
{
points = Array.prototype.slice.call(arguments);
}

// If this is a flat array of numbers, convert it to points
if (points[0] instanceof Phaser.Point)
{
var p = [];

for (var i = 0, il = points.length; i < il; i++)
{
p.push(points[i].x, points[i].y);
}

points = p;
}

this.points = points;

Expand Down Expand Up @@ -15394,7 +15521,7 @@ Object.defineProperty(Phaser.Polygon.prototype, 'points', {
/**
* Returns the area of the polygon.
*
* @name Phaser.Circle#right
* @name Phaser.Polygon#area
* @readonly
*/
Object.defineProperty(Phaser.Polygon.prototype, 'area', {
Expand Down Expand Up @@ -15443,7 +15570,7 @@ Object.defineProperty(Phaser.Polygon.prototype, 'area', {
});

// Because PIXI uses its own Polygon, we'll replace it with ours to avoid duplicating code or confusion.
PIXI.Polygon = Phaser.Polygon;
// PIXI.Polygon = Phaser.Polygon;

/**
* @author Mat Groves http://matgroves.com/ @Doormat23
Expand Down Expand Up @@ -40312,24 +40439,6 @@ Phaser.Graphics.prototype.destroy = function(destroyChildren) {

};

/*
* Draws a {Phaser.Polygon} or a {PIXI.Polygon} filled
*
* @method Phaser.Graphics.prototype.drawPolygon
*/
Phaser.Graphics.prototype.drawPolygon = function (poly) {

this.moveTo(poly.points[0].x, poly.points[0].y);

for (var i = 1; i < poly.points.length; i += 1)
{
this.lineTo(poly.points[i].x, poly.points[i].y);
}

this.lineTo(poly.points[0].x, poly.points[0].y);

};

/*
* Draws a single {Phaser.Polygon} triangle from a {Phaser.Point} array
*
Expand Down
26 changes: 13 additions & 13 deletions build/custom/phaser-arcade-physics.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 0e2378d

Please sign in to comment.