+
@@ -436,6 +488,7 @@ Object.defineProperty(Phaser.Animation.prototype, "paused", {
/**
* @name Phaser.Animation#frameTotal
* @property {number} frameTotal - The total number of frames in the currently loaded FrameData, or -1 if no FrameData is loaded.
+* @readonly
*/
Object.defineProperty(Phaser.Animation.prototype, "frameTotal", {
@@ -538,7 +591,7 @@ Phaser.Animation.generateFrameNames = function (prefix, min, max, suffix, zeroPa
Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 02 2013 01:51:37 GMT+0100 (BST) using the DocStrap template.
+ on Wed Oct 02 2013 12:09:54 GMT+0100 (BST) using the DocStrap template.
diff --git a/Docs/out/AnimationManager.js.html b/Docs/out/AnimationManager.js.html
index 986ad3a5..90563ccb 100644
--- a/Docs/out/AnimationManager.js.html
+++ b/Docs/out/AnimationManager.js.html
@@ -32,6 +32,10 @@
Phaser
+
/**
+* @author Richard Davey <rich@photonstorm.com>
+* @copyright 2013 Photon Storm Ltd.
+* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
+*/
+
+/**
+* Creates a new Circle object with the center coordinate specified by the x and y parameters and the diameter specified by the diameter parameter. If you call this function without parameters, a circle with x, y, diameter and radius properties set to 0 is created.
+* @class Circle
+* @classdesc Phaser - Circle
+* @constructor
+* @param {number} [x] The x coordinate of the center of the circle.
+* @param {number} [y] The y coordinate of the center of the circle.
+* @param {number} [diameter] The diameter of the circle.
+* @return {Phaser.Circle} This circle object
+**/
+Phaser.Circle = function (x, y, diameter) {
+
+ x = x || 0;
+ y = y || 0;
+ diameter = diameter || 0;
+
+ /**
+ * @property {number} x - The x coordinate of the center of the circle.
+ **/
+ this.x = x;
+
+ /**
+ * @property {number} y - The y coordinate of the center of the circle.
+ **/
+ this.y = y;
+
+ /**
+ * @property {number} _diameter - The diameter of the circle.
+ * @private
+ **/
+ this._diameter = diameter;
+
+ if (diameter > 0)
+ {
+ /**
+ * @property {number} _radius - The radius of the circle.
+ * @private
+ **/
+ this._radius = diameter * 0.5;
+ }
+ else
+ {
+ this._radius = 0;
+ }
+
+};
+
+Phaser.Circle.prototype = {
+
+ /**
+ * The circumference of the circle.
+ * @method Phaser.Circle#circumference
+ * @return {number}
+ **/
+ circumference: function () {
+ return 2 * (Math.PI * this._radius);
+ },
+
+ /**
+ * Sets the members of Circle to the specified values.
+ * @method Phaser.Circle#setTo
+ * @param {number} x - The x coordinate of the center of the circle.
+ * @param {number} y - The y coordinate of the center of the circle.
+ * @param {number} diameter - The diameter of the circle in pixels.
+ * @return {Circle} This circle object.
+ **/
+ setTo: function (x, y, diameter) {
+ this.x = x;
+ this.y = y;
+ this._diameter = diameter;
+ this._radius = diameter * 0.5;
+ return this;
+ },
+
+ /**
+ * Copies the x, y and diameter properties from any given object to this Circle.
+ * @method Phaser.Circle#copyFrom
+ * @param {any} source - The object to copy from.
+ * @return {Circle} This Circle object.
+ **/
+ copyFrom: function (source) {
+ return this.setTo(source.x, source.y, source.diameter);
+ },
+
+ /**
+ * Copies the x, y and diameter properties from this Circle to any given object.
+ * @method Phaser.Circle#copyTo
+ * @param {any} dest - The object to copy to.
+ * @return {Object} This dest object.
+ **/
+ copyTo: function(dest) {
+ dest[x] = this.x;
+ dest[y] = this.y;
+ dest[diameter] = this._diameter;
+ return dest;
+ },
+
+ /**
+ * Returns the distance from the center of the Circle object to the given object
+ * (can be Circle, Point or anything with x/y properties)
+ * @method Phaser.Circle#distance
+ * @param {object} dest - The target object. Must have visible x and y properties that represent the center of the object.
+ * @param {boolean} [round] - Round the distance to the nearest integer (default false).
+ * @return {number} The distance between this Point object and the destination Point object.
+ */
+ distance: function (dest, round) {
+
+ if (typeof round === "undefined") { round = false }
+
+ if (round)
+ {
+ return Phaser.Math.distanceRound(this.x, this.y, dest.x, dest.y);
+ }
+ else
+ {
+ return Phaser.Math.distance(this.x, this.y, dest.x, dest.y);
+ }
+
+ },
+
+ /**
+ * Returns a new Circle object with the same values for the x, y, width, and height properties as this Circle object.
+ * @method Phaser.Circle#clone
+ * @param {Phaser.Circle} out - Optional Circle object. If given the values will be set into the object, otherwise a brand new Circle object will be created and returned.
+ * @return {Phaser.Circle} The cloned Circle object.
+ */
+ clone: function(out) {
+
+ if (typeof out === "undefined") { out = new Phaser.Circle(); }
+
+ return out.setTo(a.x, a.y, a.diameter);
+
+ },
+
+ /**
+ * Return true if the given x/y coordinates are within this Circle object.
+ * @method Phaser.Circle#contains
+ * @param {number} x - The X value of the coordinate to test.
+ * @param {number} y - The Y value of the coordinate to test.
+ * @return {boolean} True if the coordinates are within this circle, otherwise false.
+ */
+ contains: function (x, y) {
+ return Phaser.Circle.contains(this, x, y);
+ },
+
+ /**
+ * Returns a Point object containing the coordinates of a point on the circumference of the Circle based on the given angle.
+ * @method Phaser.Circle#circumferencePoint
+ * @param {number} angle - The angle in radians (unless asDegrees is true) to return the point from.
+ * @param {boolean} asDegrees - Is the given angle in radians (false) or degrees (true)?
+ * @param {Phaser.Point} [out] - An optional Point object to put the result in to. If none specified a new Point object will be created.
+ * @return {Phaser.Point} The Point object holding the result.
+ */
+ circumferencePoint: function (angle, asDegrees, out) {
+ return Phaser.Circle.circumferencePoint(this, angle, asDegrees, out);
+ },
+
+ /**
+ * Adjusts the location of the Circle object, as determined by its center coordinate, by the specified amounts.
+ * @method Phaser.Circle#offset
+ * @param {number} dx - Moves the x value of the Circle object by this amount.
+ * @param {number} dy - Moves the y value of the Circle object by this amount.
+ * @return {Circle} This Circle object.
+ **/
+ offset: function (dx, dy) {
+ this.x += dx;
+ this.y += dy;
+ return this;
+ },
+
+ /**
+ * Adjusts the location of the Circle object using a Point object as a parameter. This method is similar to the Circle.offset() method, except that it takes a Point object as a parameter.
+ * @method Phaser.Circle#offsetPoint
+ * @param {Point} point A Point object to use to offset this Circle object (or any valid object with exposed x and y properties).
+ * @return {Circle} This Circle object.
+ **/
+ offsetPoint: function (point) {
+ return this.offset(point.x, point.y);
+ },
+
+ /**
+ * Returns a string representation of this object.
+ * @method Phaser.Circle#toString
+ * @return {string} a string representation of the instance.
+ **/
+ toString: function () {
+ return "[{Phaser.Circle (x=" + this.x + " y=" + this.y + " diameter=" + this.diameter + " radius=" + this.radius + ")}]";
+ }
+
+};
+
+/**
+* The largest distance between any two points on the circle. The same as the radius * 2.
+* @name Phaser.Circle#diameter
+* @property {number} diameter - Gets or sets the diameter of the circle.
+*/
+Object.defineProperty(Phaser.Circle.prototype, "diameter", {
+
+ get: function () {
+ return this._diameter;
+ },
+
+ set: function (value) {
+ if (value > 0) {
+ this._diameter = value;
+ this._radius = value * 0.5;
+ }
+ }
+
+});
+
+/**
+* The length of a line extending from the center of the circle to any point on the circle itself. The same as half the diameter.
+* @name Phaser.Circle#radius
+* @property {number} radius - Gets or sets the radius of the circle.
+*/
+Object.defineProperty(Phaser.Circle.prototype, "radius", {
+
+ get: function () {
+ return this._radius;
+ },
+
+ set: function (value) {
+ if (value > 0) {
+ this._radius = value;
+ this._diameter = value * 2;
+ }
+ }
+
+});
+
+/**
+* The x coordinate of the leftmost point of the circle. Changing the left property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property.
+* @name Phaser.Circle#left
+* @propety {number} left - Gets or sets the value of the leftmost point of the circle.
+*/
+Object.defineProperty(Phaser.Circle.prototype, "left", {
+
+ get: function () {
+ return this.x - this._radius;
+ },
+
+ set: function (value) {
+ if (value > this.x) {
+ this._radius = 0;
+ this._diameter = 0;
+ } else {
+ this.radius = this.x - value;
+ }
+ }
+
+});
+
+/**
+* The x coordinate of the rightmost point of the circle. Changing the right property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property.
+* @name Phaser.Circle#right
+* @property {number} right - Gets or sets the value of the rightmost point of the circle.
+*/
+Object.defineProperty(Phaser.Circle.prototype, "right", {
+
+ get: function () {
+ return this.x + this._radius;
+ },
+
+ set: function (value) {
+ if (value < this.x) {
+ this._radius = 0;
+ this._diameter = 0;
+ } else {
+ this.radius = value - this.x;
+ }
+ }
+
+});
+
+/**
+* The sum of the y minus the radius property. Changing the top property of a Circle object has no effect on the x and y properties, but does change the diameter.
+* @name Phaser.Circle#top
+* @property {number} top - Gets or sets the top of the circle.
+*/
+Object.defineProperty(Phaser.Circle.prototype, "top", {
+
+ get: function () {
+ return this.y - this._radius;
+ },
+
+ set: function (value) {
+ if (value > this.y) {
+ this._radius = 0;
+ this._diameter = 0;
+ } else {
+ this.radius = this.y - value;
+ }
+ }
+
+});
+
+/**
+* The sum of the y and radius properties. Changing the bottom property of a Circle object has no effect on the x and y properties, but does change the diameter.
+* @name Phaser.Circle#bottom
+* @property {number} bottom - Gets or sets the bottom of the circle.
+*/
+Object.defineProperty(Phaser.Circle.prototype, "bottom", {
+
+ get: function () {
+ return this.y + this._radius;
+ },
+
+ set: function (value) {
+
+ if (value < this.y) {
+ this._radius = 0;
+ this._diameter = 0;
+ } else {
+ this.radius = value - this.y;
+ }
+ }
+
+});
+
+/**
+* The area of this Circle.
+* @name Phaser.Circle#area
+* @property {number} area - The area of this circle.
+* @readonly
+*/
+Object.defineProperty(Phaser.Circle.prototype, "area", {
+
+ get: function () {
+ if (this._radius > 0) {
+ return Math.PI * this._radius * this._radius;
+ } else {
+ return 0;
+ }
+ }
+
+});
+
+/**
+* Determines whether or not this Circle object is empty. Will return a value of true if the Circle objects diameter is less than or equal to 0; otherwise false.
+* If set to true it will reset all of the Circle objects properties to 0. A Circle object is empty if its diameter is less than or equal to 0.
+* @name Phaser.Circle#empty
+* @property {boolean} empty - Gets or sets the empty state of the circle.
+*/
+Object.defineProperty(Phaser.Circle.prototype, "empty", {
+
+ get: function () {
+ return (this._diameter == 0);
+ },
+
+ set: function (value) {
+ this.setTo(0, 0, 0);
+ }
+
+});
+
+/**
+* Return true if the given x/y coordinates are within the Circle object.
+* @method Phaser.Circle.contains
+* @param {Phaser.Circle} a - The Circle to be checked.
+* @param {number} x - The X value of the coordinate to test.
+* @param {number} y - The Y value of the coordinate to test.
+* @return {boolean} True if the coordinates are within this circle, otherwise false.
+*/
+Phaser.Circle.contains = function (a, x, y) {
+
+ // Check if x/y are within the bounds first
+ if (x >= a.left && x <= a.right && y >= a.top && y <= a.bottom) {
+
+ var dx = (a.x - x) * (a.x - x);
+ var dy = (a.y - y) * (a.y - y);
+
+ return (dx + dy) <= (a.radius * a.radius);
+
+ }
+
+ return false;
+
+};
+
+/**
+* Determines whether the two Circle objects match. This method compares the x, y and diameter properties.
+* @method Phaser.Circle.equals
+* @param {Phaser.Circle} a - The first Circle object.
+* @param {Phaser.Circle} b - The second Circle object.
+* @return {boolean} A value of true if the object has exactly the same values for the x, y and diameter properties as this Circle object; otherwise false.
+*/
+Phaser.Circle.equals = function (a, b) {
+ return (a.x == b.x && a.y == b.y && a.diameter == b.diameter);
+};
+
+/**
+* Determines whether the two Circle objects intersect.
+* This method checks the radius distances between the two Circle objects to see if they intersect.
+* @method Phaser.Circle.intersects
+* @param {Phaser.Circle} a - The first Circle object.
+* @param {Phaser.Circle} b - The second Circle object.
+* @return {boolean} A value of true if the specified object intersects with this Circle object; otherwise false.
+*/
+Phaser.Circle.intersects = function (a, b) {
+ return (Phaser.Math.distance(a.x, a.y, b.x, b.y) <= (a.radius + b.radius));
+};
+
+/**
+* Returns a Point object containing the coordinates of a point on the circumference of the Circle based on the given angle.
+* @method Phaser.Circle.circumferencePoint
+* @param {Phaser.Circle} a - The first Circle object.
+* @param {number} angle - The angle in radians (unless asDegrees is true) to return the point from.
+* @param {boolean} asDegrees - Is the given angle in radians (false) or degrees (true)?
+* @param {Phaser.Point} [out] - An optional Point object to put the result in to. If none specified a new Point object will be created.
+* @return {Phaser.Point} The Point object holding the result.
+*/
+Phaser.Circle.circumferencePoint = function (a, angle, asDegrees, out) {
+
+ if (typeof asDegrees === "undefined") { asDegrees = false; }
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+
+ if (asDegrees === true) {
+ angle = Phaser.Math.radToDeg(angle);
+ }
+
+ out.x = a.x + a.radius * Math.cos(angle);
+ out.y = a.y + a.radius * Math.sin(angle);
+
+ return out;
+
+};
+
+/**
+* Checks if the given Circle and Rectangle objects intersect.
+* @method Phaser.Circle.intersectsRectangle
+* @param {Phaser.Circle} c - The Circle object to test.
+* @param {Phaser.Rectangle} r - The Rectangle object to test.
+* @return {boolean} True if the two objects intersect, otherwise false.
+*/
+Phaser.Circle.intersectsRectangle = function (c, r) {
+
+ var cx = Math.abs(c.x - r.x - r.halfWidth);
+ var xDist = r.halfWidth + c.radius;
+
+ if (cx > xDist) {
+ return false;
+ }
+
+ var cy = Math.abs(c.y - r.y - r.halfHeight);
+ var yDist = r.halfHeight + c.radius;
+
+ if (cy > yDist) {
+ return false;
+ }
+
+ if (cx <= r.halfWidth || cy <= r.halfHeight) {
+ return true;
+ }
+
+ var xCornerDist = cx - r.halfWidth;
+ var yCornerDist = cy - r.halfHeight;
+ var xCornerDistSq = xCornerDist * xCornerDist;
+ var yCornerDistSq = yCornerDist * yCornerDist;
+ var maxCornerDistSq = c.radius * c.radius;
+
+ return xCornerDistSq + yCornerDistSq <= maxCornerDistSq;
+
+};
+
/**
+* @author Richard Davey <rich@photonstorm.com>
+* @copyright 2013 Photon Storm Ltd.
+* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
+*/
+
+/**
+* A basic linked list data structure.
+*
+* @class Phaser.LinkedList
+* @constructor
+*/
+Phaser.LinkedList = function () {
+
+ /**
+ * @property {object} next - Next element in the list.
+ * @default
+ */
+ this.next = null;
+
+ /**
+ * @property {object} prev - Previous element in the list.
+ * @default
+ */
+ this.prev = null;
+
+ /**
+ * @property {object} first - First element in the list.
+ * @default
+ */
+ this.first = null;
+
+ /**
+ * @property {object} last - Last element in the list.
+ * @default
+ */
+ this.last = null;
+
+ /**
+ * @property {object} game - Number of elements in the list.
+ * @default
+ */
+ this.total = 0;
+
+};
+
+Phaser.LinkedList.prototype = {
+
+ /**
+ * Adds a new element to this linked list.
+ *
+ * @method Phaser.LinkedList#add
+ * @param {object} child - The element to add to this list. Can be a Phaser.Sprite or any other object you need to quickly iterate through.
+ * @return {object} The child that was added.
+ */
+ add: function (child) {
+
+ // If the list is empty
+ if (this.total == 0 && this.first == null && this.last == null)
+ {
+ this.first = child;
+ this.last = child;
+ this.next = child;
+ child.prev = this;
+ this.total++;
+ return child;
+ }
+
+ // Get gets appended to the end of the list, regardless of anything, and it won't have any children of its own (non-nested list)
+ this.last.next = child;
+
+ child.prev = this.last;
+
+ this.last = child;
+
+ this.total++;
+
+ return child;
+
+ },
+
+ /**
+ * Removes the given element from this linked list if it exists.
+ *
+ * @method Phaser.LinkedList#remove
+ * @param {object} child - The child to be removed from the list.
+ */
+ remove: function (child) {
+
+ if (child == this.first)
+ {
+ // It was 'first', make 'first' point to first.next
+ this.first = this.first.next;
+ }
+ else if (child == this.last)
+ {
+ // It was 'last', make 'last' point to last.prev
+ this.last = this.last.prev;
+ }
+
+ if (child.prev)
+ {
+ // make child.prev.next point to childs.next instead of child
+ child.prev.next = child.next;
+ }
+
+ if (child.next)
+ {
+ // make child.next.prev point to child.prev instead of child
+ child.next.prev = child.prev;
+ }
+
+ child.next = child.prev = null;
+
+ if (this.first == null )
+ {
+ this.last = null;
+ }
+
+ this.total--;
+
+ },
+
+ /**
+ * Calls a function on all members of this list, using the member as the context for the callback.
+ * The function must exist on the member.
+ *
+ * @method Phaser.LinkedList#callAll
+ * @param {function} callback - The function to call.
+ */
+ callAll: function (callback) {
+
+ if (!this.first || !this.last)
+ {
+ return;
+ }
+
+ var entity = this.first;
+
+ do
+ {
+ if (entity && entity[callback])
+ {
+ entity[callback].call(entity);
+ }
+
+ entity = entity.next;
+
+ }
+ while(entity != this.last.next)
+
+ }
+
+};
@@ -1575,7 +1627,7 @@ The frames are returned in the output array, or if none is provided in a new Arr
Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 02 2013 01:51:38 GMT+0100 (BST) using the DocStrap template.
+ on Wed Oct 02 2013 12:09:54 GMT+0100 (BST) using the DocStrap template.
diff --git a/Docs/out/Phaser.Animation.Parser.html b/Docs/out/Phaser.Animation.Parser.html
index cfe17a43..3580f6d5 100644
--- a/Docs/out/Phaser.Animation.Parser.html
+++ b/Docs/out/Phaser.Animation.Parser.html
@@ -32,6 +32,10 @@
Phaser
+
@@ -2459,7 +2511,7 @@ You could use this function to generate those by doing: Phaser.Animation.generat
Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 02 2013 01:51:38 GMT+0100 (BST) using the DocStrap template.
+ on Wed Oct 02 2013 12:09:54 GMT+0100 (BST) using the DocStrap template.
diff --git a/Docs/out/Phaser.AnimationManager.html b/Docs/out/Phaser.AnimationManager.html
index abbd306d..6c1f7ad9 100644
--- a/Docs/out/Phaser.AnimationManager.html
+++ b/Docs/out/Phaser.AnimationManager.html
@@ -32,6 +32,10 @@
Phaser
+
@@ -2283,7 +2335,7 @@ The currentAnim property of the AnimationManager is automatically set to the ani
Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 02 2013 01:51:38 GMT+0100 (BST) using the DocStrap template.
+ on Wed Oct 02 2013 12:09:54 GMT+0100 (BST) using the DocStrap template.
diff --git a/Docs/out/Phaser.Camera.html b/Docs/out/Phaser.Camera.html
index a6e429bd..5a83e805 100644
--- a/Docs/out/Phaser.Camera.html
+++ b/Docs/out/Phaser.Camera.html
@@ -32,6 +32,10 @@
Phaser
+
+
@@ -747,7 +799,7 @@ The game automatically creates a single Stage sized camera on boot. Move the cam
-Phaser.Rectangle
+Phaser.Rectangle
@@ -1162,7 +1214,7 @@ The game automatically creates a single Stage sized camera on boot. Move the cam
-Phaser.Rectangle
+Phaser.Rectangle
@@ -1376,7 +1428,7 @@ Objects outside of this view are not rendered (unless set to ignore the Camera,
-Phaser.Rectangle
+Phaser.Rectangle
@@ -1689,7 +1741,7 @@ Objects outside of this view are not rendered (unless set to ignore the Camera,
-Phaser.World
+Phaser.World
@@ -2710,7 +2762,7 @@ without having to use game.camera.x and game.camera.y.
Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 02 2013 01:51:38 GMT+0100 (BST) using the DocStrap template.
+ on Wed Oct 02 2013 12:09:54 GMT+0100 (BST) using the DocStrap template.
diff --git a/Docs/out/Phaser.Circle.html b/Docs/out/Phaser.Circle.html
new file mode 100644
index 00000000..4ebbc588
--- /dev/null
+++ b/Docs/out/Phaser.Circle.html
@@ -0,0 +1,4059 @@
+
+
+
+
+
+ Phaser Class: Circle
+
+
+
+
+
+
+
+
+
+
+
Creates a new Circle object with the center coordinate specified by the x and y parameters and the diameter specified by the diameter parameter. If you call this function without parameters, a circle with x, y, diameter and radius properties set to 0 is created.
The sum of the y and radius properties. Changing the bottom property of a Circle object has no effect on the x and y properties, but does change the diameter.
Determines whether or not this Circle object is empty. Will return a value of true if the Circle objects diameter is less than or equal to 0; otherwise false.
+If set to true it will reset all of the Circle objects properties to 0. A Circle object is empty if its diameter is less than or equal to 0.
The x coordinate of the leftmost point of the circle. Changing the left property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property.
The x coordinate of the rightmost point of the circle. Changing the right property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property.
+
+
+
+
+
+
+
+
+
+
Properties:
+
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
+
+
+
Description
+
+
+
+
+
+
+
+
+
right
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
Gets or sets the value of the rightmost point of the circle.
The sum of the y minus the radius property. Changing the top property of a Circle object has no effect on the x and y properties, but does change the diameter.
Adjusts the location of the Circle object using a Point object as a parameter. This method is similar to the Circle.offset() method, except that it takes a Point object as a parameter.
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
+
+
+
Description
+
+
+
+
+
+
+
+
+
point
+
+
+
+
+
+Point
+
+
+
+
+
+
+
+
+
+
A Point object to use to offset this Circle object (or any valid object with exposed x and y properties).
+
@@ -3043,7 +3095,7 @@ When a game is paused the onPause event is dispatched. When it is resumed the on
-Phaser.Stage
+Phaser.Stage
@@ -3664,7 +3716,7 @@ When a game is paused the onPause event is dispatched. When it is resumed the on
-Phaser.World
+Phaser.World
@@ -4147,7 +4199,7 @@ When a game is paused the onPause event is dispatched. When it is resumed the on
Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 02 2013 01:51:38 GMT+0100 (BST) using the DocStrap template.
+ on Wed Oct 02 2013 12:09:54 GMT+0100 (BST) using the DocStrap template.
diff --git a/Docs/out/Phaser.Group.html b/Docs/out/Phaser.Group.html
index dd422aea..c821b008 100644
--- a/Docs/out/Phaser.Group.html
+++ b/Docs/out/Phaser.Group.html
@@ -32,6 +32,10 @@
Phaser
+
Pre-update is called at the very start of the update cycle, before any other subsystems have been updated (including Physics).
+It is only called if active is set to true.
Update is called after all the core subsystems (Input, Tweens, Sound, etc) and the State have updated, but before the render.
+It is only called if active is set to true.
The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
+
+
+
+
+
+
+
+
+
+
+
new Point(x, y)
+
+
+
+
+
+
+
+
Creates a new Point. If you pass no parameters a Point is created set to (0,0).
Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters. If you call this function without parameters, a Rectangle with x, y, width, and height properties set to 0 is created.
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
+
+
+
Description
+
+
+
+
+
+
+
+
+
x
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
The x coordinate of the top-left corner of the Rectangle.
+
+
+
+
+
+
+
y
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
The y coordinate of the top-left corner of the Rectangle.
The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
Determines whether or not this Rectangle object is empty. A Rectangle object is empty if its width or height is less than or equal to 0.
+If set to true then all of the Rectangle properties are set to 0.
The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property.
The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties, however it does affect the width property.
The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
+However it does affect the height property, whereas changing the y value does not affect the height property.
A value of true if the Rectangle object contains the specified point; otherwise false.
+
+
+
+
+
+
+ Type
+
+
+
+boolean
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
<static> containsPoint(a, point) → {boolean}
+
+
+
+
+
+
+
+
Determines whether the specified point is contained within the rectangular region defined by this Rectangle object. This method is similar to the Rectangle.contains() method, except that it takes a Point object as a parameter.
A value of true if the Rectangle object contains the specified point; otherwise false.
+
+
+
+
+
+
+ Type
+
+
+
+boolean
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
<static> containsRect(a, b) → {boolean}
+
+
+
+
+
+
+
+
Determines whether the first Rectangle object is fully contained within the second Rectangle object.
+A Rectangle object is said to contain another if the second Rectangle object falls entirely within the boundaries of the first.
Increases the size of the Rectangle object by the specified amounts. The center point of the Rectangle object stays the same, and its size increases to the left and right by the dx value, and to the top and the bottom by the dy value.
The x property of this Point object is used to increase the horizontal dimension of the Rectangle object. The y property is used to increase the vertical dimension of the Rectangle object.
If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object, returns the area of intersection as a Rectangle object. If the Rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0.
Optional Rectangle object. If given the intersection values will be set into this object, otherwise a brand new Rectangle object will be created and returned.
A Rectangle object that equals the area of intersection. If the Rectangles do not intersect, this method returns an empty Rectangle object; that is, a Rectangle with its x, y, width, and height properties set to 0.
A value of true if the Rectangle object contains the specified point; otherwise false.
+
+
+
+
+
+
+ Type
+
+
+
+boolean
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
containsRect(b) → {boolean}
+
+
+
+
+
+
+
+
Determines whether the first Rectangle object is fully contained within the second Rectangle object.
+A Rectangle object is said to contain another if the second Rectangle object falls entirely within the boundaries of the first.
Increases the size of the Rectangle object by the specified amounts. The center point of the Rectangle object stays the same, and its size increases to the left and right by the dx value, and to the top and the bottom by the dy value.
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
+
+
+
Description
+
+
+
+
+
+
+
+
+
dx
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
The amount to be added to the left side of the Rectangle.
+
+
+
+
+
+
+
dy
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
The amount to be added to the bottom side of the Rectangle.
If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object, returns the area of intersection as a Rectangle object. If the Rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0.
Optional Rectangle object. If given the intersection values will be set into this object, otherwise a brand new Rectangle object will be created and returned.
A Rectangle object that equals the area of intersection. If the Rectangles do not intersect, this method returns an empty Rectangle object; that is, a Rectangle with its x, y, width, and height properties set to 0.
Adjusts the location of the Rectangle object using a Point object as a parameter. This method is similar to the Rectangle.offset() method, except that it takes a Point object as a parameter.
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
+
+
+
Description
+
+
+
+
+
+
+
+
+
point
+
+
+
+
+
+Point
+
+
+
+
+
+
+
+
+
+
A Point object to use to offset this Rectangle object.
<p><strong>IMPORTANT:</strong> Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use halt() instead.</p>
If Signal should keep record of previously dispatched parameters and
+automatically execute listener during add()/addOnce() if Signal was
+already dispatched before.
Context on which listener will be executed (object that should represent the this variable inside listener function).
+
+
+
+
+
+
+
priority
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0).
Add listener to the signal that should be removed after first execution (will be executed only once).
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
Argument
+
+
+
+
+
Description
+
+
+
+
+
+
+
+
+
listener
+
+
+
+
+
+function
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Signal handler function.
+
+
+
+
+
+
+
listenerContext
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
Context on which listener will be executed (object that should represent the this variable inside listener function).
+
+
+
+
+
+
+
priority
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
The Stage controls the canvas on which everything is displayed. It handles display within the browser,
+focus handling, game resizing, scaling and the pause, boot and orientation screens.
This is a base State class which can be extended if you are creating your own game.
+It provides quick access to common functions such as the camera, cache, input, match, sound and more.
This method is called after the game engine successfully switches states.
+Feel free to add any setup code here (do not load anything here, override preload() instead).
"This world is but a canvas to our imagination." - Henry David Thoreau
+
<p>
+A game has only one world. The world is an abstract place in which all game objects live. It is not bound
+by stage limits and can be any size. You look into the world via cameras. All game objects live within
+the world at world-based coordinates. By default a world is created the same size as your Stage.
/**
+* @author Richard Davey <rich@photonstorm.com>
+* @copyright 2013 Photon Storm Ltd.
+* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
+*/
+
+/**
+* This is a base Plugin template to use for any Phaser plugin development.
+*
+* @class Phaser.Plugin
+* @classdesc Phaser - Plugin
+* @constructor
+* @param {Phaser.Game} game - A reference to the currently running game.
+* @param {Any} parent - The object that owns this plugin, usually Phaser.PluginManager.
+*/
+Phaser.Plugin = function (game, parent) {
+
+ if (typeof parent === 'undefined') { parent = null; }
+
+ /**
+ * @property {Phaser.Game} game - A reference to the currently running game.
+ */
+ this.game = game;
+
+ /**
+ * @property {Any} parent - The parent of this plugin. If added to the PluginManager the parent will be set to that, otherwise it will be null.
+ */
+ this.parent = parent;
+
+ /**
+ * @property {boolean} active - A Plugin with active=true has its preUpdate and update methods called by the parent, otherwise they are skipped.
+ * @default
+ */
+ this.active = false;
+
+ /**
+ * @property {boolean} visible - A Plugin with visible=true has its render and postRender methods called by the parent, otherwise they are skipped.
+ * @default
+ */
+ this.visible = false;
+
+ /**
+ * @property {boolean} hasPreUpdate - A flag to indicate if this plugin has a preUpdate method.
+ * @default
+ */
+ this.hasPreUpdate = false;
+
+ /**
+ * @property {boolean} hasUpdate - A flag to indicate if this plugin has an update method.
+ * @default
+ */
+ this.hasUpdate = false;
+
+ /**
+ * @property {boolean} hasRender - A flag to indicate if this plugin has a render method.
+ * @default
+ */
+ this.hasRender = false;
+
+ /**
+ * @property {boolean} hasPostRender - A flag to indicate if this plugin has a postRender method.
+ * @default
+ */
+ this.hasPostRender = false;
+
+};
+
+Phaser.Plugin.prototype = {
+
+ /**
+ * Pre-update is called at the very start of the update cycle, before any other subsystems have been updated (including Physics).
+ * It is only called if active is set to true.
+ * @method Phaser.Plugin#preUpdate
+ */
+ preUpdate: function () {
+ },
+
+ /**
+ * Update is called after all the core subsystems (Input, Tweens, Sound, etc) and the State have updated, but before the render.
+ * It is only called if active is set to true.
+ * @method Phaser.Plugin#update
+ */
+ update: function () {
+ },
+
+ /**
+ * Render is called right after the Game Renderer completes, but before the State.render.
+ * It is only called if visible is set to true.
+ * @method Phaser.Plugin#render
+ */
+ render: function () {
+ },
+
+ /**
+ * Post-render is called after the Game Renderer and State.render have run.
+ * It is only called if visible is set to true.
+ * @method Phaser.Plugin#postRender
+ */
+ postRender: function () {
+ },
+
+ /**
+ * Clear down this Plugin and null out references
+ * @method Phaser.Plugin#destroy
+ */
+ destroy: function () {
+
+ this.game = null;
+ this.parent = null;
+ this.active = false;
+ this.visible = false;
+
+ }
+
+};
+
/**
+* @author Richard Davey <rich@photonstorm.com>
+* @copyright 2013 Photon Storm Ltd.
+* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
+*/
+
+/**
+* Creates a new Point. If you pass no parameters a Point is created set to (0,0).
+* @class Phaser.Point
+* @classdesc The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
+* @constructor
+* @param {number} x The horizontal position of this Point (default 0)
+* @param {number} y The vertical position of this Point (default 0)
+**/
+Phaser.Point = function (x, y) {
+
+ x = x || 0;
+ y = y || 0;
+
+ /**
+ * @property {number} x - The x coordinate of the point.
+ **/
+ this.x = x;
+
+ /**
+ * @property {number} y - The y coordinate of the point.
+ **/
+ this.y = y;
+
+};
+
+Phaser.Point.prototype = {
+
+ /**
+ * Copies the x and y properties from any given object to this Point.
+ * @method Phaser.Point#copyFrom
+ * @param {any} source - The object to copy from.
+ * @return {Point} This Point object.
+ **/
+ copyFrom: function (source) {
+ return this.setTo(source.x, source.y);
+ },
+
+ /**
+ * Inverts the x and y values of this Point
+ * @method Phaser.Point#invert
+ * @return {Point} This Point object.
+ **/
+ invert: function () {
+ return this.setTo(this.y, this.x);
+ },
+
+ /**
+ * Sets the x and y values of this Point object to the given coordinates.
+ * @method Phaser.Point#setTo
+ * @param {number} x - The horizontal position of this point.
+ * @param {number} y - The vertical position of this point.
+ * @return {Point} This Point object. Useful for chaining method calls.
+ **/
+ setTo: function (x, y) {
+ this.x = x;
+ this.y = y;
+ return this;
+ },
+
+ /**
+ * Adds the given x and y values to this Point.
+ * @method Phaser.Point#add
+ * @param {number} x - The value to add to Point.x.
+ * @param {number} y - The value to add to Point.y.
+ * @return {Phaser.Point} This Point object. Useful for chaining method calls.
+ **/
+ add: function (x, y) {
+
+ this.x += x;
+ this.y += y;
+ return this;
+
+ },
+
+ /**
+ * Subtracts the given x and y values from this Point.
+ * @method Phaser.Point#subtract
+ * @param {number} x - The value to subtract from Point.x.
+ * @param {number} y - The value to subtract from Point.y.
+ * @return {Phaser.Point} This Point object. Useful for chaining method calls.
+ **/
+ subtract: function (x, y) {
+
+ this.x -= x;
+ this.y -= y;
+ return this;
+
+ },
+
+ /**
+ * Multiplies Point.x and Point.y by the given x and y values.
+ * @method Phaser.Point#multiply
+ * @param {number} x - The value to multiply Point.x by.
+ * @param {number} y - The value to multiply Point.x by.
+ * @return {Phaser.Point} This Point object. Useful for chaining method calls.
+ **/
+ multiply: function (x, y) {
+
+ this.x *= x;
+ this.y *= y;
+ return this;
+
+ },
+
+ /**
+ * Divides Point.x and Point.y by the given x and y values.
+ * @method Phaser.Point#divide
+ * @param {number} x - The value to divide Point.x by.
+ * @param {number} y - The value to divide Point.x by.
+ * @return {Phaser.Point} This Point object. Useful for chaining method calls.
+ **/
+ divide: function (x, y) {
+
+ this.x /= x;
+ this.y /= y;
+ return this;
+
+ },
+
+ /**
+ * Clamps the x value of this Point to be between the given min and max.
+ * @method Phaser.Point#clampX
+ * @param {number} min - The minimum value to clamp this Point to.
+ * @param {number} max - The maximum value to clamp this Point to.
+ * @return {Phaser.Point} This Point object.
+ */
+ clampX: function (min, max) {
+
+ this.x = Phaser.Math.clamp(this.x, min, max);
+ return this;
+
+ },
+
+ /**
+ * Clamps the y value of this Point to be between the given min and max
+ * @method Phaser.Point#clampY
+ * @param {number} min - The minimum value to clamp this Point to.
+ * @param {number} max - The maximum value to clamp this Point to.
+ * @return {Phaser.Point} This Point object.
+ */
+ clampY: function (min, max) {
+
+ this.y = Phaser.Math.clamp(this.y, min, max);
+ return this;
+
+ },
+
+ /**
+ * Clamps this Point object values to be between the given min and max.
+ * @method Phaser.Point#clamp
+ * @param {number} min - The minimum value to clamp this Point to.
+ * @param {number} max - The maximum value to clamp this Point to.
+ * @return {Phaser.Point} This Point object.
+ */
+ clamp: function (min, max) {
+
+ this.x = Phaser.Math.clamp(this.x, min, max);
+ this.y = Phaser.Math.clamp(this.y, min, max);
+ return this;
+
+ },
+
+ /**
+ * Creates a copy of the given Point.
+ * @method Phaser.Point#clone
+ * @param {Phaser.Point} [output] Optional Point object. If given the values will be set into this object, otherwise a brand new Point object will be created and returned.
+ * @return {Phaser.Point} The new Point object.
+ */
+ clone: function (output) {
+
+ if (typeof output === "undefined") { output = new Phaser.Point; }
+
+ return output.setTo(this.x, this.y);
+
+ },
+
+ /**
+ * Copies the x and y properties from any given object to this Point.
+ * @method Phaser.Point#copyFrom
+ * @param {any} source - The object to copy from.
+ * @return {Point} This Point object.
+ **/
+ copyFrom: function (source) {
+ return this.setTo(source.x, source.y);
+ },
+
+ /**
+ * Copies the x and y properties from this Point to any given object.
+ * @method Phaser.Point#copyTo
+ * @param {any} dest - The object to copy to.
+ * @return {Object} The dest object.
+ **/
+ copyTo: function(dest) {
+
+ dest[x] = this.x;
+ dest[y] = this.y;
+
+ return dest;
+
+ },
+
+ /**
+ * Returns the distance of this Point object to the given object (can be a Circle, Point or anything with x/y properties)
+ * @method Phaser.Point#distance
+ * @param {object} dest - The target object. Must have visible x and y properties that represent the center of the object.
+ * @param {boolean} [round] - Round the distance to the nearest integer (default false).
+ * @return {number} The distance between this Point object and the destination Point object.
+ */
+ distance: function (dest, round) {
+
+ return Phaser.Point.distance(this, dest, round);
+
+ },
+
+ /**
+ * Determines whether the given objects x/y values are equal to this Point object.
+ * @method Phaser.Point#equals
+ * @param {Phaser.Point} a - The first object to compare.
+ * @return {boolean} A value of true if the Points are equal, otherwise false.
+ */
+ equals: function (a) {
+ return (a.x == this.x && a.y == this.y);
+ },
+
+ /**
+ * Rotates this Point around the x/y coordinates given to the desired angle.
+ * @method Phaser.Point#rotate
+ * @param {number} x - The x coordinate of the anchor point
+ * @param {number} y - The y coordinate of the anchor point
+ * @param {number} angle - The angle in radians (unless asDegrees is true) to rotate the Point to.
+ * @param {boolean} asDegrees - Is the given rotation in radians (false) or degrees (true)?
+ * @param {number} [distance] - An optional distance constraint between the Point and the anchor.
+ * @return {Phaser.Point} The modified point object.
+ */
+ rotate: function (x, y, angle, asDegrees, distance) {
+ return Phaser.Point.rotate(this, x, y, angle, asDegrees, distance);
+ },
+
+ /**
+ * Returns a string representation of this object.
+ * @method Phaser.Point#toString
+ * @return {string} A string representation of the instance.
+ **/
+ toString: function () {
+ return '[{Point (x=' + this.x + ' y=' + this.y + ')}]';
+ }
+
+};
+
+/**
+* Adds the coordinates of two points together to create a new point.
+* @method Phaser.Point.add
+* @param {Phaser.Point} a - The first Point object.
+* @param {Phaser.Point} b - The second Point object.
+* @param {Phaser.Point} [out] - Optional Point to store the value in, if not supplied a new Point object will be created.
+* @return {Phaser.Point} The new Point object.
+*/
+Phaser.Point.add = function (a, b, out) {
+
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+
+ out.x = a.x + b.x;
+ out.y = a.y + b.y;
+
+ return out;
+
+};
+
+/**
+* Subtracts the coordinates of two points to create a new point.
+* @method Phaser.Point.subtract
+* @param {Phaser.Point} a - The first Point object.
+* @param {Phaser.Point} b - The second Point object.
+* @param {Phaser.Point} [out] - Optional Point to store the value in, if not supplied a new Point object will be created.
+* @return {Phaser.Point} The new Point object.
+*/
+Phaser.Point.subtract = function (a, b, out) {
+
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+
+ out.x = a.x - b.x;
+ out.y = a.y - b.y;
+
+ return out;
+
+};
+
+/**
+* Multiplies the coordinates of two points to create a new point.
+* @method Phaser.Point.multiply
+* @param {Phaser.Point} a - The first Point object.
+* @param {Phaser.Point} b - The second Point object.
+* @param {Phaser.Point} [out] - Optional Point to store the value in, if not supplied a new Point object will be created.
+* @return {Phaser.Point} The new Point object.
+*/
+Phaser.Point.multiply = function (a, b, out) {
+
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+
+ out.x = a.x * b.x;
+ out.y = a.y * b.y;
+
+ return out;
+
+};
+
+/**
+* Divides the coordinates of two points to create a new point.
+* @method Phaser.Point.divide
+* @param {Phaser.Point} a - The first Point object.
+* @param {Phaser.Point} b - The second Point object.
+* @param {Phaser.Point} [out] - Optional Point to store the value in, if not supplied a new Point object will be created.
+* @return {Phaser.Point} The new Point object.
+*/
+Phaser.Point.divide = function (a, b, out) {
+
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+
+ out.x = a.x / b.x;
+ out.y = a.y / b.y;
+
+ return out;
+
+};
+
+/**
+* Determines whether the two given Point objects are equal. They are considered equal if they have the same x and y values.
+* @method Phaser.Point.equals
+* @param {Phaser.Point} a - The first Point object.
+* @param {Phaser.Point} b - The second Point object.
+* @return {boolean} A value of true if the Points are equal, otherwise false.
+*/
+Phaser.Point.equals = function (a, b) {
+ return (a.x == b.x && a.y == b.y);
+};
+
+/**
+* Returns the distance of this Point object to the given object (can be a Circle, Point or anything with x/y properties).
+* @method Phaser.Point.distance
+* @param {object} a - The target object. Must have visible x and y properties that represent the center of the object.
+* @param {object} b - The target object. Must have visible x and y properties that represent the center of the object.
+* @param {boolean} [round] - Round the distance to the nearest integer (default false).
+* @return {number} The distance between this Point object and the destination Point object.
+*/
+Phaser.Point.distance = function (a, b, round) {
+
+ if (typeof round === "undefined") { round = false }
+
+ if (round)
+ {
+ return Phaser.Math.distanceRound(a.x, a.y, b.x, b.y);
+ }
+ else
+ {
+ return Phaser.Math.distance(a.x, a.y, b.x, b.y);
+ }
+
+},
+
+/**
+* Rotates a Point around the x/y coordinates given to the desired angle.
+* @method Phaser.Point.rotate
+* @param {Phaser.Point} a - The Point object to rotate.
+* @param {number} x - The x coordinate of the anchor point
+* @param {number} y - The y coordinate of the anchor point
+* @param {number} angle - The angle in radians (unless asDegrees is true) to rotate the Point to.
+* @param {boolean} asDegrees - Is the given rotation in radians (false) or degrees (true)?
+* @param {number} distance - An optional distance constraint between the Point and the anchor.
+* @return {Phaser.Point} The modified point object.
+*/
+Phaser.Point.rotate = function (a, x, y, angle, asDegrees, distance) {
+
+ asDegrees = asDegrees || false;
+ distance = distance || null;
+
+ if (asDegrees)
+ {
+ angle = Phaser.Math.radToDeg(angle);
+ }
+
+ // Get distance from origin (cx/cy) to this point
+ if (distance === null)
+ {
+ distance = Math.sqrt(((x - a.x) * (x - a.x)) + ((y - a.y) * (y - a.y)));
+ }
+
+ return a.setTo(x + distance * Math.cos(angle), y + distance * Math.sin(angle));
+
+};
+
/**
+* @author Richard Davey <rich@photonstorm.com>
+* @copyright 2013 Photon Storm Ltd.
+* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
+*/
+
+/**
+* Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters. If you call this function without parameters, a Rectangle with x, y, width, and height properties set to 0 is created.
+*
+* @class Phaser.Rectangle
+* @constructor
+* @param {number} x - The x coordinate of the top-left corner of the Rectangle.
+* @param {number} y - The y coordinate of the top-left corner of the Rectangle.
+* @param {number} width - The width of the Rectangle in pixels.
+* @param {number} height - The height of the Rectangle in pixels.
+* @return {Rectangle} This Rectangle object.
+**/
+Phaser.Rectangle = function (x, y, width, height) {
+
+ x = x || 0;
+ y = y || 0;
+ width = width || 0;
+ height = height || 0;
+
+ /**
+ * @property {number} x - Description.
+ */
+ this.x = x;
+
+ /**
+ * @property {number} y - Description.
+ */
+ this.y = y;
+
+ /**
+ * @property {number} width - Description.
+ */
+ this.width = width;
+
+ /**
+ * @property {number} height - Description.
+ */
+ this.height = height;
+
+};
+
+Phaser.Rectangle.prototype = {
+
+ /**
+ * Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts.
+ * @method Phaser.Rectangle#offset
+ * @param {number} dx - Moves the x value of the Rectangle object by this amount.
+ * @param {number} dy - Moves the y value of the Rectangle object by this amount.
+ * @return {Rectangle} This Rectangle object.
+ **/
+ offset: function (dx, dy) {
+
+ this.x += dx;
+ this.y += dy;
+
+ return this;
+
+ },
+
+ /**
+ * Adjusts the location of the Rectangle object using a Point object as a parameter. This method is similar to the Rectangle.offset() method, except that it takes a Point object as a parameter.
+ * @method Phaser.Rectangle#offsetPoint
+ * @param {Point} point - A Point object to use to offset this Rectangle object.
+ * @return {Rectangle} This Rectangle object.
+ **/
+ offsetPoint: function (point) {
+ return this.offset(point.x, point.y);
+ },
+
+ /**
+ * Sets the members of Rectangle to the specified values.
+ * @method Phaser.Rectangle#setTo
+ * @param {number} x - The x coordinate of the top-left corner of the Rectangle.
+ * @param {number} y - The y coordinate of the top-left corner of the Rectangle.
+ * @param {number} width - The width of the Rectangle in pixels.
+ * @param {number} height - The height of the Rectangle in pixels.
+ * @return {Rectangle} This Rectangle object
+ **/
+ setTo: function (x, y, width, height) {
+
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+
+ return this;
+
+ },
+
+ /**
+ * Runs Math.floor() on both the x and y values of this Rectangle.
+ * @method Phaser.Rectangle#floor
+ **/
+ floor: function () {
+
+ this.x = Math.floor(this.x);
+ this.y = Math.floor(this.y);
+
+ },
+
+ /**
+ * Copies the x, y, width and height properties from any given object to this Rectangle.
+ * @method Phaser.Rectangle#copyFrom
+ * @param {any} source - The object to copy from.
+ * @return {Rectangle} This Rectangle object.
+ **/
+ copyFrom: function (source) {
+ return this.setTo(source.x, source.y, source.width, source.height);
+ },
+
+ /**
+ * Copies the x, y, width and height properties from this Rectangle to any given object.
+ * @method Phaser.Rectangle#copyTo
+ * @param {any} source - The object to copy to.
+ * @return {object} This object.
+ **/
+ copyTo: function (dest) {
+
+ dest.x = this.x;
+ dest.y = this.y;
+ dest.width = this.width;
+ dest.height = this.height;
+
+ return dest;
+
+ },
+
+ /**
+ * Increases the size of the Rectangle object by the specified amounts. The center point of the Rectangle object stays the same, and its size increases to the left and right by the dx value, and to the top and the bottom by the dy value.
+ * @method Phaser.Rectangle#inflate
+ * @param {number} dx - The amount to be added to the left side of the Rectangle.
+ * @param {number} dy - The amount to be added to the bottom side of the Rectangle.
+ * @return {Phaser.Rectangle} This Rectangle object.
+ */
+ inflate: function (dx, dy) {
+ return Phaser.Rectangle.inflate(this, dx, dy);
+ },
+
+ /**
+ * The size of the Rectangle object, expressed as a Point object with the values of the width and height properties.
+ * @method Phaser.Rectangle#size
+ * @param {Phaser.Point} [output] - Optional Point object. If given the values will be set into the object, otherwise a brand new Point object will be created and returned.
+ * @return {Phaser.Point} The size of the Rectangle object.
+ */
+ size: function (output) {
+ return Phaser.Rectangle.size(this, output);
+ },
+
+ /**
+ * Returns a new Rectangle object with the same values for the x, y, width, and height properties as the original Rectangle object.
+ * @method Phaser.Rectangle#clone
+ * @param {Phaser.Rectangle} [output] - Optional Rectangle object. If given the values will be set into the object, otherwise a brand new Rectangle object will be created and returned.
+ * @return {Phaser.Rectangle}
+ */
+ clone: function (output) {
+ return Phaser.Rectangle.clone(this, output);
+ },
+
+ /**
+ * Determines whether the specified coordinates are contained within the region defined by this Rectangle object.
+ * @method Phaser.Rectangle#contains
+ * @param {number} x - The x coordinate of the point to test.
+ * @param {number} y - The y coordinate of the point to test.
+ * @return {boolean} A value of true if the Rectangle object contains the specified point; otherwise false.
+ */
+ contains: function (x, y) {
+ return Phaser.Rectangle.contains(this, x, y);
+ },
+
+ /**
+ * Determines whether the first Rectangle object is fully contained within the second Rectangle object.
+ * A Rectangle object is said to contain another if the second Rectangle object falls entirely within the boundaries of the first.
+ * @method Phaser.Rectangle#containsRect
+ * @param {Phaser.Rectangle} b - The second Rectangle object.
+ * @return {boolean} A value of true if the Rectangle object contains the specified point; otherwise false.
+ */
+ containsRect: function (b) {
+ return Phaser.Rectangle.containsRect(this, b);
+ },
+
+ /**
+ * Determines whether the two Rectangles are equal.
+ * This method compares the x, y, width and height properties of each Rectangle.
+ * @method Phaser.Rectangle#equals
+ * @param {Phaser.Rectangle} b - The second Rectangle object.
+ * @return {boolean} A value of true if the two Rectangles have exactly the same values for the x, y, width and height properties; otherwise false.
+ */
+ equals: function (b) {
+ return Phaser.Rectangle.equals(this, b);
+ },
+
+ /**
+ * If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object, returns the area of intersection as a Rectangle object. If the Rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0.
+ * @method Phaser.Rectangle#intersection
+ * @param {Phaser.Rectangle} b - The second Rectangle object.
+ * @param {Phaser.Rectangle} out - Optional Rectangle object. If given the intersection values will be set into this object, otherwise a brand new Rectangle object will be created and returned.
+ * @return {Phaser.Rectangle} A Rectangle object that equals the area of intersection. If the Rectangles do not intersect, this method returns an empty Rectangle object; that is, a Rectangle with its x, y, width, and height properties set to 0.
+ */
+ intersection: function (b, out) {
+ return Phaser.Rectangle.intersection(this, b, output);
+ },
+
+ /**
+ * Determines whether the two Rectangles intersect with each other.
+ * This method checks the x, y, width, and height properties of the Rectangles.
+ * @method Phaser.Rectangle#intersects
+ * @param {Phaser.Rectangle} b - The second Rectangle object.
+ * @param {number} tolerance - A tolerance value to allow for an intersection test with padding, default to 0.
+ * @return {boolean} A value of true if the specified object intersects with this Rectangle object; otherwise false.
+ */
+ intersects: function (b, tolerance) {
+ return Phaser.Rectangle.intersects(this, b, tolerance);
+ },
+
+ /**
+ * Determines whether the object specified intersects (overlaps) with the given values.
+ * @method Phaser.Rectangle#intersectsRaw
+ * @param {number} left - Description.
+ * @param {number} right - Description.
+ * @param {number} top - Description.
+ * @param {number} bottomt - Description.
+ * @param {number} tolerance - A tolerance value to allow for an intersection test with padding, default to 0
+ * @return {boolean} A value of true if the specified object intersects with the Rectangle; otherwise false.
+ */
+ intersectsRaw: function (left, right, top, bottom, tolerance) {
+ return Phaser.Rectangle.intersectsRaw(this, left, right, top, bottom, tolerance);
+ },
+
+ /**
+ * Adds two Rectangles together to create a new Rectangle object, by filling in the horizontal and vertical space between the two Rectangles.
+ * @method Phaser.Rectangle#union
+ * @param {Phaser.Rectangle} b - The second Rectangle object.
+ * @param {Phaser.Rectangle} [out] - Optional Rectangle object. If given the new values will be set into this object, otherwise a brand new Rectangle object will be created and returned.
+ * @return {Phaser.Rectangle} A Rectangle object that is the union of the two Rectangles.
+ */
+ union: function (b, out) {
+ return Phaser.Rectangle.union(this, b, out);
+ },
+
+ /**
+ * Returns a string representation of this object.
+ * @method Phaser.Rectangle#toString
+ * @return {string} A string representation of the instance.
+ **/
+ toString: function () {
+ return "[{Rectangle (x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + " empty=" + this.empty + ")}]";
+ }
+
+};
+
+/**
+* @name Phaser.Rectangle#halfWidth
+* @property {number} halfWidth - Half of the width of the Rectangle.
+* @readonly
+*/
+Object.defineProperty(Phaser.Rectangle.prototype, "halfWidth", {
+
+ get: function () {
+ return Math.round(this.width / 2);
+ }
+
+});
+
+/**
+* @name Phaser.Rectangle#halfHeight
+* @property {number} halfHeight - Half of the height of the Rectangle.
+* @readonly
+*/
+Object.defineProperty(Phaser.Rectangle.prototype, "halfHeight", {
+
+ get: function () {
+ return Math.round(this.height / 2);
+ }
+
+});
+
+/**
+* The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
+* @name Phaser.Rectangle#bottom
+* @property {number} bottom - The sum of the y and height properties.
+*/
+Object.defineProperty(Phaser.Rectangle.prototype, "bottom", {
+
+ get: function () {
+ return this.y + this.height;
+ },
+
+ set: function (value) {
+ if (value <= this.y) {
+ this.height = 0;
+ } else {
+ this.height = (this.y - value);
+ }
+ }
+
+});
+
+/**
+* The location of the Rectangles bottom right corner as a Point object.
+* @name Phaser.Rectangle#bottom
+* @property {Phaser.Point} bottomRight - Gets or sets the location of the Rectangles bottom right corner as a Point object.
+*/
+Object.defineProperty(Phaser.Rectangle.prototype, "bottomRight", {
+
+ get: function () {
+ return new Phaser.Point(this.right, this.bottom);
+ },
+
+ set: function (value) {
+ this.right = value.x;
+ this.bottom = value.y;
+ }
+
+});
+
+/**
+* The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property.
+* @name Phaser.Rectangle#left
+* @property {number} left - The x coordinate of the left of the Rectangle.
+*/
+Object.defineProperty(Phaser.Rectangle.prototype, "left", {
+
+ get: function () {
+ return this.x;
+ },
+
+ set: function (value) {
+ if (value >= this.right) {
+ this.width = 0;
+ } else {
+ this.width = this.right - value;
+ }
+ this.x = value;
+ }
+
+});
+
+/**
+* The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties, however it does affect the width property.
+* @name Phaser.Rectangle#right
+* @property {number} right - The sum of the x and width properties.
+*/
+Object.defineProperty(Phaser.Rectangle.prototype, "right", {
+
+ get: function () {
+ return this.x + this.width;
+ },
+
+ set: function (value) {
+ if (value <= this.x) {
+ this.width = 0;
+ } else {
+ this.width = this.x + value;
+ }
+ }
+
+});
+
+/**
+* The volume of the Rectangle derived from width * height.
+* @name Phaser.Rectangle#volume
+* @property {number} volume - The volume of the Rectangle derived from width * height.
+* @readonly
+*/
+Object.defineProperty(Phaser.Rectangle.prototype, "volume", {
+
+ get: function () {
+ return this.width * this.height;
+ }
+
+});
+
+/**
+* The perimeter size of the Rectangle. This is the sum of all 4 sides.
+* @name Phaser.Rectangle#perimeter
+* @property {number} perimeter - The perimeter size of the Rectangle. This is the sum of all 4 sides.
+* @readonly
+*/
+Object.defineProperty(Phaser.Rectangle.prototype, "perimeter", {
+
+ get: function () {
+ return (this.width * 2) + (this.height * 2);
+ }
+
+});
+
+/**
+* The x coordinate of the center of the Rectangle.
+* @name Phaser.Rectangle#centerX
+* @property {number} centerX - The x coordinate of the center of the Rectangle.
+*/
+Object.defineProperty(Phaser.Rectangle.prototype, "centerX", {
+
+ get: function () {
+ return this.x + this.halfWidth;
+ },
+
+ set: function (value) {
+ this.x = value - this.halfWidth;
+ }
+
+});
+
+/**
+* The y coordinate of the center of the Rectangle.
+* @name Phaser.Rectangle#centerY
+* @property {number} centerY - The y coordinate of the center of the Rectangle.
+*/
+Object.defineProperty(Phaser.Rectangle.prototype, "centerY", {
+
+ get: function () {
+ return this.y + this.halfHeight;
+ },
+
+ set: function (value) {
+ this.y = value - this.halfHeight;
+ }
+
+});
+
+/**
+* The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
+* However it does affect the height property, whereas changing the y value does not affect the height property.
+* @name Phaser.Rectangle#top
+* @property {number} top - The y coordinate of the top of the Rectangle.
+*/
+Object.defineProperty(Phaser.Rectangle.prototype, "top", {
+
+ get: function () {
+ return this.y;
+ },
+
+ set: function (value) {
+ if (value >= this.bottom) {
+ this.height = 0;
+ this.y = value;
+ } else {
+ this.height = (this.bottom - value);
+ }
+ }
+
+});
+
+/**
+* The location of the Rectangles top left corner as a Point object.
+* @name Phaser.Rectangle#topLeft
+* @property {Phaser.Point} topLeft - The location of the Rectangles top left corner as a Point object.
+*/
+Object.defineProperty(Phaser.Rectangle.prototype, "topLeft", {
+
+ get: function () {
+ return new Phaser.Point(this.x, this.y);
+ },
+
+ set: function (value) {
+ this.x = value.x;
+ this.y = value.y;
+ }
+
+});
+
+/**
+* Determines whether or not this Rectangle object is empty. A Rectangle object is empty if its width or height is less than or equal to 0.
+* If set to true then all of the Rectangle properties are set to 0.
+* @name Phaser.Rectangle#empty
+* @property {boolean} empty - Gets or sets the Rectangles empty state.
+*/
+Object.defineProperty(Phaser.Rectangle.prototype, "empty", {
+
+ get: function () {
+ return (!this.width || !this.height);
+ },
+
+ set: function (value) {
+ this.setTo(0, 0, 0, 0);
+ }
+
+});
+
+/**
+* Increases the size of the Rectangle object by the specified amounts. The center point of the Rectangle object stays the same, and its size increases to the left and right by the dx value, and to the top and the bottom by the dy value.
+* @method Phaser.Rectangle.inflate
+* @param {Phaser.Rectangle} a - The Rectangle object.
+* @param {number} dx - The amount to be added to the left side of the Rectangle.
+* @param {number} dy - The amount to be added to the bottom side of the Rectangle.
+* @return {Phaser.Rectangle} This Rectangle object.
+*/
+Phaser.Rectangle.inflate = function (a, dx, dy) {
+ a.x -= dx;
+ a.width += 2 * dx;
+ a.y -= dy;
+ a.height += 2 * dy;
+ return a;
+};
+
+/**
+* Increases the size of the Rectangle object. This method is similar to the Rectangle.inflate() method except it takes a Point object as a parameter.
+* @method Phaser.Rectangle.inflatePoint
+* @param {Phaser.Rectangle} a - The Rectangle object.
+* @param {Phaser.Point} point - The x property of this Point object is used to increase the horizontal dimension of the Rectangle object. The y property is used to increase the vertical dimension of the Rectangle object.
+* @return {Phaser.Rectangle} The Rectangle object.
+*/
+Phaser.Rectangle.inflatePoint = function (a, point) {
+ return Phaser.Phaser.Rectangle.inflate(a, point.x, point.y);
+};
+
+/**
+* The size of the Rectangle object, expressed as a Point object with the values of the width and height properties.
+* @method Phaser.Rectangle.size
+* @param {Phaser.Rectangle} a - The Rectangle object.
+* @param {Phaser.Point} [output] - Optional Point object. If given the values will be set into the object, otherwise a brand new Point object will be created and returned.
+* @return {Phaser.Point} The size of the Rectangle object
+*/
+Phaser.Rectangle.size = function (a, output) {
+ if (typeof output === "undefined") { output = new Phaser.Point(); }
+ return output.setTo(a.width, a.height);
+};
+
+/**
+* Returns a new Rectangle object with the same values for the x, y, width, and height properties as the original Rectangle object.
+* @method Phaser.Rectangle.clone
+* @param {Phaser.Rectangle} a - The Rectangle object.
+* @param {Phaser.Rectangle} [output] - Optional Rectangle object. If given the values will be set into the object, otherwise a brand new Rectangle object will be created and returned.
+* @return {Phaser.Rectangle}
+*/
+Phaser.Rectangle.clone = function (a, output) {
+ if (typeof output === "undefined") { output = new Phaser.Rectangle(); }
+ return output.setTo(a.x, a.y, a.width, a.height);
+};
+
+/**
+* Determines whether the specified coordinates are contained within the region defined by this Rectangle object.
+* @method Phaser.Rectangle.contains
+* @param {Phaser.Rectangle} a - The Rectangle object.
+* @param {number} x - The x coordinate of the point to test.
+* @param {number} y - The y coordinate of the point to test.
+* @return {boolean} A value of true if the Rectangle object contains the specified point; otherwise false.
+*/
+Phaser.Rectangle.contains = function (a, x, y) {
+ return (x >= a.x && x <= a.right && y >= a.y && y <= a.bottom);
+};
+
+/**
+* Determines whether the specified point is contained within the rectangular region defined by this Rectangle object. This method is similar to the Rectangle.contains() method, except that it takes a Point object as a parameter.
+* @method Phaser.Rectangle.containsPoint
+* @param {Phaser.Rectangle} a - The Rectangle object.
+* @param {Phaser.Point} point - The point object being checked. Can be Point or any object with .x and .y values.
+* @return {boolean} A value of true if the Rectangle object contains the specified point; otherwise false.
+*/
+Phaser.Rectangle.containsPoint = function (a, point) {
+ return Phaser.Phaser.Rectangle.contains(a, point.x, point.y);
+};
+
+/**
+* Determines whether the first Rectangle object is fully contained within the second Rectangle object.
+* A Rectangle object is said to contain another if the second Rectangle object falls entirely within the boundaries of the first.
+* @method Phaser.Rectangle.containsRect
+* @param {Phaser.Rectangle} a - The first Rectangle object.
+* @param {Phaser.Rectangle} b - The second Rectangle object.
+* @return {boolean} A value of true if the Rectangle object contains the specified point; otherwise false.
+*/
+Phaser.Rectangle.containsRect = function (a, b) {
+
+ // If the given rect has a larger volume than this one then it can never contain it
+ if (a.volume > b.volume)
+ {
+ return false;
+ }
+
+ return (a.x >= b.x && a.y >= b.y && a.right <= b.right && a.bottom <= b.bottom);
+
+};
+
+/**
+* Determines whether the two Rectangles are equal.
+* This method compares the x, y, width and height properties of each Rectangle.
+* @method Phaser.Rectangle.equals
+* @param {Phaser.Rectangle} a - The first Rectangle object.
+* @param {Phaser.Rectangle} b - The second Rectangle object.
+* @return {boolean} A value of true if the two Rectangles have exactly the same values for the x, y, width and height properties; otherwise false.
+*/
+Phaser.Rectangle.equals = function (a, b) {
+ return (a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height);
+};
+
+/**
+* If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object, returns the area of intersection as a Rectangle object. If the Rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0.
+* @method Phaser.Rectangle.intersection
+* @param {Phaser.Rectangle} a - The first Rectangle object.
+* @param {Phaser.Rectangle} b - The second Rectangle object.
+* @param {Phaser.Rectangle} [out] - Optional Rectangle object. If given the intersection values will be set into this object, otherwise a brand new Rectangle object will be created and returned.
+* @return {Phaser.Rectangle} A Rectangle object that equals the area of intersection. If the Rectangles do not intersect, this method returns an empty Rectangle object; that is, a Rectangle with its x, y, width, and height properties set to 0.
+*/
+Phaser.Rectangle.intersection = function (a, b, out) {
+
+ out = out || new Phaser.Rectangle;
+
+ if (Phaser.Rectangle.intersects(a, b))
+ {
+ out.x = Math.max(a.x, b.x);
+ out.y = Math.max(a.y, b.y);
+ out.width = Math.min(a.right, b.right) - out.x;
+ out.height = Math.min(a.bottom, b.bottom) - out.y;
+ }
+
+ return out;
+
+};
+
+/**
+* Determines whether the two Rectangles intersect with each other.
+* This method checks the x, y, width, and height properties of the Rectangles.
+* @method Phaser.Rectangle.intersects
+* @param {Phaser.Rectangle} a - The first Rectangle object.
+* @param {Phaser.Rectangle} b - The second Rectangle object.
+* @param {number} tolerance - A tolerance value to allow for an intersection test with padding, default to 0
+* @return {boolean} A value of true if the specified object intersects with this Rectangle object; otherwise false.
+*/
+Phaser.Rectangle.intersects = function (a, b, tolerance) {
+
+ tolerance = tolerance || 0;
+
+ return !(a.x > b.right + tolerance || a.right < b.x - tolerance || a.y > b.bottom + tolerance || a.bottom < b.y - tolerance);
+
+};
+
+/**
+* Determines whether the object specified intersects (overlaps) with the given values.
+* @method Phaser.Rectangle.intersectsRaw
+* @param {number} left - Description.
+* @param {number} right - Description.
+* @param {number} top - Description.
+* @param {number} bottom - Description.
+* @param {number} tolerance - A tolerance value to allow for an intersection test with padding, default to 0
+* @return {boolean} A value of true if the specified object intersects with the Rectangle; otherwise false.
+*/
+Phaser.Rectangle.intersectsRaw = function (a, left, right, top, bottom, tolerance) {
+
+ if (typeof tolerance === "undefined") { tolerance = 0; }
+
+ return !(left > a.right + tolerance || right < a.left - tolerance || top > a.bottom + tolerance || bottom < a.top - tolerance);
+
+};
+
+/**
+* Adds two Rectangles together to create a new Rectangle object, by filling in the horizontal and vertical space between the two Rectangles.
+* @method Phaser.Rectangle.union
+* @param {Phaser.Rectangle} a - The first Rectangle object.
+* @param {Phaser.Rectangle} b - The second Rectangle object.
+* @param {Phaser.Rectangle} [out] - Optional Rectangle object. If given the new values will be set into this object, otherwise a brand new Rectangle object will be created and returned.
+* @return {Phaser.Rectangle} A Rectangle object that is the union of the two Rectangles.
+*/
+Phaser.Rectangle.union = function (a, b, out) {
+
+ if (typeof out === "undefined") { out = new Phaser.Rectangle(); }
+
+ return out.setTo(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.max(a.right, b.right), Math.max(a.bottom, b.bottom));
+
+};
+
/**
+* @author Richard Davey <rich@photonstorm.com>
+* @copyright 2013 Photon Storm Ltd.
+* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
+*/
+
+/**
+* @class Phaser.Signal
+* @classdesc A Signal is used for object communication via a custom broadcaster instead of Events.
+* @author Miller Medeiros http://millermedeiros.github.com/js-signals/
+* @constructor
+*/
+Phaser.Signal = function () {
+
+ /**
+ * @property {Array.<Phaser.SignalBinding>} _bindings - Description.
+ * @private
+ */
+ this._bindings = [];
+
+ /**
+ * @property {Description} _prevParams - Description.
+ * @private
+ */
+ this._prevParams = null;
+
+ // enforce dispatch to aways work on same context (#47)
+ var self = this;
+
+ /**
+ * @property {Description} dispatch - Description.
+ */
+ this.dispatch = function(){
+ Phaser.Signal.prototype.dispatch.apply(self, arguments);
+ };
+
+};
+
+Phaser.Signal.prototype = {
+
+ /**
+ * If Signal should keep record of previously dispatched parameters and
+ * automatically execute listener during `add()`/`addOnce()` if Signal was
+ * already dispatched before.
+ * @property {boolean} memorize
+ */
+ memorize: false,
+
+ /**
+ * @property {boolean} _shouldPropagate
+ * @private
+ */
+ _shouldPropagate: true,
+
+ /**
+ * If Signal is active and should broadcast events.
+ * <p><strong>IMPORTANT:</strong> Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.</p>
+ * @property {boolean} active
+ * @default
+ */
+ active: true,
+
+ /**
+ * @method Phaser.Signal#validateListener
+ * @param {function} listener - Signal handler function.
+ * @param {Description} fnName - Description.
+ * @private
+ */
+ validateListener: function (listener, fnName) {
+ if (typeof listener !== 'function') {
+ throw new Error( 'listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName) );
+ }
+ },
+
+ /**
+ * @method Phaser.Signal#_registerListener
+ * @param {function} listener - Signal handler function.
+ * @param {boolean} isOnce - Description.
+ * @param {object} [listenerContext] - Description.
+ * @param {number} [priority] - The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0).
+ * @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
+ * @private
+ */
+ _registerListener: function (listener, isOnce, listenerContext, priority) {
+
+ var prevIndex = this._indexOfListener(listener, listenerContext),
+ binding;
+
+ if (prevIndex !== -1) {
+ binding = this._bindings[prevIndex];
+ if (binding.isOnce() !== isOnce) {
+ throw new Error('You cannot add'+ (isOnce? '' : 'Once') +'() then add'+ (!isOnce? '' : 'Once') +'() the same listener without removing the relationship first.');
+ }
+ } else {
+ binding = new Phaser.SignalBinding(this, listener, isOnce, listenerContext, priority);
+ this._addBinding(binding);
+ }
+
+ if (this.memorize && this._prevParams){
+ binding.execute(this._prevParams);
+ }
+
+ return binding;
+ },
+
+ /**
+ * @method Phaser.Signal#_addBinding
+ * @param {Phaser.SignalBinding} binding - An Object representing the binding between the Signal and listener.
+ * @private
+ */
+ _addBinding: function (binding) {
+ //simplified insertion sort
+ var n = this._bindings.length;
+ do { --n; } while (this._bindings[n] && binding._priority <= this._bindings[n]._priority);
+ this._bindings.splice(n + 1, 0, binding);
+ },
+
+ /**
+ * @method Phaser.Signal#_indexOfListener
+ * @param {function} listener - Signal handler function.
+ * @return {number} Description.
+ * @private
+ */
+ _indexOfListener: function (listener, context) {
+ var n = this._bindings.length,
+ cur;
+ while (n--) {
+ cur = this._bindings[n];
+ if (cur._listener === listener && cur.context === context) {
+ return n;
+ }
+ }
+ return -1;
+ },
+
+ /**
+ * Check if listener was attached to Signal.
+ *
+ * @method Phaser.Signal#has
+ * @param {Function} listener - Signal handler function.
+ * @param {Object} [context] - Context on which listener will be executed (object that should represent the `this` variable inside listener function).
+ * @return {boolean} If Signal has the specified listener.
+ */
+ has: function (listener, context) {
+ return this._indexOfListener(listener, context) !== -1;
+ },
+
+ /**
+ * Add a listener to the signal.
+ *
+ * @method Phaser.Signal#add
+ * @param {function} listener - Signal handler function.
+ * @param {object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
+ * @param {number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0).
+ * @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
+ */
+ add: function (listener, listenerContext, priority) {
+ this.validateListener(listener, 'add');
+ return this._registerListener(listener, false, listenerContext, priority);
+ },
+
+ /**
+ * Add listener to the signal that should be removed after first execution (will be executed only once).
+ *
+ * @method Phaser.Signal#addOnce
+ * @param {function} listener Signal handler function.
+ * @param {object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
+ * @param {number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
+ * @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
+ */
+ addOnce: function (listener, listenerContext, priority) {
+ this.validateListener(listener, 'addOnce');
+ return this._registerListener(listener, true, listenerContext, priority);
+ },
+
+ /**
+ * Remove a single listener from the dispatch queue.
+ *
+ * @method Phaser.Signal#remove
+ * @param {function} listener Handler function that should be removed.
+ * @param {object} [context] Execution context (since you can add the same handler multiple times if executing in a different context).
+ * @return {function} Listener handler function.
+ */
+ remove: function (listener, context) {
+
+ this.validateListener(listener, 'remove');
+
+ var i = this._indexOfListener(listener, context);
+
+ if (i !== -1)
+ {
+ this._bindings[i]._destroy(); //no reason to a Phaser.SignalBinding exist if it isn't attached to a signal
+ this._bindings.splice(i, 1);
+ }
+
+ return listener;
+
+ },
+
+ /**
+ * Remove all listeners from the Signal.
+ *
+ * @method Phaser.Signal#removeAll
+ */
+ removeAll: function () {
+ var n = this._bindings.length;
+ while (n--) {
+ this._bindings[n]._destroy();
+ }
+ this._bindings.length = 0;
+ },
+
+ /**
+ * Gets the total number of listeneres attached to ths Signal.
+ *
+ * @method Phaser.Signal#getNumListeners
+ * @return {number} Number of listeners attached to the Signal.
+ */
+ getNumListeners: function () {
+ return this._bindings.length;
+ },
+
+ /**
+ * Stop propagation of the event, blocking the dispatch to next listeners on the queue.
+ * <p><strong>IMPORTANT:</strong> should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.</p>
+ * @see Signal.prototype.disable
+ *
+ * @method Phaser.Signal#halt
+ */
+ halt: function () {
+ this._shouldPropagate = false;
+ },
+
+ /**
+ * Dispatch/Broadcast Signal to all listeners added to the queue.
+ *
+ * @method Phaser.Signal#dispatch
+ * @param {any} [params] - Parameters that should be passed to each handler.
+ */
+ dispatch: function (params) {
+ if (! this.active) {
+ return;
+ }
+
+ var paramsArr = Array.prototype.slice.call(arguments),
+ n = this._bindings.length,
+ bindings;
+
+ if (this.memorize) {
+ this._prevParams = paramsArr;
+ }
+
+ if (! n) {
+ //should come after memorize
+ return;
+ }
+
+ bindings = this._bindings.slice(); //clone array in case add/remove items during dispatch
+ this._shouldPropagate = true; //in case `halt` was called before dispatch or during the previous dispatch.
+
+ //execute all callbacks until end of the list or until a callback returns `false` or stops propagation
+ //reverse loop since listeners with higher priority will be added at the end of the list
+ do { n--; } while (bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false);
+ },
+
+ /**
+ * Forget memorized arguments.
+ * @see Signal.memorize
+ *
+ * @method Phaser.Signal#forget
+ */
+ forget: function(){
+ this._prevParams = null;
+ },
+
+ /**
+ * Remove all bindings from signal and destroy any reference to external objects (destroy Signal object).
+ * <p><strong>IMPORTANT:</strong> calling any method on the signal instance after calling dispose will throw errors.</p>
+ *
+ * @method Phaser.Signal#dispose
+ */
+ dispose: function () {
+ this.removeAll();
+ delete this._bindings;
+ delete this._prevParams;
+ },
+
+ /**
+ *
+ * @method Phaser.Signal#toString
+ * @return {string} String representation of the object.
+ */
+ toString: function () {
+ return '[Phaser.Signal active:'+ this.active +' numListeners:'+ this.getNumListeners() +']';
+ }
+
+};
+
new SignalBinding(signal, listener, isOnce, listenerContext, priority)
+
+
+
+
+
+
+
+
Phaser.SignalBinding
+
Object that represents a binding between a Signal and a listener function.
+<br />- <strong>This is an internal constructor and shouldn't be called by regular users.</strong>
+<br />- inspired by Joa Ebert AS3 SignalBinding and Robert Penner's Slot classes.
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
Argument
+
+
+
+
+
Description
+
+
+
+
+
+
+
+
+
signal
+
+
+
+
+
+Signal
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Reference to Signal object that listener is currently bound to.
+
+
+
+
+
+
+
listener
+
+
+
+
+
+function
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Handler function bound to the signal.
+
+
+
+
+
+
+
isOnce
+
+
+
+
+
+boolean
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
If binding should be executed just once.
+
+
+
+
+
+
+
listenerContext
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
Context on which listener will be executed (object that should represent the this variable inside listener function).
+
+
+
+
+
+
+
priority
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
The priority level of the event listener. (default = 0).
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Author:
+
+
+
Miller Medeiros http://millermedeiros.github.com/js-signals/
/**
+* @author Richard Davey <rich@photonstorm.com>
+* @copyright 2013 Photon Storm Ltd.
+* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
+*/
+
+/**
+ * "This world is but a canvas to our imagination." - Henry David Thoreau
+ * <p>
+ * A game has only one world. The world is an abstract place in which all game objects live. It is not bound
+ * by stage limits and can be any size. You look into the world via cameras. All game objects live within
+ * the world at world-based coordinates. By default a world is created the same size as your Stage.
+ *
+ * @class Phaser.World
+ * @constructor
+ * @param {Phaser.Game} game - Reference to the current game instance.
+ */
+Phaser.World = function (game) {
+
+ /**
+ * @property {Phaser.Game} game - A reference to the currently running Game.
+ */
+ this.game = game;
+
+ /**
+ * @property {Phaser.Rectangle} bounds - Bound of this world that objects can not escape from.
+ */
+ this.bounds = new Phaser.Rectangle(0, 0, game.width, game.height);
+
+ /**
+ * @property {Phaser.Camera} camera - Camera instance.
+ */
+ this.camera = null;
+
+ /**
+ * @property {number} currentRenderOrderID - Reset each frame, keeps a count of the total number of objects updated.
+ */
+ this.currentRenderOrderID = 0;
+
+ /**
+ * @property {Phaser.Group} group - Object container stores every object created with `create*` methods.
+ */
+ this.group = null;
+
+};
+
+Phaser.World.prototype = {
+
+ /**
+ * Initialises the game world.
+ *
+ * @method Phaser.World#boot
+ * @protected
+ */
+ boot: function () {
+
+ this.camera = new Phaser.Camera(this.game, 0, 0, 0, this.game.width, this.game.height);
+
+ this.game.camera = this.camera;
+
+ this.group = new Phaser.Group(this.game, null, '__world', true);
+
+ },
+
+ /**
+ * This is called automatically every frame, and is where main logic happens.
+ *
+ * @method Phaser.World#update
+ */
+ update: function () {
+
+ this.camera.update();
+
+ this.currentRenderOrderID = 0;
+
+ if (this.game.stage._stage.first._iNext)
+ {
+ var currentNode = this.game.stage._stage.first._iNext;
+
+ do
+ {
+ if (currentNode['preUpdate'])
+ {
+ currentNode.preUpdate();
+ }
+
+ if (currentNode['update'])
+ {
+ currentNode.update();
+ }
+
+ currentNode = currentNode._iNext;
+ }
+ while (currentNode != this.game.stage._stage.last._iNext)
+ }
+
+ },
+
+ /**
+ * This is called automatically every frame, and is where main logic happens.
+ * @method Phaser.World#postUpdate
+ */
+ postUpdate: function () {
+
+ if (this.game.stage._stage.first._iNext)
+ {
+ var currentNode = this.game.stage._stage.first._iNext;
+
+ do
+ {
+ if (currentNode['postUpdate'])
+ {
+ currentNode.postUpdate();
+ }
+
+ currentNode = currentNode._iNext;
+ }
+ while (currentNode != this.game.stage._stage.last._iNext)
+ }
+
+ },
+
+ /**
+ * Updates the size of this world.
+ * @method Phaser.World#setSize
+ * @param {number} width - New width of the world.
+ * @param {number} height - New height of the world.
+ */
+ setSize: function (width, height) {
+
+ if (width >= this.game.width)
+ {
+ this.bounds.width = width;
+ }
+
+ if (height >= this.game.height)
+ {
+ this.bounds.height = height;
+ }
+
+ },
+
+ /**
+ * Destroyer of worlds.
+ * @method Phaser.World#destroy
+ */
+ destroy: function () {
+
+ this.camera.x = 0;
+ this.camera.y = 0;
+
+ this.game.input.reset(true);
+
+ this.group.removeAll();
+
+ }
+
+};
+
+/**
+* @name Phaser.World#width
+* @property {number} width - Gets or sets the current width of the game world.
+*/
+Object.defineProperty(Phaser.World.prototype, "width", {
+
+ get: function () {
+ return this.bounds.width;
+ },
+
+ set: function (value) {
+ this.bounds.width = value;
+ }
+
+});
+
+/**
+* @name Phaser.World#height
+* @property {number} height - Gets or sets the current height of the game world.
+*/
+Object.defineProperty(Phaser.World.prototype, "height", {
+
+ get: function () {
+ return this.bounds.height;
+ },
+
+ set: function (value) {
+ this.bounds.height = value;
+ }
+
+});
+
+/**
+* @name Phaser.World#centerX
+* @property {number} centerX - Gets the X position corresponding to the center point of the world.
+* @readonly
+*/
+Object.defineProperty(Phaser.World.prototype, "centerX", {
+
+ get: function () {
+ return this.bounds.halfWidth;
+ }
+
+});
+
+/**
+* @name Phaser.World#centerY
+* @property {number} centerY - Gets the Y position corresponding to the center point of the world.
+* @readonly
+*/
+Object.defineProperty(Phaser.World.prototype, "centerY", {
+
+ get: function () {
+ return this.bounds.halfHeight;
+ }
+
+});
+
+/**
+* @name Phaser.World#randomX
+* @property {number} randomX - Gets a random integer which is lesser than or equal to the current width of the game world.
+* @readonly
+*/
+Object.defineProperty(Phaser.World.prototype, "randomX", {
+
+ get: function () {
+ return Math.round(Math.random() * this.bounds.width);
+ }
+
+});
+
+/**
+* @name Phaser.World#randomY
+* @property {number} randomY - Gets a random integer which is lesser than or equal to the current height of the game world.
+* @readonly
+*/
+Object.defineProperty(Phaser.World.prototype, "randomY", {
+
+ get: function () {
+ return Math.round(Math.random() * this.bounds.height);
+ }
+
+});
+