diff --git a/build/phaser.js b/build/phaser.js index 29f3cfa6..7266c7ca 100644 --- a/build/phaser.js +++ b/build/phaser.js @@ -18,7 +18,7 @@ * * Phaser - http://www.phaser.io * -* v1.1.3 - Built at: Fri Nov 29 2013 18:20:59 +* v1.1.4 - Built at: Thu Jan 09 2014 18:23:23 * * By Richard Davey http://www.photonstorm.com @photonstorm * @@ -29,7 +29,7 @@ * * Follow Phaser development progress at http://www.photonstorm.com * -* Many thanks to Adam Saltsman (@ADAMATOMIC) for releasing Flixel, from both which Phaser +* Many thanks to Adam Saltsman (@ADAMATOMIC) for releasing Flixel, from which both Phaser * and my love of game development originate. * * "If you want your children to be intelligent, read them fairy tales." @@ -57,8 +57,8 @@ var PIXI = PIXI || {}; */ var Phaser = Phaser || { - VERSION: '1.1.3', - DEV_VERSION: '1.1.3', + VERSION: '1.1.4', + DEV_VERSION: '1.1.4', GAMES: [], AUTO: 0, @@ -342,6 +342,16 @@ function HEXtoRGB(hex) { return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255]; } +/** + * Converts a hex color number to an [R, G, B] array + * + * @method hex2rgb + * @param hex {Number} + */ +PIXI.hex2rgb = function hex2rgb(hex) { + return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255]; +}; + /** * A polyfill for Function.prototype.bind */ @@ -397,112 +407,112 @@ PIXI.mat3 = {}; PIXI.mat3.create = function() { - var matrix = new PIXI.Matrix(9); + var matrix = new PIXI.Matrix(9); - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 1; - matrix[5] = 0; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 1; + matrix[0] = 1; + matrix[1] = 0; + matrix[2] = 0; + matrix[3] = 0; + matrix[4] = 1; + matrix[5] = 0; + matrix[6] = 0; + matrix[7] = 0; + matrix[8] = 1; - return matrix; -} + return matrix; +}; PIXI.mat3.identity = function(matrix) { - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 1; - matrix[5] = 0; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 1; + matrix[0] = 1; + matrix[1] = 0; + matrix[2] = 0; + matrix[3] = 0; + matrix[4] = 1; + matrix[5] = 0; + matrix[6] = 0; + matrix[7] = 0; + matrix[8] = 1; - return matrix; -} + return matrix; +}; PIXI.mat4 = {}; PIXI.mat4.create = function() { - var matrix = new PIXI.Matrix(16); + var matrix = new PIXI.Matrix(16); - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 0; - matrix[5] = 1; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 0; - matrix[9] = 0; - matrix[10] = 1; - matrix[11] = 0; - matrix[12] = 0; - matrix[13] = 0; - matrix[14] = 0; - matrix[15] = 1; + matrix[0] = 1; + matrix[1] = 0; + matrix[2] = 0; + matrix[3] = 0; + matrix[4] = 0; + matrix[5] = 1; + matrix[6] = 0; + matrix[7] = 0; + matrix[8] = 0; + matrix[9] = 0; + matrix[10] = 1; + matrix[11] = 0; + matrix[12] = 0; + matrix[13] = 0; + matrix[14] = 0; + matrix[15] = 1; - return matrix; -} + return matrix; +}; PIXI.mat3.multiply = function (mat, mat2, dest) { - if (!dest) { dest = mat; } + if (!dest) { dest = mat; } - // Cache the matrix values (makes for huge speed increases!) - var a00 = mat[0], a01 = mat[1], a02 = mat[2], - a10 = mat[3], a11 = mat[4], a12 = mat[5], - a20 = mat[6], a21 = mat[7], a22 = mat[8], + // Cache the matrix values (makes for huge speed increases!) + var a00 = mat[0], a01 = mat[1], a02 = mat[2], + a10 = mat[3], a11 = mat[4], a12 = mat[5], + a20 = mat[6], a21 = mat[7], a22 = mat[8], - b00 = mat2[0], b01 = mat2[1], b02 = mat2[2], - b10 = mat2[3], b11 = mat2[4], b12 = mat2[5], - b20 = mat2[6], b21 = mat2[7], b22 = mat2[8]; + b00 = mat2[0], b01 = mat2[1], b02 = mat2[2], + b10 = mat2[3], b11 = mat2[4], b12 = mat2[5], + b20 = mat2[6], b21 = mat2[7], b22 = mat2[8]; - dest[0] = b00 * a00 + b01 * a10 + b02 * a20; - dest[1] = b00 * a01 + b01 * a11 + b02 * a21; - dest[2] = b00 * a02 + b01 * a12 + b02 * a22; + dest[0] = b00 * a00 + b01 * a10 + b02 * a20; + dest[1] = b00 * a01 + b01 * a11 + b02 * a21; + dest[2] = b00 * a02 + b01 * a12 + b02 * a22; - dest[3] = b10 * a00 + b11 * a10 + b12 * a20; - dest[4] = b10 * a01 + b11 * a11 + b12 * a21; - dest[5] = b10 * a02 + b11 * a12 + b12 * a22; + dest[3] = b10 * a00 + b11 * a10 + b12 * a20; + dest[4] = b10 * a01 + b11 * a11 + b12 * a21; + dest[5] = b10 * a02 + b11 * a12 + b12 * a22; - dest[6] = b20 * a00 + b21 * a10 + b22 * a20; - dest[7] = b20 * a01 + b21 * a11 + b22 * a21; - dest[8] = b20 * a02 + b21 * a12 + b22 * a22; + dest[6] = b20 * a00 + b21 * a10 + b22 * a20; + dest[7] = b20 * a01 + b21 * a11 + b22 * a21; + dest[8] = b20 * a02 + b21 * a12 + b22 * a22; - return dest; -} + return dest; +}; PIXI.mat3.clone = function(mat) { - var matrix = new PIXI.Matrix(9); + var matrix = new PIXI.Matrix(9); - matrix[0] = mat[0]; - matrix[1] = mat[1]; - matrix[2] = mat[2]; - matrix[3] = mat[3]; - matrix[4] = mat[4]; - matrix[5] = mat[5]; - matrix[6] = mat[6]; - matrix[7] = mat[7]; - matrix[8] = mat[8]; + matrix[0] = mat[0]; + matrix[1] = mat[1]; + matrix[2] = mat[2]; + matrix[3] = mat[3]; + matrix[4] = mat[4]; + matrix[5] = mat[5]; + matrix[6] = mat[6]; + matrix[7] = mat[7]; + matrix[8] = mat[8]; - return matrix; -} + return matrix; +}; PIXI.mat3.transpose = function (mat, dest) { - // If we are transposing ourselves we can skip a few steps but have to cache some values + // If we are transposing ourselves we can skip a few steps but have to cache some values if (!dest || mat === dest) { var a01 = mat[1], a02 = mat[2], a12 = mat[5]; @@ -526,34 +536,34 @@ PIXI.mat3.transpose = function (mat, dest) dest[7] = mat[5]; dest[8] = mat[8]; return dest; -} +}; PIXI.mat3.toMat4 = function (mat, dest) { - if (!dest) { dest = PIXI.mat4.create(); } + if (!dest) { dest = PIXI.mat4.create(); } - dest[15] = 1; - dest[14] = 0; - dest[13] = 0; - dest[12] = 0; + dest[15] = 1; + dest[14] = 0; + dest[13] = 0; + dest[12] = 0; - dest[11] = 0; - dest[10] = mat[8]; - dest[9] = mat[7]; - dest[8] = mat[6]; + dest[11] = 0; + dest[10] = mat[8]; + dest[9] = mat[7]; + dest[8] = mat[6]; - dest[7] = 0; - dest[6] = mat[5]; - dest[5] = mat[4]; - dest[4] = mat[3]; + dest[7] = 0; + dest[6] = mat[5]; + dest[5] = mat[4]; + dest[4] = mat[3]; - dest[3] = 0; - dest[2] = mat[2]; - dest[1] = mat[1]; - dest[0] = mat[0]; + dest[3] = 0; + dest[2] = mat[2]; + dest[1] = mat[1]; + dest[0] = mat[0]; - return dest; -} + return dest; +}; ///// @@ -561,82 +571,82 @@ PIXI.mat3.toMat4 = function (mat, dest) PIXI.mat4.create = function() { - var matrix = new PIXI.Matrix(16); + var matrix = new PIXI.Matrix(16); - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 0; - matrix[5] = 1; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 0; - matrix[9] = 0; - matrix[10] = 1; - matrix[11] = 0; - matrix[12] = 0; - matrix[13] = 0; - matrix[14] = 0; - matrix[15] = 1; + matrix[0] = 1; + matrix[1] = 0; + matrix[2] = 0; + matrix[3] = 0; + matrix[4] = 0; + matrix[5] = 1; + matrix[6] = 0; + matrix[7] = 0; + matrix[8] = 0; + matrix[9] = 0; + matrix[10] = 1; + matrix[11] = 0; + matrix[12] = 0; + matrix[13] = 0; + matrix[14] = 0; + matrix[15] = 1; - return matrix; -} + return matrix; +}; PIXI.mat4.transpose = function (mat, dest) { - // If we are transposing ourselves we can skip a few steps but have to cache some values - if (!dest || mat === dest) - { - var a01 = mat[1], a02 = mat[2], a03 = mat[3], - a12 = mat[6], a13 = mat[7], - a23 = mat[11]; + // If we are transposing ourselves we can skip a few steps but have to cache some values + if (!dest || mat === dest) + { + var a01 = mat[1], a02 = mat[2], a03 = mat[3], + a12 = mat[6], a13 = mat[7], + a23 = mat[11]; - mat[1] = mat[4]; - mat[2] = mat[8]; - mat[3] = mat[12]; - mat[4] = a01; - mat[6] = mat[9]; - mat[7] = mat[13]; - mat[8] = a02; - mat[9] = a12; - mat[11] = mat[14]; - mat[12] = a03; - mat[13] = a13; - mat[14] = a23; - return mat; - } + mat[1] = mat[4]; + mat[2] = mat[8]; + mat[3] = mat[12]; + mat[4] = a01; + mat[6] = mat[9]; + mat[7] = mat[13]; + mat[8] = a02; + mat[9] = a12; + mat[11] = mat[14]; + mat[12] = a03; + mat[13] = a13; + mat[14] = a23; + return mat; + } - dest[0] = mat[0]; - dest[1] = mat[4]; - dest[2] = mat[8]; - dest[3] = mat[12]; - dest[4] = mat[1]; - dest[5] = mat[5]; - dest[6] = mat[9]; - dest[7] = mat[13]; - dest[8] = mat[2]; - dest[9] = mat[6]; - dest[10] = mat[10]; - dest[11] = mat[14]; - dest[12] = mat[3]; - dest[13] = mat[7]; - dest[14] = mat[11]; - dest[15] = mat[15]; - return dest; -} + dest[0] = mat[0]; + dest[1] = mat[4]; + dest[2] = mat[8]; + dest[3] = mat[12]; + dest[4] = mat[1]; + dest[5] = mat[5]; + dest[6] = mat[9]; + dest[7] = mat[13]; + dest[8] = mat[2]; + dest[9] = mat[6]; + dest[10] = mat[10]; + dest[11] = mat[14]; + dest[12] = mat[3]; + dest[13] = mat[7]; + dest[14] = mat[11]; + dest[15] = mat[15]; + return dest; +}; PIXI.mat4.multiply = function (mat, mat2, dest) { - if (!dest) { dest = mat; } + if (!dest) { dest = mat; } - // Cache the matrix values (makes for huge speed increases!) - var a00 = mat[ 0], a01 = mat[ 1], a02 = mat[ 2], a03 = mat[3]; - var a10 = mat[ 4], a11 = mat[ 5], a12 = mat[ 6], a13 = mat[7]; - var a20 = mat[ 8], a21 = mat[ 9], a22 = mat[10], a23 = mat[11]; - var a30 = mat[12], a31 = mat[13], a32 = mat[14], a33 = mat[15]; + // Cache the matrix values (makes for huge speed increases!) + var a00 = mat[ 0], a01 = mat[ 1], a02 = mat[ 2], a03 = mat[3]; + var a10 = mat[ 4], a11 = mat[ 5], a12 = mat[ 6], a13 = mat[7]; + var a20 = mat[ 8], a21 = mat[ 9], a22 = mat[10], a23 = mat[11]; + var a30 = mat[12], a31 = mat[13], a32 = mat[14], a33 = mat[15]; - // Cache only the current line of the second matrix + // Cache only the current line of the second matrix var b0 = mat2[0], b1 = mat2[1], b2 = mat2[2], b3 = mat2[3]; dest[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30; dest[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31; @@ -671,7 +681,7 @@ PIXI.mat4.multiply = function (mat, mat2, dest) dest[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33; return dest; -} +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 @@ -687,20 +697,20 @@ PIXI.mat4.multiply = function (mat, mat2, dest) */ PIXI.Point = function(x, y) { - /** - * @property x - * @type Number - * @default 0 - */ - this.x = x || 0; + /** + * @property x + * @type Number + * @default 0 + */ + this.x = x || 0; - /** - * @property y - * @type Number - * @default 0 - */ - this.y = y || 0; -} + /** + * @property y + * @type Number + * @default 0 + */ + this.y = y || 0; +}; /** * Creates a clone of this point @@ -710,8 +720,8 @@ PIXI.Point = function(x, y) */ PIXI.Point.prototype.clone = function() { - return new PIXI.Point(this.x, this.y); -} + return new PIXI.Point(this.x, this.y); +}; // constructor PIXI.Point.prototype.constructor = PIXI.Point; @@ -733,34 +743,34 @@ PIXI.Point.prototype.constructor = PIXI.Point; */ PIXI.Rectangle = function(x, y, width, height) { - /** - * @property x - * @type Number - * @default 0 - */ - this.x = x || 0; + /** + * @property x + * @type Number + * @default 0 + */ + this.x = x || 0; - /** - * @property y - * @type Number - * @default 0 - */ - this.y = y || 0; + /** + * @property y + * @type Number + * @default 0 + */ + this.y = y || 0; - /** - * @property width - * @type Number - * @default 0 - */ - this.width = width || 0; + /** + * @property width + * @type Number + * @default 0 + */ + this.width = width || 0; - /** - * @property height - * @type Number - * @default 0 - */ - this.height = height || 0; -} + /** + * @property height + * @type Number + * @default 0 + */ + this.height = height || 0; +}; /** * Creates a clone of this Rectangle @@ -770,8 +780,8 @@ PIXI.Rectangle = function(x, y, width, height) */ PIXI.Rectangle.prototype.clone = function() { - return new PIXI.Rectangle(this.x, this.y, this.width, this.height); -} + return new PIXI.Rectangle(this.x, this.y, this.width, this.height); +}; /** * Checks if the x, and y coords passed to this function are contained within this Rectangle @@ -786,19 +796,19 @@ PIXI.Rectangle.prototype.contains = function(x, y) if(this.width <= 0 || this.height <= 0) return false; - var x1 = this.x; - if(x >= x1 && x <= x1 + this.width) - { - var y1 = this.y; + var x1 = this.x; + if(x >= x1 && x <= x1 + this.width) + { + var y1 = this.y; - if(y >= y1 && y <= y1 + this.height) - { - return true; - } - } + if(y >= y1 && y <= y1 + this.height) + { + return true; + } + } - return false; -} + return false; +}; // constructor PIXI.Rectangle.prototype.constructor = PIXI.Rectangle; @@ -835,8 +845,8 @@ PIXI.Polygon = function(points) points = p; } - this.points = points; -} + this.points = points; +}; /** * Creates a clone of this polygon @@ -846,13 +856,13 @@ PIXI.Polygon = function(points) */ PIXI.Polygon.prototype.clone = function() { - var points = []; - for (var i=0; i y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi); + 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; @@ -894,236 +904,238 @@ PIXI.Polygon.prototype.constructor = PIXI.Polygon; */ PIXI.DisplayObject = function() { - this.last = this; - this.first = this; - /** - * The coordinate of the object relative to the local coordinates of the parent. - * - * @property position - * @type Point - */ - this.position = new PIXI.Point(); + this.last = this; + this.first = this; + /** + * The coordinate of the object relative to the local coordinates of the parent. + * + * @property position + * @type Point + */ + this.position = new PIXI.Point(); - /** - * The scale factor of the object. - * - * @property scale - * @type Point - */ - this.scale = new PIXI.Point(1,1);//{x:1, y:1}; + /** + * The scale factor of the object. + * + * @property scale + * @type Point + */ + this.scale = new PIXI.Point(1,1);//{x:1, y:1}; - /** - * The pivot point of the displayObject that it rotates around - * - * @property pivot - * @type Point - */ - this.pivot = new PIXI.Point(0,0); + /** + * The pivot point of the displayObject that it rotates around + * + * @property pivot + * @type Point + */ + this.pivot = new PIXI.Point(0,0); - /** - * The rotation of the object in radians. - * - * @property rotation - * @type Number - */ - this.rotation = 0; + /** + * The rotation of the object in radians. + * + * @property rotation + * @type Number + */ + this.rotation = 0; - /** - * The opacity of the object. - * - * @property alpha - * @type Number - */ - this.alpha = 1; + /** + * The opacity of the object. + * + * @property alpha + * @type Number + */ + this.alpha = 1; - /** - * The visibility of the object. - * - * @property visible - * @type Boolean - */ - this.visible = true; + /** + * The visibility of the object. + * + * @property visible + * @type Boolean + */ + this.visible = true; - /** - * This is the defined area that will pick up mouse / touch events. It is null by default. - * Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children) - * - * @property hitArea - * @type Rectangle|Circle|Ellipse|Polygon - */ - this.hitArea = null; + /** + * This is the defined area that will pick up mouse / touch events. It is null by default. + * Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children) + * + * @property hitArea + * @type Rectangle|Circle|Ellipse|Polygon + */ + this.hitArea = null; - /** - * This is used to indicate if the displayObject should display a mouse hand cursor on rollover - * - * @property buttonMode - * @type Boolean - */ - this.buttonMode = false; + /** + * This is used to indicate if the displayObject should display a mouse hand cursor on rollover + * + * @property buttonMode + * @type Boolean + */ + this.buttonMode = false; - /** - * Can this object be rendered - * - * @property renderable - * @type Boolean - */ - this.renderable = false; + /** + * Can this object be rendered + * + * @property renderable + * @type Boolean + */ + this.renderable = false; - /** - * [read-only] The display object container that contains this display object. - * - * @property parent - * @type DisplayObjectContainer - * @readOnly - */ - this.parent = null; + /** + * [read-only] The display object container that contains this display object. + * + * @property parent + * @type DisplayObjectContainer + * @readOnly + */ + this.parent = null; - /** - * [read-only] The stage the display object is connected to, or undefined if it is not connected to the stage. - * - * @property stage - * @type Stage - * @readOnly - */ - this.stage = null; + /** + * [read-only] The stage the display object is connected to, or undefined if it is not connected to the stage. + * + * @property stage + * @type Stage + * @readOnly + */ + this.stage = null; - /** - * [read-only] The multiplied alpha of the displayobject - * - * @property worldAlpha - * @type Number - * @readOnly - */ - this.worldAlpha = 1; + /** + * [read-only] The multiplied alpha of the displayobject + * + * @property worldAlpha + * @type Number + * @readOnly + */ + this.worldAlpha = 1; - /** - * [read-only] Whether or not the object is interactive, do not toggle directly! use the `interactive` property - * - * @property _interactive - * @type Boolean - * @readOnly - * @private - */ - this._interactive = false; + /** + * [read-only] Whether or not the object is interactive, do not toggle directly! use the `interactive` property + * + * @property _interactive + * @type Boolean + * @readOnly + * @private + */ + this._interactive = false; - /** - * [read-only] Current transform of the object based on world (parent) factors - * - * @property worldTransform - * @type Mat3 - * @readOnly - * @private - */ - this.worldTransform = PIXI.mat3.create()//mat3.identity(); + this.defaultCursor = 'pointer'; - /** - * [read-only] Current transform of the object locally - * - * @property localTransform - * @type Mat3 - * @readOnly - * @private - */ - this.localTransform = PIXI.mat3.create()//mat3.identity(); + /** + * [read-only] Current transform of the object based on world (parent) factors + * + * @property worldTransform + * @type Mat3 + * @readOnly + * @private + */ + this.worldTransform = PIXI.mat3.create(); //mat3.identity(); - /** - * [NYI] Unkown - * - * @property color - * @type Array<> - * @private - */ - this.color = []; + /** + * [read-only] Current transform of the object locally + * + * @property localTransform + * @type Mat3 + * @readOnly + * @private + */ + this.localTransform = PIXI.mat3.create(); //mat3.identity(); - /** - * [NYI] Holds whether or not this object is dynamic, for rendering optimization - * - * @property dynamic - * @type Boolean - * @private - */ - this.dynamic = true; + /** + * [NYI] Unkown + * + * @property color + * @type Array<> + * @private + */ + this.color = []; - // chach that puppy! - this._sr = 0; - this._cr = 1; + /** + * [NYI] Holds whether or not this object is dynamic, for rendering optimization + * + * @property dynamic + * @type Boolean + * @private + */ + this.dynamic = true; + + // chach that puppy! + this._sr = 0; + this._cr = 1; - this.filterArea = new PIXI.Rectangle(0,0,1,1); - - /* - * MOUSE Callbacks - */ + this.filterArea = new PIXI.Rectangle(0,0,1,1); - /** - * A callback that is used when the users clicks on the displayObject with their mouse - * @method click - * @param interactionData {InteractionData} - */ + /* + * MOUSE Callbacks + */ - /** - * A callback that is used when the user clicks the mouse down over the sprite - * @method mousedown - * @param interactionData {InteractionData} - */ + /** + * A callback that is used when the users clicks on the displayObject with their mouse + * @method click + * @param interactionData {InteractionData} + */ - /** - * A callback that is used when the user releases the mouse that was over the displayObject - * for this callback to be fired the mouse must have been pressed down over the displayObject - * @method mouseup - * @param interactionData {InteractionData} - */ + /** + * A callback that is used when the user clicks the mouse down over the sprite + * @method mousedown + * @param interactionData {InteractionData} + */ - /** - * A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject - * for this callback to be fired, The touch must have started over the displayObject - * @method mouseupoutside - * @param interactionData {InteractionData} - */ + /** + * A callback that is used when the user releases the mouse that was over the displayObject + * for this callback to be fired the mouse must have been pressed down over the displayObject + * @method mouseup + * @param interactionData {InteractionData} + */ - /** - * A callback that is used when the users mouse rolls over the displayObject - * @method mouseover - * @param interactionData {InteractionData} - */ + /** + * A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject + * for this callback to be fired, The touch must have started over the displayObject + * @method mouseupoutside + * @param interactionData {InteractionData} + */ - /** - * A callback that is used when the users mouse leaves the displayObject - * @method mouseout - * @param interactionData {InteractionData} - */ + /** + * A callback that is used when the users mouse rolls over the displayObject + * @method mouseover + * @param interactionData {InteractionData} + */ + + /** + * A callback that is used when the users mouse leaves the displayObject + * @method mouseout + * @param interactionData {InteractionData} + */ - /* - * TOUCH Callbacks - */ + /* + * TOUCH Callbacks + */ - /** - * A callback that is used when the users taps on the sprite with their finger - * basically a touch version of click - * @method tap - * @param interactionData {InteractionData} - */ + /** + * A callback that is used when the users taps on the sprite with their finger + * basically a touch version of click + * @method tap + * @param interactionData {InteractionData} + */ - /** - * A callback that is used when the user touch's over the displayObject - * @method touchstart - * @param interactionData {InteractionData} - */ + /** + * A callback that is used when the user touch's over the displayObject + * @method touchstart + * @param interactionData {InteractionData} + */ - /** - * A callback that is used when the user releases a touch over the displayObject - * @method touchend - * @param interactionData {InteractionData} - */ + /** + * A callback that is used when the user releases a touch over the displayObject + * @method touchend + * @param interactionData {InteractionData} + */ - /** - * A callback that is used when the user releases the touch that was over the displayObject - * for this callback to be fired, The touch must have started over the sprite - * @method touchendoutside - * @param interactionData {InteractionData} - */ -} + /** + * A callback that is used when the user releases the touch that was over the displayObject + * for this callback to be fired, The touch must have started over the sprite + * @method touchendoutside + * @param interactionData {InteractionData} + */ +}; // constructor PIXI.DisplayObject.prototype.constructor = PIXI.DisplayObject; @@ -1138,8 +1150,8 @@ PIXI.DisplayObject.prototype.constructor = PIXI.DisplayObject; */ PIXI.DisplayObject.prototype.setInteractive = function(interactive) { - this.interactive = interactive; -} + this.interactive = interactive; +}; /** * Indicates if the sprite will have touch and mouse interactivity. It is false by default @@ -1153,11 +1165,11 @@ Object.defineProperty(PIXI.DisplayObject.prototype, 'interactive', { return this._interactive; }, set: function(value) { - this._interactive = value; - - // TODO more to be done here.. - // need to sort out a re-crawl! - if(this.stage)this.stage.dirty = true; + this._interactive = value; + + // TODO more to be done here.. + // need to sort out a re-crawl! + if(this.stage)this.stage.dirty = true; } }); @@ -1174,33 +1186,33 @@ Object.defineProperty(PIXI.DisplayObject.prototype, 'mask', { return this._mask; }, set: function(value) { - - + + if(value) { - if(this._mask) - { - value.start = this._mask.start; - value.end = this._mask.end; - } - else - { - this.addFilter(value); - value.renderable = false; - } + if(this._mask) + { + value.start = this._mask.start; + value.end = this._mask.end; + } + else + { + this.addFilter(value); + value.renderable = false; + } } else { - this.removeFilter(this._mask); - this._mask.renderable = true; + this.removeFilter(this._mask); + this._mask.renderable = true; } - + this._mask = value; } }); /** - * Sets the filters for the displayObject. + * Sets the filters for the displayObject. * * IMPORTANT: This is a webGL only feature and will be ignored by the canvas renderer. * To remove filters simply set this property to 'null' * @property filters @@ -1211,35 +1223,33 @@ Object.defineProperty(PIXI.DisplayObject.prototype, 'filters', { return this._filters; }, set: function(value) { - + if(value) { - if(this._filters)this.removeFilter(this._filters); - this.addFilter(value); + if(this._filters)this.removeFilter(this._filters); + this.addFilter(value); - // now put all the passes in one place.. - var passes = []; - for (var i = 0; i < value.length; i++) - { - var filterPasses = value[i].passes; - for (var j = 0; j < filterPasses.length; j++) - { - passes.push(filterPasses[j]); - }; - }; + // now put all the passes in one place.. + var passes = []; + for (var i = 0; i < value.length; i++) + { + var filterPasses = value[i].passes; + for (var j = 0; j < filterPasses.length; j++) + { + passes.push(filterPasses[j]); + } + } - value.start.filterPasses = passes; + value.start.filterPasses = passes; } else { - if(this._filters)this.removeFilter(this._filters); + if(this._filters) { + this.removeFilter(this._filters); + } } - + this._filters = value; - - - - } }); @@ -1252,97 +1262,99 @@ Object.defineProperty(PIXI.DisplayObject.prototype, 'filters', { */ PIXI.DisplayObject.prototype.addFilter = function(data) { + //if(this.filter)return; + //this.filter = true; +// data[0].target = this; - // insert a filter block.. - // TODO Onject pool thease bad boys.. - var start = new PIXI.FilterBlock(); - var end = new PIXI.FilterBlock(); - - data.start = start; - data.end = end; - - start.data = data; - end.data = data; - - start.first = start.last = this; - end.first = end.last = this; - - start.open = true; - - start.target = this; - - /* - * insert start - */ - - var childFirst = start - var childLast = start - var nextObject; - var previousObject; - - previousObject = this.first._iPrev; - - if(previousObject) - { - nextObject = previousObject._iNext; - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; - } - else - { - nextObject = this; - } - - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - - // now insert the end filter block.. - - /* - * insert end filter - */ - var childFirst = end - var childLast = end - var nextObject = null; - var previousObject = null; - - previousObject = this.last; - nextObject = previousObject._iNext; - - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; - - var updateLast = this; - - var prevLast = this.last; - while(updateLast) - { - if(updateLast.last == prevLast) - { - updateLast.last = end; - } - updateLast = updateLast.parent; - } - - this.first = start; - - // if webGL... - if(this.__renderGroup) - { - this.__renderGroup.addFilterBlocks(start, end); - } - -} + + // insert a filter block.. + // TODO Onject pool thease bad boys.. + var start = new PIXI.FilterBlock(); + var end = new PIXI.FilterBlock(); + + data.start = start; + data.end = end; + + start.data = data; + end.data = data; + + start.first = start.last = this; + end.first = end.last = this; + + start.open = true; + + start.target = this; + + /* + * insert start + */ + + var childFirst = start; + var childLast = start; + var nextObject; + var previousObject; + + previousObject = this.first._iPrev; + + if(previousObject) + { + nextObject = previousObject._iNext; + childFirst._iPrev = previousObject; + previousObject._iNext = childFirst; + } + else + { + nextObject = this; + } + + if(nextObject) + { + nextObject._iPrev = childLast; + childLast._iNext = nextObject; + } + + // now insert the end filter block.. + + /* + * insert end filter + */ + childFirst = end; + childLast = end; + nextObject = null; + previousObject = null; + + previousObject = this.last; + nextObject = previousObject._iNext; + + if(nextObject) + { + nextObject._iPrev = childLast; + childLast._iNext = nextObject; + } + + childFirst._iPrev = previousObject; + previousObject._iNext = childFirst; + + var updateLast = this; + + var prevLast = this.last; + while(updateLast) + { + if(updateLast.last === prevLast) + { + updateLast.last = end; + } + updateLast = updateLast.parent; + } + + this.first = start; + + // if webGL... + if(this.__renderGroup) + { + this.__renderGroup.addFilterBlocks(start, end); + } +}; /* * Removes the filter to this displayObject @@ -1352,47 +1364,47 @@ PIXI.DisplayObject.prototype.addFilter = function(data) */ PIXI.DisplayObject.prototype.removeFilter = function(data) { - //if(!this.filter)return; - //this.filter = false; - console.log("YUOIO") - // modify the list.. - var startBlock = data.start; - - - var nextObject = startBlock._iNext; - var previousObject = startBlock._iPrev; - - if(nextObject)nextObject._iPrev = previousObject; - if(previousObject)previousObject._iNext = nextObject; - - this.first = startBlock._iNext; - - // remove the end filter - var lastBlock = data.end; - - var nextObject = lastBlock._iNext; - var previousObject = lastBlock._iPrev; - - if(nextObject)nextObject._iPrev = previousObject; - previousObject._iNext = nextObject; - - // this is always true too! - var tempLast = lastBlock._iPrev; - // need to make sure the parents last is updated too - var updateLast = this; - while(updateLast.last == lastBlock) - { - updateLast.last = tempLast; - updateLast = updateLast.parent; - if(!updateLast)break; - } - - // if webGL... - if(this.__renderGroup) - { - this.__renderGroup.removeFilterBlocks(startBlock, lastBlock); - } -} + //if(!this.filter)return; + //this.filter = false; + // console.log('YUOIO') + // modify the list.. + var startBlock = data.start; + + + var nextObject = startBlock._iNext; + var previousObject = startBlock._iPrev; + + if(nextObject)nextObject._iPrev = previousObject; + if(previousObject)previousObject._iNext = nextObject; + + this.first = startBlock._iNext; + + // remove the end filter + var lastBlock = data.end; + + nextObject = lastBlock._iNext; + previousObject = lastBlock._iPrev; + + if(nextObject)nextObject._iPrev = previousObject; + previousObject._iNext = nextObject; + + // this is always true too! + var tempLast = lastBlock._iPrev; + // need to make sure the parents last is updated too + var updateLast = this; + while(updateLast.last === lastBlock) + { + updateLast.last = tempLast; + updateLast = updateLast.parent; + if(!updateLast)break; + } + + // if webGL... + if(this.__renderGroup) + { + this.__renderGroup.removeFilterBlocks(startBlock, lastBlock); + } +}; /* * Updates the object transform for rendering @@ -1402,28 +1414,28 @@ PIXI.DisplayObject.prototype.removeFilter = function(data) */ PIXI.DisplayObject.prototype.updateTransform = function() { - // TODO OPTIMIZE THIS!! with dirty - if(this.rotation !== this.rotationCache) - { - this.rotationCache = this.rotation; - this._sr = Math.sin(this.rotation); - this._cr = Math.cos(this.rotation); - } - - var localTransform = this.localTransform; - var parentTransform = this.parent.worldTransform; - var worldTransform = this.worldTransform; - //console.log(localTransform) - localTransform[0] = this._cr * this.scale.x; - localTransform[1] = -this._sr * this.scale.y - localTransform[3] = this._sr * this.scale.x; - localTransform[4] = this._cr * this.scale.y; - - // TODO --> do we even need a local matrix??? - - var px = this.pivot.x; - var py = this.pivot.y; - + // TODO OPTIMIZE THIS!! with dirty + if(this.rotation !== this.rotationCache) + { + this.rotationCache = this.rotation; + this._sr = Math.sin(this.rotation); + this._cr = Math.cos(this.rotation); + } + + var localTransform = this.localTransform; + var parentTransform = this.parent.worldTransform; + var worldTransform = this.worldTransform; + //console.log(localTransform) + localTransform[0] = this._cr * this.scale.x; + localTransform[1] = -this._sr * this.scale.y; + localTransform[3] = this._sr * this.scale.x; + localTransform[4] = this._cr * this.scale.y; + + // TODO --> do we even need a local matrix??? + + var px = this.pivot.x; + var py = this.pivot.y; + // Cache the matrix values (makes for huge speed increases!) var a00 = localTransform[0], a01 = localTransform[1], a02 = this.position.x - localTransform[0] * px - py * localTransform[1], a10 = localTransform[3], a11 = localTransform[4], a12 = this.position.y - localTransform[4] * py - px * localTransform[3], @@ -1431,9 +1443,9 @@ PIXI.DisplayObject.prototype.updateTransform = function() b00 = parentTransform[0], b01 = parentTransform[1], b02 = parentTransform[2], b10 = parentTransform[3], b11 = parentTransform[4], b12 = parentTransform[5]; - localTransform[2] = a02 - localTransform[5] = a12 - + localTransform[2] = a02; + localTransform[5] = a12; + worldTransform[0] = b00 * a00 + b01 * a10; worldTransform[1] = b00 * a01 + b01 * a11; worldTransform[2] = b00 * a02 + b01 * a12 + b02; @@ -1442,13 +1454,12 @@ PIXI.DisplayObject.prototype.updateTransform = function() worldTransform[4] = b10 * a01 + b11 * a11; worldTransform[5] = b10 * a02 + b11 * a12 + b12; - // because we are using affine transformation, we can optimise the matrix concatenation process.. wooo! - // mat3.multiply(this.localTransform, this.parent.worldTransform, this.worldTransform); - this.worldAlpha = this.alpha * this.parent.worldAlpha; - - this.vcount = PIXI.visibleCount; + // because we are using affine transformation, we can optimise the matrix concatenation process.. wooo! + // mat3.multiply(this.localTransform, this.parent.worldTransform, this.worldTransform); + this.worldAlpha = this.alpha * this.parent.worldAlpha; -} + this.vcount = PIXI.visibleCount; +}; PIXI.visibleCount = 0; /** @@ -1460,23 +1471,23 @@ PIXI.visibleCount = 0; * A DisplayObjectContainer represents a collection of display objects. * It is the base class of all display objects that act as a container for other objects. * - * @class DisplayObjectContainer + * @class DisplayObjectContainer * @extends DisplayObject * @constructor */ PIXI.DisplayObjectContainer = function() { - PIXI.DisplayObject.call( this ); - - /** - * [read-only] The of children of this container. - * - * @property children - * @type Array - * @readOnly - */ - this.children = []; -} + PIXI.DisplayObject.call( this ); + + /** + * [read-only] The of children of this container. + * + * @property children + * @type Array + * @readOnly + */ + this.children = []; +}; // constructor PIXI.DisplayObjectContainer.prototype = Object.create( PIXI.DisplayObject.prototype ); @@ -1490,85 +1501,83 @@ PIXI.DisplayObjectContainer.prototype.constructor = PIXI.DisplayObjectContainer; */ PIXI.DisplayObjectContainer.prototype.addChild = function(child) { - if(child.parent != undefined) - { - - //// COULD BE THIS??? - child.parent.removeChild(child); - // return; - } + if(child.parent && child.parent !== this) + { + //// COULD BE THIS??? + child.parent.removeChild(child); + // return; + } - child.parent = this; - - this.children.push(child); - - // update the stage refference.. - - if(this.stage) - { - var tmpChild = child; - do - { - if(tmpChild.interactive)this.stage.dirty = true; - tmpChild.stage = this.stage; - tmpChild = tmpChild._iNext; - } - while(tmpChild) - } - - // LINKED LIST // - - // modify the list.. - var childFirst = child.first - var childLast = child.last; - var nextObject; - var previousObject; - - // this could be wrong if there is a filter?? - if(this._filters || this._mask) - { - previousObject = this.last._iPrev; - } - else - { - previousObject = this.last; - } + child.parent = this; - nextObject = previousObject._iNext; - - // always true in this case - // need to make sure the parents last is updated too - var updateLast = this; - var prevLast = previousObject; - - while(updateLast) - { - if(updateLast.last == prevLast) - { - updateLast.last = child.last; - } - updateLast = updateLast.parent; - } - - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; + this.children.push(child); - // need to remove any render groups.. - if(this.__renderGroup) - { - // being used by a renderTexture.. if it exists then it must be from a render texture; - if(child.__renderGroup)child.__renderGroup.removeDisplayObjectAndChildren(child); - // add them to the new render group.. - this.__renderGroup.addDisplayObjectAndChildren(child); - } - -} + // update the stage refference.. + + if(this.stage) + { + var tmpChild = child; + do + { + if(tmpChild.interactive)this.stage.dirty = true; + tmpChild.stage = this.stage; + tmpChild = tmpChild._iNext; + } + while(tmpChild); + } + + // LINKED LIST // + + // modify the list.. + var childFirst = child.first; + var childLast = child.last; + var nextObject; + var previousObject; + + // this could be wrong if there is a filter?? + if(this._filters || this._mask) + { + previousObject = this.last._iPrev; + } + else + { + previousObject = this.last; + } + + nextObject = previousObject._iNext; + + // always true in this case + // need to make sure the parents last is updated too + var updateLast = this; + var prevLast = previousObject; + + while(updateLast) + { + if(updateLast.last === prevLast) + { + updateLast.last = child.last; + } + updateLast = updateLast.parent; + } + + if(nextObject) + { + nextObject._iPrev = childLast; + childLast._iNext = nextObject; + } + + childFirst._iPrev = previousObject; + previousObject._iNext = childFirst; + + // need to remove any render groups.. + if(this.__renderGroup) + { + // being used by a renderTexture.. if it exists then it must be from a render texture; + if(child.__renderGroup)child.__renderGroup.removeDisplayObjectAndChildren(child); + // add them to the new render group.. + this.__renderGroup.addDisplayObjectAndChildren(child); + } +}; /** * Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown @@ -1579,83 +1588,84 @@ PIXI.DisplayObjectContainer.prototype.addChild = function(child) */ PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index) { - if(index >= 0 && index <= this.children.length) - { - if(child.parent != undefined) - { - child.parent.removeChild(child); - } - child.parent = this; - - if(this.stage) - { - var tmpChild = child; - do - { - if(tmpChild.interactive)this.stage.dirty = true; - tmpChild.stage = this.stage; - tmpChild = tmpChild._iNext; - } - while(tmpChild) - } - - // modify the list.. - var childFirst = child.first; - var childLast = child.last; - var nextObject; - var previousObject; - - if(index == this.children.length) - { - previousObject = this.last; - var updateLast = this; - var prevLast = this.last; - while(updateLast) - { - if(updateLast.last == prevLast) - { - updateLast.last = child.last; - } - updateLast = updateLast.parent; - } - } - else if(index === 0) - { - previousObject = this; - } - else - { - previousObject = this.children[index-1].last; - } - - nextObject = previousObject._iNext; - - // always true in this case - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; + if(index >= 0 && index <= this.children.length) + { + if(child.parent !== undefined) + { + child.parent.removeChild(child); + } - this.children.splice(index, 0, child); - // need to remove any render groups.. - if(this.__renderGroup) - { - // being used by a renderTexture.. if it exists then it must be from a render texture; - if(child.__renderGroup)child.__renderGroup.removeDisplayObjectAndChildren(child); - // add them to the new render group.. - this.__renderGroup.addDisplayObjectAndChildren(child); - } - - } - else - { - throw new Error(child + " The index "+ index +" supplied is out of bounds " + this.children.length); - } -} + child.parent = this; + + if(this.stage) + { + var tmpChild = child; + do + { + if(tmpChild.interactive)this.stage.dirty = true; + tmpChild.stage = this.stage; + tmpChild = tmpChild._iNext; + } + while(tmpChild); + } + + // modify the list.. + var childFirst = child.first; + var childLast = child.last; + var nextObject; + var previousObject; + + if(index === this.children.length) + { + previousObject = this.last; + var updateLast = this; + var prevLast = this.last; + while(updateLast) + { + if(updateLast.last === prevLast) + { + updateLast.last = child.last; + } + updateLast = updateLast.parent; + } + } + else if(index === 0) + { + previousObject = this; + } + else + { + previousObject = this.children[index-1].last; + } + + nextObject = previousObject._iNext; + + // always true in this case + if(nextObject) + { + nextObject._iPrev = childLast; + childLast._iNext = nextObject; + } + + childFirst._iPrev = previousObject; + previousObject._iNext = childFirst; + + this.children.splice(index, 0, child); + // need to remove any render groups.. + if(this.__renderGroup) + { + // being used by a renderTexture.. if it exists then it must be from a render texture; + if(child.__renderGroup)child.__renderGroup.removeDisplayObjectAndChildren(child); + // add them to the new render group.. + this.__renderGroup.addDisplayObjectAndChildren(child); + } + + } + else + { + throw new Error(child + ' The index '+ index +' supplied is out of bounds ' + this.children.length); + } +}; /** * [NYI] Swaps the depth of 2 displayObjects @@ -1667,44 +1677,31 @@ PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index) */ PIXI.DisplayObjectContainer.prototype.swapChildren = function(child, child2) { - /* - * this funtion needs to be recoded.. - * can be done a lot faster.. - */ - return; - - // need to fix this function :/ - /* - // TODO I already know this?? - var index = this.children.indexOf( child ); - var index2 = this.children.indexOf( child2 ); - - if ( index !== -1 && index2 !== -1 ) - { - // cool - - /* - if(this.stage) - { - // this is to satisfy the webGL batching.. - // TODO sure there is a nicer way to achieve this! - this.stage.__removeChild(child); - this.stage.__removeChild(child2); - - this.stage.__addChild(child); - this.stage.__addChild(child2); - } - - // swap the positions.. - this.children[index] = child2; - this.children[index2] = child; - - } - else - { - throw new Error(child + " Both the supplied DisplayObjects must be a child of the caller " + this); - }*/ -} + if(child === child2) { + return; + } + + var index1 = this.children.indexOf(child); + var index2 = this.children.indexOf(child2); + + if(index1 < 0 || index2 < 0) { + throw new Error('swapChildren: Both the supplied DisplayObjects must be a child of the caller.'); + } + + this.removeChild(child); + this.removeChild(child2); + + if(index1 < index2) + { + this.addChildAt(child2, index1); + this.addChildAt(child, index2); + } + else + { + this.addChildAt(child, index2); + this.addChildAt(child2, index1); + } +}; /** * Returns the Child at the specified index @@ -1714,15 +1711,15 @@ PIXI.DisplayObjectContainer.prototype.swapChildren = function(child, child2) */ PIXI.DisplayObjectContainer.prototype.getChildAt = function(index) { - if(index >= 0 && index < this.children.length) - { - return this.children[index]; - } - else - { - throw new Error(child + " Both the supplied DisplayObjects must be a child of the caller " + this); - } -} + if(index >= 0 && index < this.children.length) + { + return this.children[index]; + } + else + { + throw new Error('Both the supplied DisplayObjects must be a child of the caller ' + this); + } +}; /** * Removes a child from the container. @@ -1732,63 +1729,65 @@ PIXI.DisplayObjectContainer.prototype.getChildAt = function(index) */ PIXI.DisplayObjectContainer.prototype.removeChild = function(child) { - var index = this.children.indexOf( child ); - if ( index !== -1 ) - { - // unlink // - // modify the list.. - var childFirst = child.first; - var childLast = child.last; - - var nextObject = childLast._iNext; - var previousObject = childFirst._iPrev; - - if(nextObject)nextObject._iPrev = previousObject; - previousObject._iNext = nextObject; - - if(this.last == childLast) - { - var tempLast = childFirst._iPrev; - // need to make sure the parents last is updated too - var updateLast = this; - while(updateLast.last == childLast.last) - { - updateLast.last = tempLast; - updateLast = updateLast.parent; - if(!updateLast)break; - } - } - - childLast._iNext = null; - childFirst._iPrev = null; - - // update the stage reference.. - if(this.stage) - { - var tmpChild = child; - do - { - if(tmpChild.interactive)this.stage.dirty = true; - tmpChild.stage = null; - tmpChild = tmpChild._iNext; - } - while(tmpChild) - } - - // webGL trim - if(child.__renderGroup) - { - child.__renderGroup.removeDisplayObjectAndChildren(child); - } - - child.parent = undefined; - this.children.splice( index, 1 ); - } - else - { - throw new Error(child + " The supplied DisplayObject must be a child of the caller " + this); - } -} + var index = this.children.indexOf( child ); + if ( index !== -1 ) + { + // unlink // + // modify the list.. + var childFirst = child.first; + var childLast = child.last; + + var nextObject = childLast._iNext; + var previousObject = childFirst._iPrev; + + if(nextObject)nextObject._iPrev = previousObject; + previousObject._iNext = nextObject; + + if(this.last === childLast) + { + var tempLast = childFirst._iPrev; + // need to make sure the parents last is updated too + var updateLast = this; + + while(updateLast.last === childLast) + { + updateLast.last = tempLast; + updateLast = updateLast.parent; + if(!updateLast)break; + + } + } + + childLast._iNext = null; + childFirst._iPrev = null; + + // update the stage reference.. + if(this.stage) + { + var tmpChild = child; + do + { + if(tmpChild.interactive)this.stage.dirty = true; + tmpChild.stage = null; + tmpChild = tmpChild._iNext; + } + while(tmpChild); + } + + // webGL trim + if(child.__renderGroup) + { + child.__renderGroup.removeDisplayObjectAndChildren(child); + } + + child.parent = undefined; + this.children.splice( index, 1 ); + } + else + { + throw new Error(child + ' The supplied DisplayObject must be a child of the caller ' + this); + } +}; /* * Updates the container's children's transform for rendering @@ -1798,15 +1797,16 @@ PIXI.DisplayObjectContainer.prototype.removeChild = function(child) */ PIXI.DisplayObjectContainer.prototype.updateTransform = function() { - if(!this.visible)return; - - PIXI.DisplayObject.prototype.updateTransform.call( this ); - - for(var i=0,j=this.children.length; i 1) ratio = 1; - var ratio = (1 - (i / (total-1))) * 10; - if(ratio > 1)ratio = 1; + perpLength = Math.sqrt(perp.x * perp.x + perp.y * perp.y); + num = this.texture.height / 2; //(20 + Math.abs(Math.sin((i + this.count) * 0.3) * 50) )* ratio; + perp.x /= perpLength; + perp.y /= perpLength; - var perpLength = Math.sqrt(perp.x * perp.x + perp.y * perp.y); - var num = this.texture.height/2//(20 + Math.abs(Math.sin((i + this.count) * 0.3) * 50) )* ratio; - perp.x /= perpLength; - perp.y /= perpLength; + perp.x *= num; + perp.y *= num; - perp.x *= num; - perp.y *= num; + verticies[index] = point.x + perp.x; + verticies[index+1] = point.y + perp.y; + verticies[index+2] = point.x - perp.x; + verticies[index+3] = point.y - perp.y; - verticies[index] = point.x + perp.x - verticies[index+1] = point.y + perp.y - verticies[index+2] = point.x - perp.x - verticies[index+3] = point.y - perp.y + lastPoint = point; + } - lastPoint = point; - } - - PIXI.DisplayObjectContainer.prototype.updateTransform.call( this ); -} + PIXI.DisplayObjectContainer.prototype.updateTransform.call( this ); +}; PIXI.Rope.prototype.setTexture = function(texture) { - // stop current texture - this.texture = texture; - this.updateFrame = true; -} - - - - + // stop current texture + this.texture = texture; + this.updateFrame = true; +}; /** * @author Mat Groves http://matgroves.com/ @@ -2479,52 +2470,52 @@ PIXI.Rope.prototype.setTexture = function(texture) */ PIXI.TilingSprite = function(texture, width, height) { - PIXI.DisplayObjectContainer.call( this ); + PIXI.DisplayObjectContainer.call( this ); - /** - * The texture that the sprite is using - * - * @property texture - * @type Texture - */ - this.texture = texture; + /** + * The texture that the sprite is using + * + * @property texture + * @type Texture + */ + this.texture = texture; - /** - * The width of the tiling sprite - * - * @property width - * @type Number - */ - this.width = width; + /** + * The width of the tiling sprite + * + * @property width + * @type Number + */ + this.width = width; - /** - * The height of the tiling sprite - * - * @property height - * @type Number - */ - this.height = height; + /** + * The height of the tiling sprite + * + * @property height + * @type Number + */ + this.height = height; - /** - * The scaling of the image that is being tiled - * - * @property tileScale - * @type Point - */ - this.tileScale = new PIXI.Point(1,1); + /** + * The scaling of the image that is being tiled + * + * @property tileScale + * @type Point + */ + this.tileScale = new PIXI.Point(1,1); - /** - * The offset position of the image that is being tiled - * - * @property tilePosition - * @type Point - */ - this.tilePosition = new PIXI.Point(0,0); + /** + * The offset position of the image that is being tiled + * + * @property tilePosition + * @type Point + */ + this.tilePosition = new PIXI.Point(0,0); - this.renderable = true; + this.renderable = true; - this.blendMode = PIXI.blendModes.NORMAL -} + this.blendMode = PIXI.blendModes.NORMAL; +}; // constructor PIXI.TilingSprite.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); @@ -2538,13 +2529,13 @@ PIXI.TilingSprite.prototype.constructor = PIXI.TilingSprite; */ PIXI.TilingSprite.prototype.setTexture = function(texture) { - //TODO SET THE TEXTURES - //TODO VISIBILITY + //TODO SET THE TEXTURES + //TODO VISIBILITY - // stop current texture - this.texture = texture; - this.updateFrame = true; -} + // stop current texture + this.texture = texture; + this.updateFrame = true; +}; /** * When the texture is updated, this event will fire to update the frame @@ -2553,49 +2544,46 @@ PIXI.TilingSprite.prototype.setTexture = function(texture) * @param event * @private */ -PIXI.TilingSprite.prototype.onTextureUpdate = function(event) +PIXI.TilingSprite.prototype.onTextureUpdate = function() { - this.updateFrame = true; -} - + this.updateFrame = true; +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ - /** * This is the base class for creating a pixi.js filter. Currently only webGL supports filters. * If you want to make a custom filter this should be your base class. * @class AbstractFilter * @constructor * @param fragmentSrc - * @param uniforms + * @param uniforms */ PIXI.AbstractFilter = function(fragmentSrc, uniforms) { - /** - * An array of passes - some filters contain a few steps this array simply stores the steps in a liniear fashion. - * For example the blur filter has two passes blurX and blurY. - * @property passes - * @type Array an array of filter objects - * @private - */ - this.passes = [this]; + /** + * An array of passes - some filters contain a few steps this array simply stores the steps in a liniear fashion. + * For example the blur filter has two passes blurX and blurY. + * @property passes + * @type Array an array of filter objects + * @private + */ + this.passes = [this]; - this.dirty = true; - this.padding = 0; + this.dirty = true; + this.padding = 0; - /** - @property uniforms - @private - */ - this.uniforms = uniforms || {}; - - this.fragmentSrc = fragmentSrc || []; -} + /** + @property uniforms + @private + */ + this.uniforms = uniforms || {}; + this.fragmentSrc = fragmentSrc || []; +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 @@ -2605,9 +2593,10 @@ PIXI.AbstractFilter = function(fragmentSrc, uniforms) PIXI.FilterBlock = function() { - this.visible = true; - this.renderable = true; -} + this.visible = true; + this.renderable = true; +}; + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2624,52 +2613,52 @@ PIXI.FilterBlock = function() */ PIXI.Graphics = function() { - PIXI.DisplayObjectContainer.call( this ); + PIXI.DisplayObjectContainer.call( this ); - this.renderable = true; + this.renderable = true; /** - * The alpha of the fill of this graphics object - * - * @property fillAlpha - * @type Number - */ - this.fillAlpha = 1; + * The alpha of the fill of this graphics object + * + * @property fillAlpha + * @type Number + */ + this.fillAlpha = 1; /** - * The width of any lines drawn - * - * @property lineWidth - * @type Number - */ - this.lineWidth = 0; + * The width of any lines drawn + * + * @property lineWidth + * @type Number + */ + this.lineWidth = 0; /** - * The color of any lines drawn - * - * @property lineColor - * @type String - */ - this.lineColor = "black"; + * The color of any lines drawn + * + * @property lineColor + * @type String + */ + this.lineColor = "black"; /** - * Graphics data - * - * @property graphicsData - * @type Array - * @private - */ - this.graphicsData = []; + * Graphics data + * + * @property graphicsData + * @type Array + * @private + */ + this.graphicsData = []; /** - * Current path - * - * @property currentPath - * @type Object - * @private - */ - this.currentPath = {points:[]}; -} + * Current path + * + * @property currentPath + * @type Object + * @private + */ + this.currentPath = {points:[]}; +}; // constructor PIXI.Graphics.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); @@ -2685,17 +2674,17 @@ PIXI.Graphics.prototype.constructor = PIXI.Graphics; */ PIXI.Graphics.prototype.lineStyle = function(lineWidth, color, alpha) { - if(this.currentPath.points.length === 0)this.graphicsData.pop(); + if (!this.currentPath.points.length) this.graphicsData.pop(); - this.lineWidth = lineWidth || 0; - this.lineColor = color || 0; - this.lineAlpha = (alpha == undefined) ? 1 : alpha; + this.lineWidth = lineWidth || 0; + this.lineColor = color || 0; + this.lineAlpha = (arguments.length < 3) ? 1 : alpha; - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, points:[], type:PIXI.Graphics.POLY}; + this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, + fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, points:[], type:PIXI.Graphics.POLY}; - this.graphicsData.push(this.currentPath); -} + this.graphicsData.push(this.currentPath); +}; /** * Moves the current drawing position to (x, y). @@ -2706,15 +2695,15 @@ PIXI.Graphics.prototype.lineStyle = function(lineWidth, color, alpha) */ PIXI.Graphics.prototype.moveTo = function(x, y) { - if(this.currentPath.points.length === 0)this.graphicsData.pop(); + if (!this.currentPath.points.length) this.graphicsData.pop(); - this.currentPath = this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, points:[], type:PIXI.Graphics.POLY}; + this.currentPath = this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, + fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, points:[], type:PIXI.Graphics.POLY}; - this.currentPath.points.push(x, y); + this.currentPath.points.push(x, y); - this.graphicsData.push(this.currentPath); -} + this.graphicsData.push(this.currentPath); +}; /** * Draws a line using the current line style from the current drawing position to (x, y); @@ -2726,9 +2715,9 @@ PIXI.Graphics.prototype.moveTo = function(x, y) */ PIXI.Graphics.prototype.lineTo = function(x, y) { - this.currentPath.points.push(x, y); - this.dirty = true; -} + this.currentPath.points.push(x, y); + this.dirty = true; +}; /** * Specifies a simple one-color fill that subsequent calls to other Graphics methods @@ -2740,10 +2729,10 @@ PIXI.Graphics.prototype.lineTo = function(x, y) */ PIXI.Graphics.prototype.beginFill = function(color, alpha) { - this.filling = true; - this.fillColor = color || 0; - this.fillAlpha = (alpha == undefined) ? 1 : alpha; -} + this.filling = true; + this.fillColor = color || 0; + this.fillAlpha = (arguments.length < 2) ? 1 : alpha; +}; /** * Applies a fill to the lines and shapes that were added since the last call to the beginFill() method. @@ -2752,10 +2741,10 @@ PIXI.Graphics.prototype.beginFill = function(color, alpha) */ PIXI.Graphics.prototype.endFill = function() { - this.filling = false; - this.fillColor = null; - this.fillAlpha = 1; -} + this.filling = false; + this.fillColor = null; + this.fillAlpha = 1; +}; /** * @method drawRect @@ -2767,15 +2756,15 @@ PIXI.Graphics.prototype.endFill = function() */ PIXI.Graphics.prototype.drawRect = function( x, y, width, height ) { - if(this.currentPath.points.length === 0)this.graphicsData.pop(); + if (!this.currentPath.points.length) this.graphicsData.pop(); - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, - points:[x, y, width, height], type:PIXI.Graphics.RECT}; + this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, + fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, + points:[x, y, width, height], type:PIXI.Graphics.RECT}; - this.graphicsData.push(this.currentPath); - this.dirty = true; -} + this.graphicsData.push(this.currentPath); + this.dirty = true; +}; /** * Draws a circle. @@ -2787,36 +2776,36 @@ PIXI.Graphics.prototype.drawRect = function( x, y, width, height ) */ PIXI.Graphics.prototype.drawCircle = function( x, y, radius) { - if(this.currentPath.points.length === 0)this.graphicsData.pop(); + if (!this.currentPath.points.length) this.graphicsData.pop(); - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, - points:[x, y, radius, radius], type:PIXI.Graphics.CIRC}; + this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, + fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, + points:[x, y, radius, radius], type:PIXI.Graphics.CIRC}; - this.graphicsData.push(this.currentPath); - this.dirty = true; -} + this.graphicsData.push(this.currentPath); + this.dirty = true; +}; /** - * Draws an elipse. + * Draws an ellipse. * - * @method drawElipse + * @method drawEllipse * @param x {Number} * @param y {Number} * @param width {Number} * @param height {Number} */ -PIXI.Graphics.prototype.drawElipse = function( x, y, width, height) +PIXI.Graphics.prototype.drawEllipse = function( x, y, width, height) { - if(this.currentPath.points.length === 0)this.graphicsData.pop(); + if (!this.currentPath.points.length) this.graphicsData.pop(); - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, - points:[x, y, width, height], type:PIXI.Graphics.ELIP}; + this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, + fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, + points:[x, y, width, height], type:PIXI.Graphics.ELIP}; - this.graphicsData.push(this.currentPath); - this.dirty = true; -} + this.graphicsData.push(this.currentPath); + this.dirty = true; +}; /** * Clears the graphics that were drawn to this Graphics object, and resets fill and line style settings. @@ -2825,88 +2814,83 @@ PIXI.Graphics.prototype.drawElipse = function( x, y, width, height) */ PIXI.Graphics.prototype.clear = function() { - this.lineWidth = 0; - this.filling = false; + this.lineWidth = 0; + this.filling = false; - this.dirty = true; - this.clearDirty = true; - this.graphicsData = []; + this.dirty = true; + this.clearDirty = true; + this.graphicsData = []; - this.bounds = null//new PIXI.Rectangle(); -} + this.bounds = null; //new PIXI.Rectangle(); +}; PIXI.Graphics.prototype.updateFilterBounds = function() { - if(!this.bounds) - { - var minX = Infinity; - var maxX = -Infinity; + if(!this.bounds) + { + var minX = Infinity; + var maxX = -Infinity; - var minY = Infinity; - var maxY = -Infinity; + var minY = Infinity; + var maxY = -Infinity; - var points, x, y; + var points, x, y; - for (var i = 0; i < this.graphicsData.length; i++) { - + for (var i = 0; i < this.graphicsData.length; i++) { + var data = this.graphicsData[i]; + var type = data.type; + var lineWidth = data.lineWidth; - var data = this.graphicsData[i]; - var type = data.type; - var lineWidth = data.lineWidth; + points = data.points; - points = data.points; + if(type === PIXI.Graphics.RECT) + { + x = points.x - lineWidth/2; + y = points.y - lineWidth/2; + var width = points.width + lineWidth; + var height = points.height + lineWidth; - if(type === PIXI.Graphics.RECT) - { - x = points.x - lineWidth/2; - y = points.y - lineWidth/2; - var width = points.width + lineWidth; - var height = points.height + lineWidth; + minX = x < minX ? x : minX; + maxX = x + width > maxX ? x + width : maxX; - minX = x < minX ? x : minX; - maxX = x + width > maxX ? x + width : maxX; + minY = y < minY ? x : minY; + maxY = y + height > maxY ? y + height : maxY; + } + else if(type === PIXI.Graphics.CIRC || type === PIXI.Graphics.ELIP) + { + x = points.x; + y = points.y; + var radius = points.radius + lineWidth/2; - minY = y < minY ? x : minY; - maxY = y + height > maxY ? y + height : maxY; - } - else if(type === PIXI.Graphics.CIRC || type === PIXI.Graphics.ELIP) - { - x = points.x; - y = points.y; - var radius = points.radius + lineWidth/2; - - minX = x - radius < minX ? x - radius : minX; - maxX = x + radius > maxX ? x + radius : maxX; + minX = x - radius < minX ? x - radius : minX; + maxX = x + radius > maxX ? x + radius : maxX; - minY = y - radius < minY ? y - radius : minY; - maxY = y + radius > maxY ? y + radius : maxY; - } - else - { - // POLY - for (var j = 0; j < points.length; j+=2) - { - - x = points[j]; - y = points[j+1]; + minY = y - radius < minY ? y - radius : minY; + maxY = y + radius > maxY ? y + radius : maxY; + } + else + { + // POLY + for (var j = 0; j < points.length; j+=2) + { - minX = x-lineWidth < minX ? x-lineWidth : minX; - maxX = x+lineWidth > maxX ? x+lineWidth : maxX; + x = points[j]; + y = points[j+1]; - minY = y-lineWidth < minY ? y-lineWidth : minY; - maxY = y+lineWidth > maxY ? y+lineWidth : maxY; - }; - } + minX = x-lineWidth < minX ? x-lineWidth : minX; + maxX = x+lineWidth > maxX ? x+lineWidth : maxX; - }; + minY = y-lineWidth < minY ? y-lineWidth : minY; + maxY = y+lineWidth > maxY ? y+lineWidth : maxY; + } + } + } - this.bounds = new PIXI.Rectangle(minX, minY, maxX - minX, maxY - minY); - - } - -// console.log(this.bounds); -} + this.bounds = new PIXI.Rectangle(minX, minY, maxX - minX, maxY - minY); + } +// console.log(this.bounds); +}; // SOME TYPES: PIXI.Graphics.POLY = 0; @@ -2927,7 +2911,7 @@ PIXI.Graphics.ELIP = 3; PIXI.CanvasGraphics = function() { -} +}; /* @@ -2941,128 +2925,128 @@ PIXI.CanvasGraphics = function() */ PIXI.CanvasGraphics.renderGraphics = function(graphics, context) { - var worldAlpha = graphics.worldAlpha; + var worldAlpha = graphics.worldAlpha; + var color = ''; - for (var i=0; i < graphics.graphicsData.length; i++) - { - var data = graphics.graphicsData[i]; - var points = data.points; + for (var i = 0; i < graphics.graphicsData.length; i++) + { + var data = graphics.graphicsData[i]; + var points = data.points; - context.strokeStyle = color = '#' + ('00000' + ( data.lineColor | 0).toString(16)).substr(-6); + context.strokeStyle = color = '#' + ('00000' + ( data.lineColor | 0).toString(16)).substr(-6); - context.lineWidth = data.lineWidth; + context.lineWidth = data.lineWidth; - if(data.type == PIXI.Graphics.POLY) - { - context.beginPath(); + if(data.type === PIXI.Graphics.POLY) + { + context.beginPath(); - context.moveTo(points[0], points[1]); + context.moveTo(points[0], points[1]); - for (var j=1; j < points.length/2; j++) - { - context.lineTo(points[j * 2], points[j * 2 + 1]); - } + for (var j=1; j < points.length/2; j++) + { + context.lineTo(points[j * 2], points[j * 2 + 1]); + } - // if the first and last point are the same close the path - much neater :) - if(points[0] == points[points.length-2] && points[1] == points[points.length-1]) - { - context.closePath(); - } + // if the first and last point are the same close the path - much neater :) + if(points[0] === points[points.length-2] && points[1] === points[points.length-1]) + { + context.closePath(); + } - if(data.fill) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fill(); - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.stroke(); - } - } - else if(data.type == PIXI.Graphics.RECT) - { + if(data.fill) + { + context.globalAlpha = data.fillAlpha * worldAlpha; + context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); + context.fill(); + } + if(data.lineWidth) + { + context.globalAlpha = data.lineAlpha * worldAlpha; + context.stroke(); + } + } + else if(data.type === PIXI.Graphics.RECT) + { - if(data.fillColor || data.fillColor === 0) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fillRect(points[0], points[1], points[2], points[3]); + if(data.fillColor || data.fillColor === 0) + { + context.globalAlpha = data.fillAlpha * worldAlpha; + context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); + context.fillRect(points[0], points[1], points[2], points[3]); - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.strokeRect(points[0], points[1], points[2], points[3]); - } + } + if(data.lineWidth) + { + context.globalAlpha = data.lineAlpha * worldAlpha; + context.strokeRect(points[0], points[1], points[2], points[3]); + } - } - else if(data.type == PIXI.Graphics.CIRC) - { - // TODO - need to be Undefined! - context.beginPath(); - context.arc(points[0], points[1], points[2],0,2*Math.PI); - context.closePath(); + } + else if(data.type === PIXI.Graphics.CIRC) + { + // TODO - need to be Undefined! + context.beginPath(); + context.arc(points[0], points[1], points[2],0,2*Math.PI); + context.closePath(); - if(data.fill) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fill(); - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.stroke(); - } - } - else if(data.type == PIXI.Graphics.ELIP) - { + if(data.fill) + { + context.globalAlpha = data.fillAlpha * worldAlpha; + context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); + context.fill(); + } + if(data.lineWidth) + { + context.globalAlpha = data.lineAlpha * worldAlpha; + context.stroke(); + } + } + else if(data.type === PIXI.Graphics.ELIP) + { - // elipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas + // ellipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas - var elipseData = data.points; + var ellipseData = data.points; - var w = elipseData[2] * 2; - var h = elipseData[3] * 2; + var w = ellipseData[2] * 2; + var h = ellipseData[3] * 2; - var x = elipseData[0] - w/2; - var y = elipseData[1] - h/2; + var x = ellipseData[0] - w/2; + var y = ellipseData[1] - h/2; - context.beginPath(); + context.beginPath(); - var kappa = .5522848, - ox = (w / 2) * kappa, // control point offset horizontal - oy = (h / 2) * kappa, // control point offset vertical - xe = x + w, // x-end - ye = y + h, // y-end - xm = x + w / 2, // x-middle - ym = y + h / 2; // y-middle + var kappa = 0.5522848, + ox = (w / 2) * kappa, // control point offset horizontal + oy = (h / 2) * kappa, // control point offset vertical + xe = x + w, // x-end + ye = y + h, // y-end + xm = x + w / 2, // x-middle + ym = y + h / 2; // y-middle - context.moveTo(x, ym); - context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); - context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); - context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); - context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); + context.moveTo(x, ym); + context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); + context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); + context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); + context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); - context.closePath(); + context.closePath(); - if(data.fill) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fill(); - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.stroke(); - } - } - - }; -} + if(data.fill) + { + context.globalAlpha = data.fillAlpha * worldAlpha; + context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); + context.fill(); + } + if(data.lineWidth) + { + context.globalAlpha = data.lineAlpha * worldAlpha; + context.stroke(); + } + } + } +}; /* * Renders a graphics mask @@ -3075,91 +3059,87 @@ PIXI.CanvasGraphics.renderGraphics = function(graphics, context) */ PIXI.CanvasGraphics.renderGraphicsMask = function(graphics, context) { - var worldAlpha = graphics.worldAlpha; + var len = graphics.graphicsData.length; - var len = graphics.graphicsData.length; - if(len === 0)return; + if(len === 0) return; - if(len > 1) - { - len = 1; - console.log("Pixi.js warning: masks in canvas can only mask using the first path in the graphics object") - } + if(len > 1) + { + len = 1; + window.console.log('Pixi.js warning: masks in canvas can only mask using the first path in the graphics object'); + } - for (var i=0; i < 1; i++) - { - var data = graphics.graphicsData[i]; - var points = data.points; + for (var i = 0; i < 1; i++) + { + var data = graphics.graphicsData[i]; + var points = data.points; - if(data.type == PIXI.Graphics.POLY) - { - context.beginPath(); - context.moveTo(points[0], points[1]); + if(data.type === PIXI.Graphics.POLY) + { + context.beginPath(); + context.moveTo(points[0], points[1]); - for (var j=1; j < points.length/2; j++) - { - context.lineTo(points[j * 2], points[j * 2 + 1]); - } + for (var j=1; j < points.length/2; j++) + { + context.lineTo(points[j * 2], points[j * 2 + 1]); + } - // if the first and last point are the same close the path - much neater :) - if(points[0] == points[points.length-2] && points[1] == points[points.length-1]) - { - context.closePath(); - } + // if the first and last point are the same close the path - much neater :) + if(points[0] === points[points.length-2] && points[1] === points[points.length-1]) + { + context.closePath(); + } - } - else if(data.type == PIXI.Graphics.RECT) - { - context.beginPath(); - context.rect(points[0], points[1], points[2], points[3]); - context.closePath(); - } - else if(data.type == PIXI.Graphics.CIRC) - { - // TODO - need to be Undefined! - context.beginPath(); - context.arc(points[0], points[1], points[2],0,2*Math.PI); - context.closePath(); - } - else if(data.type == PIXI.Graphics.ELIP) - { + } + else if(data.type === PIXI.Graphics.RECT) + { + context.beginPath(); + context.rect(points[0], points[1], points[2], points[3]); + context.closePath(); + } + else if(data.type === PIXI.Graphics.CIRC) + { + // TODO - need to be Undefined! + context.beginPath(); + context.arc(points[0], points[1], points[2],0,2*Math.PI); + context.closePath(); + } + else if(data.type === PIXI.Graphics.ELIP) + { - // elipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas - var elipseData = data.points; + // ellipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas + var ellipseData = data.points; - var w = elipseData[2] * 2; - var h = elipseData[3] * 2; + var w = ellipseData[2] * 2; + var h = ellipseData[3] * 2; - var x = elipseData[0] - w/2; - var y = elipseData[1] - h/2; + var x = ellipseData[0] - w/2; + var y = ellipseData[1] - h/2; - context.beginPath(); + context.beginPath(); - var kappa = .5522848, - ox = (w / 2) * kappa, // control point offset horizontal - oy = (h / 2) * kappa, // control point offset vertical - xe = x + w, // x-end - ye = y + h, // y-end - xm = x + w / 2, // x-middle - ym = y + h / 2; // y-middle + var kappa = 0.5522848, + ox = (w / 2) * kappa, // control point offset horizontal + oy = (h / 2) * kappa, // control point offset vertical + xe = x + w, // x-end + ye = y + h, // y-end + xm = x + w / 2, // x-middle + ym = y + h / 2; // y-middle - context.moveTo(x, ym); - context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); - context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); - context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); - context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); - context.closePath(); - } - - - }; -} + context.moveTo(x, ym); + context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); + context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); + context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); + context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); + context.closePath(); + } + } +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ - /** * the CanvasRenderer draws the stage and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Dont forget to add the view to your DOM or you will not see anything :) @@ -3173,49 +3153,63 @@ PIXI.CanvasGraphics.renderGraphicsMask = function(graphics, context) */ PIXI.CanvasRenderer = function(width, height, view, transparent) { - this.transparent = transparent; + this.transparent = transparent; - /** - * The width of the canvas view - * - * @property width - * @type Number - * @default 800 - */ - this.width = width || 800; + /** + * The width of the canvas view + * + * @property width + * @type Number + * @default 800 + */ + this.width = width || 800; - /** - * The height of the canvas view - * - * @property height - * @type Number - * @default 600 - */ - this.height = height || 600; + /** + * The height of the canvas view + * + * @property height + * @type Number + * @default 600 + */ + this.height = height || 600; - /** - * The canvas element that the everything is drawn to - * - * @property view - * @type Canvas - */ - this.view = view || document.createElement( 'canvas' ); + /** + * The canvas element that the everything is drawn to + * + * @property view + * @type Canvas + */ + this.view = view || document.createElement( 'canvas' ); - /** - * The canvas context that the everything is drawn to - * @property context - * @type Canvas 2d Context - */ - this.context = this.view.getContext("2d"); + /** + * The canvas context that the everything is drawn to + * @property context + * @type Canvas 2d Context + */ + this.context = this.view.getContext( '2d' ); + + //some filter variables + this.smoothProperty = null; + + if('imageSmoothingEnabled' in this.context) + this.smoothProperty = 'imageSmoothingEnabled'; + else if('webkitImageSmoothingEnabled' in this.context) + this.smoothProperty = 'webkitImageSmoothingEnabled'; + else if('mozImageSmoothingEnabled' in this.context) + this.smoothProperty = 'mozImageSmoothingEnabled'; + else if('oImageSmoothingEnabled' in this.context) + this.smoothProperty = 'oImageSmoothingEnabled'; + + this.scaleMode = null; + + this.refresh = true; + // hack to enable some hardware acceleration! + //this.view.style["transform"] = "translatez(0)"; - this.refresh = true; - // hack to enable some hardware acceleration! - //this.view.style["transform"] = "translatez(0)"; - this.view.width = this.width; - this.view.height = this.height; - this.count = 0; -} + this.view.height = this.height; + this.count = 0; +}; // constructor PIXI.CanvasRenderer.prototype.constructor = PIXI.CanvasRenderer; @@ -3228,44 +3222,42 @@ PIXI.CanvasRenderer.prototype.constructor = PIXI.CanvasRenderer; */ PIXI.CanvasRenderer.prototype.render = function(stage) { - - //stage.__childrenAdded = []; - //stage.__childrenRemoved = []; - - // update textures if need be - PIXI.texturesToUpdate = []; - PIXI.texturesToDestroy = []; - - PIXI.visibleCount++; - stage.updateTransform(); - - // update the background color - if(this.view.style.backgroundColor!=stage.backgroundColorString && !this.transparent)this.view.style.backgroundColor = stage.backgroundColorString; + //stage.__childrenAdded = []; + //stage.__childrenRemoved = []; - this.context.setTransform(1,0,0,1,0,0); - this.context.clearRect(0, 0, this.width, this.height) + // update textures if need be + PIXI.texturesToUpdate = []; + PIXI.texturesToDestroy = []; + + PIXI.visibleCount++; + stage.updateTransform(); + + // update the background color + if(this.view.style.backgroundColor !== stage.backgroundColorString && !this.transparent) + this.view.style.backgroundColor = stage.backgroundColorString; + + this.context.setTransform(1,0,0,1,0,0); + this.context.clearRect(0, 0, this.width, this.height); this.renderDisplayObject(stage); //as - + // run interaction! - if(stage.interactive) - { - //need to add some events! - if(!stage._interactiveEventsAdded) - { - stage._interactiveEventsAdded = true; - stage.interactionManager.setTarget(this); - } - } - - // remove frame updates.. - if(PIXI.Texture.frameUpdates.length > 0) - { - PIXI.Texture.frameUpdates = []; - } - - -} + if(stage.interactive) + { + //need to add some events! + if(!stage._interactiveEventsAdded) + { + stage._interactiveEventsAdded = true; + stage.interactionManager.setTarget(this); + } + } + + // remove frame updates.. + if(PIXI.Texture.frameUpdates.length > 0) + { + PIXI.Texture.frameUpdates = []; + } +}; /** * resizes the canvas view to the specified width and height @@ -3276,12 +3268,12 @@ PIXI.CanvasRenderer.prototype.render = function(stage) */ PIXI.CanvasRenderer.prototype.resize = function(width, height) { - this.width = width; - this.height = height; - - this.view.width = width; - this.view.height = height; -} + this.width = width; + this.height = height; + + this.view.width = width; + this.view.height = height; +}; /** * Renders a display object @@ -3292,117 +3284,116 @@ PIXI.CanvasRenderer.prototype.resize = function(width, height) */ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject) { - // no loger recurrsive! - var transform; - var context = this.context; - - context.globalCompositeOperation = 'source-over'; - - // one the display object hits this. we can break the loop - var testObject = displayObject.last._iNext; - displayObject = displayObject.first; - - do - { - transform = displayObject.worldTransform; - - if(!displayObject.visible) - { - displayObject = displayObject.last._iNext; - continue; - } - - if(!displayObject.renderable) - { - displayObject = displayObject._iNext; - continue; - } - - if(displayObject instanceof PIXI.Sprite) - { - - var frame = displayObject.texture.frame; - - if(frame && frame.width && frame.height) - { - context.globalAlpha = displayObject.worldAlpha; - - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]); - - context.drawImage(displayObject.texture.baseTexture.source, - frame.x, - frame.y, - frame.width, - frame.height, - (displayObject.anchor.x) * -frame.width, - (displayObject.anchor.y) * -frame.height, - frame.width, - frame.height); - } - } - else if(displayObject instanceof PIXI.Strip) - { - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]) - this.renderStrip(displayObject); - } - else if(displayObject instanceof PIXI.TilingSprite) - { - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]) - this.renderTilingSprite(displayObject); - } - else if(displayObject instanceof PIXI.CustomRenderable) - { - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]); - displayObject.renderCanvas(this); - } - else if(displayObject instanceof PIXI.Graphics) - { - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]) - PIXI.CanvasGraphics.renderGraphics(displayObject, context); - } - else if(displayObject instanceof PIXI.FilterBlock) - { - if(displayObject.data instanceof PIXI.Graphics) - { - var mask = displayObject.data; + // no loger recurrsive! + var transform; + var context = this.context; - if(displayObject.open) - { - context.save(); - - var cacheAlpha = mask.alpha; - var maskTransform = mask.worldTransform; - - context.setTransform(maskTransform[0], maskTransform[3], maskTransform[1], maskTransform[4], maskTransform[2], maskTransform[5]) - - mask.worldAlpha = 0.5; - - context.worldAlpha = 0; - - PIXI.CanvasGraphics.renderGraphicsMask(mask, context); - context.clip(); - - mask.worldAlpha = cacheAlpha; - } - else - { - context.restore(); - } - } - else - { - // only masks supported right now! - } - } - // count++ - displayObject = displayObject._iNext; - - - } - while(displayObject != testObject) + context.globalCompositeOperation = 'source-over'; - -} + // one the display object hits this. we can break the loop + var testObject = displayObject.last._iNext; + displayObject = displayObject.first; + + do + { + transform = displayObject.worldTransform; + + if(!displayObject.visible) + { + displayObject = displayObject.last._iNext; + continue; + } + + if(!displayObject.renderable) + { + displayObject = displayObject._iNext; + continue; + } + + if(displayObject instanceof PIXI.Sprite) + { + + var frame = displayObject.texture.frame; + + //ignore null sources + if(frame && frame.width && frame.height && displayObject.texture.baseTexture.source) + { + context.globalAlpha = displayObject.worldAlpha; + + context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]); + + //if smoothingEnabled is supported and we need to change the smoothing property for this texture + if(this.smoothProperty && this.scaleMode !== displayObject.texture.baseTexture.scaleMode) { + this.scaleMode = displayObject.texture.baseTexture.scaleMode; + context[this.smoothProperty] = (this.scaleMode === PIXI.BaseTexture.SCALE_MODE.LINEAR); + } + + context.drawImage(displayObject.texture.baseTexture.source, + frame.x, + frame.y, + frame.width, + frame.height, + (displayObject.anchor.x) * -frame.width, + (displayObject.anchor.y) * -frame.height, + frame.width, + frame.height); + } + } + else if(displayObject instanceof PIXI.Strip) + { + context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]); + this.renderStrip(displayObject); + } + else if(displayObject instanceof PIXI.TilingSprite) + { + context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]); + this.renderTilingSprite(displayObject); + } + else if(displayObject instanceof PIXI.CustomRenderable) + { + context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]); + displayObject.renderCanvas(this); + } + else if(displayObject instanceof PIXI.Graphics) + { + context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]); + PIXI.CanvasGraphics.renderGraphics(displayObject, context); + } + else if(displayObject instanceof PIXI.FilterBlock) + { + if(displayObject.data instanceof PIXI.Graphics) + { + var mask = displayObject.data; + + if(displayObject.open) + { + context.save(); + + var cacheAlpha = mask.alpha; + var maskTransform = mask.worldTransform; + + context.setTransform(maskTransform[0], maskTransform[3], maskTransform[1], maskTransform[4], maskTransform[2], maskTransform[5]); + + mask.worldAlpha = 0.5; + + context.worldAlpha = 0; + + PIXI.CanvasGraphics.renderGraphicsMask(mask, context); + context.clip(); + + mask.worldAlpha = cacheAlpha; + } + else + { + context.restore(); + } + } + } + //count++ + displayObject = displayObject._iNext; + } + while(displayObject !== testObject); +}; /** * Renders a flat strip @@ -3413,33 +3404,30 @@ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject) */ PIXI.CanvasRenderer.prototype.renderStripFlat = function(strip) { - var context = this.context; - var verticies = strip.verticies; - var uvs = strip.uvs; - - var length = verticies.length/2; - this.count++; - - context.beginPath(); - for (var i=1; i < length-2; i++) - { - - // draw some triangles! - var index = i*2; - - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - - }; - - context.fillStyle = "#FF0000"; - context.fill(); - context.closePath(); -} + var context = this.context; + var verticies = strip.verticies; + + var length = verticies.length/2; + this.count++; + + context.beginPath(); + for (var i=1; i < length-2; i++) + { + // draw some triangles! + var index = i*2; + + var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; + var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; + + context.moveTo(x0, y0); + context.lineTo(x1, y1); + context.lineTo(x2, y2); + } + + context.fillStyle = '#FF0000'; + context.fill(); + context.closePath(); +}; /** * Renders a tiling sprite @@ -3450,29 +3438,30 @@ PIXI.CanvasRenderer.prototype.renderStripFlat = function(strip) */ PIXI.CanvasRenderer.prototype.renderTilingSprite = function(sprite) { - var context = this.context; - - context.globalAlpha = sprite.worldAlpha; - - if(!sprite.__tilePattern) sprite.__tilePattern = context.createPattern(sprite.texture.baseTexture.source, "repeat"); - - context.beginPath(); - - var tilePosition = sprite.tilePosition; - var tileScale = sprite.tileScale; - + var context = this.context; + + context.globalAlpha = sprite.worldAlpha; + + if(!sprite.__tilePattern) + sprite.__tilePattern = context.createPattern(sprite.texture.baseTexture.source, 'repeat'); + + context.beginPath(); + + var tilePosition = sprite.tilePosition; + var tileScale = sprite.tileScale; + // offset context.scale(tileScale.x,tileScale.y); context.translate(tilePosition.x, tilePosition.y); - - context.fillStyle = sprite.__tilePattern; - context.fillRect(-tilePosition.x,-tilePosition.y,sprite.width / tileScale.x, sprite.height / tileScale.y); - - context.scale(1/tileScale.x, 1/tileScale.y); + + context.fillStyle = sprite.__tilePattern; + context.fillRect(-tilePosition.x,-tilePosition.y,sprite.width / tileScale.x, sprite.height / tileScale.y); + + context.scale(1/tileScale.x, 1/tileScale.y); context.translate(-tilePosition.x, -tilePosition.y); - + context.closePath(); -} +}; /** * Renders a strip @@ -3483,58 +3472,52 @@ PIXI.CanvasRenderer.prototype.renderTilingSprite = function(sprite) */ PIXI.CanvasRenderer.prototype.renderStrip = function(strip) { - var context = this.context; + var context = this.context; - // draw triangles!! - var verticies = strip.verticies; - var uvs = strip.uvs; - - var length = verticies.length/2; - this.count++; - for (var i=1; i < length-2; i++) - { - - // draw some triangles! - var index = i*2; - - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2] * strip.texture.width, u2 = uvs[index+4]* strip.texture.width; - var v0 = uvs[index+1]* strip.texture.height, v1 = uvs[index+3] * strip.texture.height, v2 = uvs[index+5]* strip.texture.height; + // draw triangles!! + var verticies = strip.verticies; + var uvs = strip.uvs; + var length = verticies.length/2; + this.count++; + + for (var i = 1; i < length-2; i++) + { + // draw some triangles! + var index = i*2; + + var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; + var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; + + var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2] * strip.texture.width, u2 = uvs[index+4]* strip.texture.width; + var v0 = uvs[index+1]* strip.texture.height, v1 = uvs[index+3] * strip.texture.height, v2 = uvs[index+5]* strip.texture.height; + + context.save(); + context.beginPath(); + context.moveTo(x0, y0); + context.lineTo(x1, y1); + context.lineTo(x2, y2); + context.closePath(); + + context.clip(); - context.save(); - context.beginPath(); - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - context.closePath(); - - context.clip(); - - // Compute matrix transform var delta = u0*v1 + v0*u2 + u1*v2 - v1*u2 - v0*u1 - u0*v2; - var delta_a = x0*v1 + v0*x2 + x1*v2 - v1*x2 - v0*x1 - x0*v2; - var delta_b = u0*x1 + x0*u2 + u1*x2 - x1*u2 - x0*u1 - u0*x2; - var delta_c = u0*v1*x2 + v0*x1*u2 + x0*u1*v2 - x0*v1*u2 - v0*u1*x2 - u0*x1*v2; - var delta_d = y0*v1 + v0*y2 + y1*v2 - v1*y2 - v0*y1 - y0*v2; - var delta_e = u0*y1 + y0*u2 + u1*y2 - y1*u2 - y0*u1 - u0*y2; - var delta_f = u0*v1*y2 + v0*y1*u2 + y0*u1*v2 - y0*v1*u2 - v0*u1*y2 - u0*y1*v2; - - - - - context.transform(delta_a/delta, delta_d/delta, - delta_b/delta, delta_e/delta, - delta_c/delta, delta_f/delta); - - context.drawImage(strip.texture.baseTexture.source, 0, 0); - context.restore(); - }; - -} + var deltaA = x0*v1 + v0*x2 + x1*v2 - v1*x2 - v0*x1 - x0*v2; + var deltaB = u0*x1 + x0*u2 + u1*x2 - x1*u2 - x0*u1 - u0*x2; + var deltaC = u0*v1*x2 + v0*x1*u2 + x0*u1*v2 - x0*v1*u2 - v0*u1*x2 - u0*x1*v2; + var deltaD = y0*v1 + v0*y2 + y1*v2 - v1*y2 - v0*y1 - y0*v2; + var deltaE = u0*y1 + y0*u2 + u1*y2 - y1*u2 - y0*u1 - u0*y2; + var deltaF = u0*v1*y2 + v0*y1*u2 + y0*u1*v2 - y0*v1*u2 - v0*u1*y2 - u0*y1*v2; + + context.transform(deltaA / delta, deltaD / delta, + deltaB / delta, deltaE / delta, + deltaC / delta, deltaF / delta); + + context.drawImage(strip.texture.baseTexture.source, 0, 0); + context.restore(); + } +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 @@ -3550,26 +3533,25 @@ PIXI.PixiShader = function() /** * @property {any} program - The WebGL program. */ - this.program; - + this.program = null; + /** * @property {array} fragmentSrc - The fragment shader. */ this.fragmentSrc = [ - "precision lowp float;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "uniform sampler2D uSampler;", - "void main(void) {", - "gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor;", - "}" + 'precision lowp float;', + 'varying vec2 vTextureCoord;', + 'varying float vColor;', + 'uniform sampler2D uSampler;', + 'void main(void) {', + ' gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor;', + '}' ]; /** * @property {number} textureCount - A local texture counter for multi-texture shaders. */ this.textureCount = 0; - }; /** @@ -3577,23 +3559,23 @@ PIXI.PixiShader = function() */ PIXI.PixiShader.prototype.init = function() { - var program = PIXI.compileProgram(this.vertexSrc || PIXI.PixiShader.defaultVertexSrc, this.fragmentSrc) - + var program = PIXI.compileProgram(this.vertexSrc || PIXI.PixiShader.defaultVertexSrc, this.fragmentSrc); + var gl = PIXI.gl; gl.useProgram(program); - + // get and store the uniforms for the shader - this.uSampler = gl.getUniformLocation(program, "uSampler"); - this.projectionVector = gl.getUniformLocation(program, "projectionVector"); - this.offsetVector = gl.getUniformLocation(program, "offsetVector"); - this.dimensions = gl.getUniformLocation(program, "dimensions"); - + this.uSampler = gl.getUniformLocation(program, 'uSampler'); + this.projectionVector = gl.getUniformLocation(program, 'projectionVector'); + this.offsetVector = gl.getUniformLocation(program, 'offsetVector'); + this.dimensions = gl.getUniformLocation(program, 'dimensions'); + // get and store the attributes - this.aVertexPosition = gl.getAttribLocation(program, "aVertexPosition"); - this.colorAttribute = gl.getAttribLocation(program, "aColor"); - this.aTextureCoord = gl.getAttribLocation(program, "aTextureCoord"); - + this.aVertexPosition = gl.getAttribLocation(program, 'aVertexPosition'); + this.colorAttribute = gl.getAttribLocation(program, 'aColor'); + this.aTextureCoord = gl.getAttribLocation(program, 'aTextureCoord'); + // add those custom shaders! for (var key in this.uniforms) { @@ -3602,7 +3584,7 @@ PIXI.PixiShader.prototype.init = function() } this.initUniforms(); - + this.program = program; }; @@ -3618,13 +3600,14 @@ PIXI.PixiShader.prototype.initUniforms = function() this.textureCount = 1; var uniform; - - for (var key in this.uniforms) + + for (var key in this.uniforms) { - var uniform = this.uniforms[key]; + uniform = this.uniforms[key]; + var type = uniform.type; - if (type == 'sampler2D') + if (type === 'sampler2D') { uniform._init = false; @@ -3633,21 +3616,21 @@ PIXI.PixiShader.prototype.initUniforms = function() this.initSampler2D(uniform); } } - else if (type == 'mat2' || type == 'mat3' || type == 'mat4') + else if (type === 'mat2' || type === 'mat3' || type === 'mat4') { // These require special handling uniform.glMatrix = true; uniform.glValueLength = 1; - if (type == 'mat2') + if (type === 'mat2') { uniform.glFunc = PIXI.gl.uniformMatrix2fv; } - else if (type == 'mat3') + else if (type === 'mat3') { uniform.glFunc = PIXI.gl.uniformMatrix3fv; } - else if (type == 'mat4') + else if (type === 'mat4') { uniform.glFunc = PIXI.gl.uniformMatrix4fv; } @@ -3657,15 +3640,15 @@ PIXI.PixiShader.prototype.initUniforms = function() // GL function reference uniform.glFunc = PIXI.gl['uniform' + type]; - if (type == '2f' || type == '2i') + if (type === '2f' || type === '2i') { uniform.glValueLength = 2; } - else if (type == '3f' || type == '3i') + else if (type === '3f' || type === '3i') { uniform.glValueLength = 3; } - else if (type == '4f' || type == '4i') + else if (type === '4f' || type === '4i') { uniform.glValueLength = 4; } @@ -3675,7 +3658,7 @@ PIXI.PixiShader.prototype.initUniforms = function() } } } - + }; /** @@ -3762,11 +3745,12 @@ PIXI.PixiShader.prototype.syncUniforms = function() var uniform; // This would probably be faster in an array and it would guarantee key order - for (var key in this.uniforms) + for (var key in this.uniforms) { + uniform = this.uniforms[key]; - if (uniform.glValueLength == 1) + if (uniform.glValueLength === 1) { if (uniform.glMatrix === true) { @@ -3777,19 +3761,19 @@ PIXI.PixiShader.prototype.syncUniforms = function() uniform.glFunc.call(PIXI.gl, uniform.uniformLocation, uniform.value); } } - else if (uniform.glValueLength == 2) + else if (uniform.glValueLength === 2) { uniform.glFunc.call(PIXI.gl, uniform.uniformLocation, uniform.value.x, uniform.value.y); } - else if (uniform.glValueLength == 3) + else if (uniform.glValueLength === 3) { uniform.glFunc.call(PIXI.gl, uniform.uniformLocation, uniform.value.x, uniform.value.y, uniform.value.z); } - else if (uniform.glValueLength == 4) + else if (uniform.glValueLength === 4) { uniform.glFunc.call(PIXI.gl, uniform.uniformLocation, uniform.value.x, uniform.value.y, uniform.value.z, uniform.value.w); } - else if (uniform.type == 'sampler2D') + else if (uniform.type === 'sampler2D') { if (uniform._init) { @@ -3804,28 +3788,27 @@ PIXI.PixiShader.prototype.syncUniforms = function() } } } - + }; PIXI.PixiShader.defaultVertexSrc = [ - - "attribute vec2 aVertexPosition;", - "attribute vec2 aTextureCoord;", - "attribute float aColor;", + 'attribute vec2 aVertexPosition;', + 'attribute vec2 aTextureCoord;', + 'attribute float aColor;', - "uniform vec2 projectionVector;", - "uniform vec2 offsetVector;", - "varying vec2 vTextureCoord;", + 'uniform vec2 projectionVector;', + 'uniform vec2 offsetVector;', + 'varying vec2 vTextureCoord;', - "varying float vColor;", + 'varying float vColor;', - "const vec2 center = vec2(-1.0, 1.0);", - - "void main(void) {", - "gl_Position = vec4( ((aVertexPosition + offsetVector) / projectionVector) + center , 0.0, 1.0);", - "vTextureCoord = aTextureCoord;", - "vColor = aColor;", - "}" + 'const vec2 center = vec2(-1.0, 1.0);', + + 'void main(void) {', + ' gl_Position = vec4( ((aVertexPosition + offsetVector) / projectionVector) + center , 0.0, 1.0);', + ' vTextureCoord = aTextureCoord;', + ' vColor = aColor;', + '}' ]; /** @@ -3835,56 +3818,57 @@ PIXI.PixiShader.defaultVertexSrc = [ PIXI.PrimitiveShader = function() { - // the webGL program.. - this.program; - + // the webGL program.. + this.program = null; + this.fragmentSrc = [ - "precision mediump float;", - "varying vec4 vColor;", - "void main(void) {", - "gl_FragColor = vColor;", - "}" + 'precision mediump float;', + 'varying vec4 vColor;', + + 'void main(void) {', + ' gl_FragColor = vColor;', + '}' ]; this.vertexSrc = [ - "attribute vec2 aVertexPosition;", - "attribute vec4 aColor;", - "uniform mat3 translationMatrix;", - "uniform vec2 projectionVector;", - "uniform vec2 offsetVector;", - "uniform float alpha;", - "varying vec4 vColor;", - "void main(void) {", - "vec3 v = translationMatrix * vec3(aVertexPosition , 1.0);", - "v -= offsetVector.xyx;", - "gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / -projectionVector.y + 1.0 , 0.0, 1.0);", - "vColor = aColor * alpha;", - "}" + 'attribute vec2 aVertexPosition;', + 'attribute vec4 aColor;', + 'uniform mat3 translationMatrix;', + 'uniform vec2 projectionVector;', + 'uniform vec2 offsetVector;', + 'uniform float alpha;', + 'varying vec4 vColor;', + + 'void main(void) {', + ' vec3 v = translationMatrix * vec3(aVertexPosition , 1.0);', + ' v -= offsetVector.xyx;', + ' gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / -projectionVector.y + 1.0 , 0.0, 1.0);', + ' vColor = aColor * alpha;', + '}' ]; - -} +}; PIXI.PrimitiveShader.prototype.init = function() { - var program = PIXI.compileProgram(this.vertexSrc, this.fragmentSrc); - - var gl = PIXI.gl; - - gl.useProgram(program); - - // get and store the uniforms for the shader - this.projectionVector = gl.getUniformLocation(program, "projectionVector"); - this.offsetVector = gl.getUniformLocation(program, "offsetVector"); - - // get and store the attributes - this.aVertexPosition = gl.getAttribLocation(program, "aVertexPosition"); - this.colorAttribute = gl.getAttribLocation(program, "aColor"); - - this.translationMatrix = gl.getUniformLocation(program, "translationMatrix"); - this.alpha = gl.getUniformLocation(program, "alpha"); + var program = PIXI.compileProgram(this.vertexSrc, this.fragmentSrc); - this.program = program; -} + var gl = PIXI.gl; + + gl.useProgram(program); + + // get and store the uniforms for the shader + this.projectionVector = gl.getUniformLocation(program, 'projectionVector'); + this.offsetVector = gl.getUniformLocation(program, 'offsetVector'); + + // get and store the attributes + this.aVertexPosition = gl.getAttribLocation(program, 'aVertexPosition'); + this.colorAttribute = gl.getAttribLocation(program, 'aColor'); + + this.translationMatrix = gl.getUniformLocation(program, 'translationMatrix'); + this.alpha = gl.getUniformLocation(program, 'alpha'); + + this.program = program; +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 @@ -3893,64 +3877,66 @@ PIXI.PrimitiveShader.prototype.init = function() PIXI.StripShader = function() { - // the webGL program.. - this.program; - + // the webGL program.. + this.program = null; + this.fragmentSrc = [ - "precision mediump float;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "uniform float alpha;", - "uniform sampler2D uSampler;", - "void main(void) {", - "gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));", - "gl_FragColor = gl_FragColor * alpha;", - "}" + 'precision mediump float;', + 'varying vec2 vTextureCoord;', + 'varying float vColor;', + 'uniform float alpha;', + 'uniform sampler2D uSampler;', + + 'void main(void) {', + ' gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));', + ' gl_FragColor = gl_FragColor * alpha;', + '}' ]; this.vertexSrc = [ - "attribute vec2 aVertexPosition;", - "attribute vec2 aTextureCoord;", - "attribute float aColor;", - "uniform mat3 translationMatrix;", - "uniform vec2 projectionVector;", - "varying vec2 vTextureCoord;", - "varying vec2 offsetVector;", - "varying float vColor;", - "void main(void) {", - "vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);", - "v -= offsetVector.xyx;", - "gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / projectionVector.y + 1.0 , 0.0, 1.0);", - "vTextureCoord = aTextureCoord;", - "vColor = aColor;", - "}" + 'attribute vec2 aVertexPosition;', + 'attribute vec2 aTextureCoord;', + 'attribute float aColor;', + 'uniform mat3 translationMatrix;', + 'uniform vec2 projectionVector;', + 'uniform vec2 offsetVector;', + 'varying vec2 vTextureCoord;', + 'varying float vColor;', + + 'void main(void) {', + ' vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);', + ' v -= offsetVector.xyx;', + ' gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / projectionVector.y + 1.0 , 0.0, 1.0);', + ' vTextureCoord = aTextureCoord;', + ' vColor = aColor;', + '}' ]; -} +}; PIXI.StripShader.prototype.init = function() { - var program = PIXI.compileProgram(this.vertexSrc, this.fragmentSrc) - - var gl = PIXI.gl; - + var program = PIXI.compileProgram(this.vertexSrc, this.fragmentSrc); + + var gl = PIXI.gl; + gl.useProgram(program); - // get and store the uniforms for the shader - this.uSampler = gl.getUniformLocation(program, "uSampler"); - this.projectionVector = gl.getUniformLocation(program, "projectionVector"); - this.offsetVector = gl.getUniformLocation(program, "offsetVector"); - this.colorAttribute = gl.getAttribLocation(program, "aColor"); - //this.dimensions = gl.getUniformLocation(this.program, "dimensions"); - - // get and store the attributes - this.aVertexPosition = gl.getAttribLocation(program, "aVertexPosition"); - this.aTextureCoord = gl.getAttribLocation(program, "aTextureCoord"); - - this.translationMatrix = gl.getUniformLocation(program, "translationMatrix"); - this.alpha = gl.getUniformLocation(program, "alpha"); - - this.program = program; -} + // get and store the uniforms for the shader + this.uSampler = gl.getUniformLocation(program, 'uSampler'); + this.projectionVector = gl.getUniformLocation(program, 'projectionVector'); + this.offsetVector = gl.getUniformLocation(program, 'offsetVector'); + this.colorAttribute = gl.getAttribLocation(program, 'aColor'); + //this.dimensions = gl.getUniformLocation(this.program, 'dimensions'); + + // get and store the attributes + this.aVertexPosition = gl.getAttribLocation(program, 'aVertexPosition'); + this.aTextureCoord = gl.getAttribLocation(program, 'aTextureCoord'); + + this.translationMatrix = gl.getUniformLocation(program, 'translationMatrix'); + this.alpha = gl.getUniformLocation(program, 'alpha'); + + this.program = program; +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 @@ -3963,35 +3949,35 @@ PIXI._batchs = []; */ PIXI._getBatch = function(gl) { - if(PIXI._batchs.length === 0) - { - return new PIXI.WebGLBatch(gl); - } - else - { - return PIXI._batchs.pop(); - } -} + if(PIXI._batchs.length === 0) + { + return new PIXI.WebGLBatch(gl); + } + else + { + return PIXI._batchs.pop(); + } +}; /** * @private */ PIXI._returnBatch = function(batch) { - batch.clean(); - PIXI._batchs.push(batch); -} + batch.clean(); + PIXI._batchs.push(batch); +}; /** * @private */ PIXI._restoreBatchs = function(gl) { - for (var i=0; i < PIXI._batchs.length; i++) - { - PIXI._batchs[i].restoreLostContext(gl); - }; -} + for (var i=0; i < PIXI._batchs.length; i++) + { + PIXI._batchs[i].restoreLostContext(gl); + } +}; /** * A WebGLBatch Enables a group of sprites to be drawn using the same settings. @@ -4007,17 +3993,17 @@ PIXI._restoreBatchs = function(gl) */ PIXI.WebGLBatch = function(gl) { - this.gl = gl; - - this.size = 0; + this.gl = gl; - this.vertexBuffer = gl.createBuffer(); - this.indexBuffer = gl.createBuffer(); - this.uvBuffer = gl.createBuffer(); - this.colorBuffer = gl.createBuffer(); - this.blendMode = PIXI.blendModes.NORMAL; - this.dynamicSize = 1; -} + this.size = 0; + + this.vertexBuffer = gl.createBuffer(); + this.indexBuffer = gl.createBuffer(); + this.uvBuffer = gl.createBuffer(); + this.colorBuffer = gl.createBuffer(); + this.blendMode = PIXI.blendModes.NORMAL; + this.dynamicSize = 1; +}; // constructor PIXI.WebGLBatch.prototype.constructor = PIXI.WebGLBatch; @@ -4029,17 +4015,17 @@ PIXI.WebGLBatch.prototype.constructor = PIXI.WebGLBatch; */ PIXI.WebGLBatch.prototype.clean = function() { - this.verticies = []; - this.uvs = []; - this.indices = []; - this.colors = []; - this.dynamicSize = 1; - this.texture = null; - this.last = null; - this.size = 0; - this.head; - this.tail; -} + this.verticies = []; + this.uvs = []; + this.indices = []; + this.colors = []; + this.dynamicSize = 1; + this.texture = null; + this.last = null; + this.size = 0; + this.head = null; + this.tail = null; +}; /** * Recreates the buffers in the event of a context loss @@ -4049,32 +4035,32 @@ PIXI.WebGLBatch.prototype.clean = function() */ PIXI.WebGLBatch.prototype.restoreLostContext = function(gl) { - this.gl = gl; - this.vertexBuffer = gl.createBuffer(); - this.indexBuffer = gl.createBuffer(); - this.uvBuffer = gl.createBuffer(); - this.colorBuffer = gl.createBuffer(); -} + this.gl = gl; + this.vertexBuffer = gl.createBuffer(); + this.indexBuffer = gl.createBuffer(); + this.uvBuffer = gl.createBuffer(); + this.colorBuffer = gl.createBuffer(); +}; /** * inits the batch's texture and blend mode based if the supplied sprite * * @method init * @param sprite {Sprite} the first sprite to be added to the batch. Only sprites with - * the same base texture and blend mode will be allowed to be added to this batch - */ + * the same base texture and blend mode will be allowed to be added to this batch + */ PIXI.WebGLBatch.prototype.init = function(sprite) { - sprite.batch = this; - this.dirty = true; - this.blendMode = sprite.blendMode; - this.texture = sprite.texture.baseTexture; - this.head = sprite; - this.tail = sprite; - this.size = 1; + sprite.batch = this; + this.dirty = true; + this.blendMode = sprite.blendMode; + this.texture = sprite.texture.baseTexture; + this.head = sprite; + this.tail = sprite; + this.size = 1; - this.growBatch(); -} + this.growBatch(); +}; /** * inserts a sprite before the specified sprite @@ -4082,27 +4068,27 @@ PIXI.WebGLBatch.prototype.init = function(sprite) * @method insertBefore * @param sprite {Sprite} the sprite to be added * @param nextSprite {nextSprite} the first sprite will be inserted before this sprite - */ + */ PIXI.WebGLBatch.prototype.insertBefore = function(sprite, nextSprite) { - this.size++; + this.size++; - sprite.batch = this; - this.dirty = true; - var tempPrev = nextSprite.__prev; - nextSprite.__prev = sprite; - sprite.__next = nextSprite; + sprite.batch = this; + this.dirty = true; + var tempPrev = nextSprite.__prev; + nextSprite.__prev = sprite; + sprite.__next = nextSprite; - if(tempPrev) - { - sprite.__prev = tempPrev; - tempPrev.__next = sprite; - } - else - { - this.head = sprite; - } -} + if(tempPrev) + { + sprite.__prev = tempPrev; + tempPrev.__next = sprite; + } + else + { + this.head = sprite; + } +}; /** * inserts a sprite after the specified sprite @@ -4110,72 +4096,72 @@ PIXI.WebGLBatch.prototype.insertBefore = function(sprite, nextSprite) * @method insertAfter * @param sprite {Sprite} the sprite to be added * @param previousSprite {Sprite} the first sprite will be inserted after this sprite - */ + */ PIXI.WebGLBatch.prototype.insertAfter = function(sprite, previousSprite) { - this.size++; + this.size++; - sprite.batch = this; - this.dirty = true; + sprite.batch = this; + this.dirty = true; - var tempNext = previousSprite.__next; - previousSprite.__next = sprite; - sprite.__prev = previousSprite; + var tempNext = previousSprite.__next; + previousSprite.__next = sprite; + sprite.__prev = previousSprite; - if(tempNext) - { - sprite.__next = tempNext; - tempNext.__prev = sprite; - } - else - { - this.tail = sprite - } -} + if(tempNext) + { + sprite.__next = tempNext; + tempNext.__prev = sprite; + } + else + { + this.tail = sprite; + } +}; /** * removes a sprite from the batch * * @method remove * @param sprite {Sprite} the sprite to be removed - */ + */ PIXI.WebGLBatch.prototype.remove = function(sprite) { - this.size--; + this.size--; - if(this.size === 0) - { - sprite.batch = null; - sprite.__prev = null; - sprite.__next = null; - return; - } + if(this.size === 0) + { + sprite.batch = null; + sprite.__prev = null; + sprite.__next = null; + return; + } - if(sprite.__prev) - { - sprite.__prev.__next = sprite.__next; - } - else - { - this.head = sprite.__next; - this.head.__prev = null; - } + if(sprite.__prev) + { + sprite.__prev.__next = sprite.__next; + } + else + { + this.head = sprite.__next; + this.head.__prev = null; + } - if(sprite.__next) - { - sprite.__next.__prev = sprite.__prev; - } - else - { - this.tail = sprite.__prev; - this.tail.__next = null - } + if(sprite.__next) + { + sprite.__next.__prev = sprite.__prev; + } + else + { + this.tail = sprite.__prev; + this.tail.__next = null; + } - sprite.batch = null; - sprite.__next = null; - sprite.__prev = null; - this.dirty = true; -} + sprite.batch = null; + sprite.__next = null; + sprite.__prev = null; + this.dirty = true; +}; /** * Splits the batch into two with the specified sprite being the start of the new batch. @@ -4186,62 +4172,62 @@ PIXI.WebGLBatch.prototype.remove = function(sprite) */ PIXI.WebGLBatch.prototype.split = function(sprite) { - this.dirty = true; + this.dirty = true; - var batch = new PIXI.WebGLBatch(this.gl); - batch.init(sprite); - batch.texture = this.texture; - batch.tail = this.tail; + var batch = new PIXI.WebGLBatch(this.gl); + batch.init(sprite); + batch.texture = this.texture; + batch.tail = this.tail; - this.tail = sprite.__prev; - this.tail.__next = null; + this.tail = sprite.__prev; + this.tail.__next = null; - sprite.__prev = null; - // return a splite batch! + sprite.__prev = null; + // return a splite batch! - // TODO this size is wrong! - // need to recalculate :/ problem with a linked list! - // unless it gets calculated in the "clean"? + // TODO this size is wrong! + // need to recalculate :/ problem with a linked list! + // unless it gets calculated in the "clean"? - // need to loop through items as there is no way to know the length on a linked list :/ - var tempSize = 0; - while(sprite) - { - tempSize++; - sprite.batch = batch; - sprite = sprite.__next; - } + // need to loop through items as there is no way to know the length on a linked list :/ + var tempSize = 0; + while(sprite) + { + tempSize++; + sprite.batch = batch; + sprite = sprite.__next; + } - batch.size = tempSize; - this.size -= tempSize; + batch.size = tempSize; + this.size -= tempSize; - return batch; -} + return batch; +}; /** * Merges two batchs together * * @method merge - * @param batch {WebGLBatch} the batch that will be merged + * @param batch {WebGLBatch} the batch that will be merged */ PIXI.WebGLBatch.prototype.merge = function(batch) { - this.dirty = true; + this.dirty = true; - this.tail.__next = batch.head; - batch.head.__prev = this.tail; + this.tail.__next = batch.head; + batch.head.__prev = this.tail; - this.size += batch.size; + this.size += batch.size; - this.tail = batch.tail; + this.tail = batch.tail; - var sprite = batch.head; - while(sprite) - { - sprite.batch = this; - sprite = sprite.__next; - } -} + var sprite = batch.head; + while(sprite) + { + sprite.batch = this; + sprite = sprite.__next; + } +}; /** * Grows the size of the batch. As the elements in the batch cannot have a dynamic size this @@ -4252,51 +4238,52 @@ PIXI.WebGLBatch.prototype.merge = function(batch) */ PIXI.WebGLBatch.prototype.growBatch = function() { - var gl = this.gl; - if( this.size == 1) - { - this.dynamicSize = 1; - } - else - { - this.dynamicSize = this.size * 1.5 - } - // grow verts - this.verticies = new Float32Array(this.dynamicSize * 8); + var gl = this.gl; + if( this.size === 1) + { + this.dynamicSize = 1; + } + else + { + this.dynamicSize = this.size * 1.5; + } - gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER,this.verticies , gl.DYNAMIC_DRAW); + // grow verts + this.verticies = new Float32Array(this.dynamicSize * 8); - this.uvs = new Float32Array( this.dynamicSize * 8 ); - gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer); - gl.bufferData(gl.ARRAY_BUFFER, this.uvs , gl.DYNAMIC_DRAW); + gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); + gl.bufferData(gl.ARRAY_BUFFER,this.verticies , gl.DYNAMIC_DRAW); - this.dirtyUVS = true; + this.uvs = new Float32Array( this.dynamicSize * 8 ); + gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer); + gl.bufferData(gl.ARRAY_BUFFER, this.uvs , gl.DYNAMIC_DRAW); - this.colors = new Float32Array( this.dynamicSize * 4 ); - gl.bindBuffer(gl.ARRAY_BUFFER, this.colorBuffer); - gl.bufferData(gl.ARRAY_BUFFER, this.colors , gl.DYNAMIC_DRAW); + this.dirtyUVS = true; - this.dirtyColors = true; + this.colors = new Float32Array( this.dynamicSize * 4 ); + gl.bindBuffer(gl.ARRAY_BUFFER, this.colorBuffer); + gl.bufferData(gl.ARRAY_BUFFER, this.colors , gl.DYNAMIC_DRAW); - this.indices = new Uint16Array(this.dynamicSize * 6); - var length = this.indices.length/6; + this.dirtyColors = true; - for (var i=0; i < length; i++) - { - var index2 = i * 6; - var index3 = i * 4; - this.indices[index2 + 0] = index3 + 0; - this.indices[index2 + 1] = index3 + 1; - this.indices[index2 + 2] = index3 + 2; - this.indices[index2 + 3] = index3 + 0; - this.indices[index2 + 4] = index3 + 2; - this.indices[index2 + 5] = index3 + 3; - }; + this.indices = new Uint16Array(this.dynamicSize * 6); + var length = this.indices.length/6; - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); + for (var i = 0; i < length; i++) + { + var index2 = i * 6; + var index3 = i * 4; + this.indices[index2 + 0] = index3 + 0; + this.indices[index2 + 1] = index3 + 1; + this.indices[index2 + 2] = index3 + 2; + this.indices[index2 + 3] = index3 + 0; + this.indices[index2 + 4] = index3 + 2; + this.indices[index2 + 5] = index3 + 3; + } + + gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices, gl.STATIC_DRAW); -} +}; /** * Refresh's all the data in the batch and sync's it with the webGL buffers @@ -4305,54 +4292,51 @@ PIXI.WebGLBatch.prototype.growBatch = function() */ PIXI.WebGLBatch.prototype.refresh = function() { - var gl = this.gl; + if (this.dynamicSize < this.size) + { + this.growBatch(); + } - if (this.dynamicSize < this.size) - { - this.growBatch(); - } + var indexRun = 0; + var index, colorIndex; - var indexRun = 0; - var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index; - var a, b, c, d, tx, ty; + var displayObject = this.head; - var displayObject = this.head; + while(displayObject) + { + index = indexRun * 8; - while(displayObject) - { - index = indexRun * 8; + var texture = displayObject.texture; - var texture = displayObject.texture; + var frame = texture.frame; + var tw = texture.baseTexture.width; + var th = texture.baseTexture.height; - var frame = texture.frame; - var tw = texture.baseTexture.width; - var th = texture.baseTexture.height; + this.uvs[index + 0] = frame.x / tw; + this.uvs[index +1] = frame.y / th; - this.uvs[index + 0] = frame.x / tw; - this.uvs[index +1] = frame.y / th; + this.uvs[index +2] = (frame.x + frame.width) / tw; + this.uvs[index +3] = frame.y / th; - this.uvs[index +2] = (frame.x + frame.width) / tw; - this.uvs[index +3] = frame.y / th; + this.uvs[index +4] = (frame.x + frame.width) / tw; + this.uvs[index +5] = (frame.y + frame.height) / th; - this.uvs[index +4] = (frame.x + frame.width) / tw; - this.uvs[index +5] = (frame.y + frame.height) / th; + this.uvs[index +6] = frame.x / tw; + this.uvs[index +7] = (frame.y + frame.height) / th; - this.uvs[index +6] = frame.x / tw; - this.uvs[index +7] = (frame.y + frame.height) / th; + displayObject.updateFrame = false; - displayObject.updateFrame = false; + colorIndex = indexRun * 4; + this.colors[colorIndex] = this.colors[colorIndex + 1] = this.colors[colorIndex + 2] = this.colors[colorIndex + 3] = displayObject.worldAlpha; - colorIndex = indexRun * 4; - this.colors[colorIndex] = this.colors[colorIndex + 1] = this.colors[colorIndex + 2] = this.colors[colorIndex + 3] = displayObject.worldAlpha; + displayObject = displayObject.__next; - displayObject = displayObject.__next; + indexRun++; + } - indexRun ++; - } - - this.dirtyUVS = true; - this.dirtyColors = true; -} + this.dirtyUVS = true; + this.dirtyColors = true; +}; /** * Updates all the relevant geometry and uploads the data to the GPU @@ -4361,103 +4345,102 @@ PIXI.WebGLBatch.prototype.refresh = function() */ PIXI.WebGLBatch.prototype.update = function() { - var gl = this.gl; - var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index, index2, index3 + var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index; - var a, b, c, d, tx, ty; + var a, b, c, d, tx, ty; - var indexRun = 0; + var indexRun = 0; - var displayObject = this.head; - var verticies = this.verticies; - var uvs = this.uvs; - var colors = this.colors; - - while(displayObject) - { - if(displayObject.vcount === PIXI.visibleCount) - { - width = displayObject.texture.frame.width; - height = displayObject.texture.frame.height; + var displayObject = this.head; + var verticies = this.verticies; + var uvs = this.uvs; + var colors = this.colors; - // TODO trim?? - aX = displayObject.anchor.x;// - displayObject.texture.trim.x - aY = displayObject.anchor.y; //- displayObject.texture.trim.y - w0 = width * (1-aX); - w1 = width * -aX; + while(displayObject) + { + if(displayObject.vcount === PIXI.visibleCount) + { + width = displayObject.texture.frame.width; + height = displayObject.texture.frame.height; - h0 = height * (1-aY); - h1 = height * -aY; + // TODO trim?? + aX = displayObject.anchor.x;// - displayObject.texture.trim.x + aY = displayObject.anchor.y; //- displayObject.texture.trim.y + w0 = width * (1-aX); + w1 = width * -aX; - index = indexRun * 8; + h0 = height * (1-aY); + h1 = height * -aY; - worldTransform = displayObject.worldTransform; + index = indexRun * 8; - a = worldTransform[0]; - b = worldTransform[3]; - c = worldTransform[1]; - d = worldTransform[4]; - tx = worldTransform[2]; - ty = worldTransform[5]; + worldTransform = displayObject.worldTransform; - verticies[index + 0 ] = a * w1 + c * h1 + tx; - verticies[index + 1 ] = d * h1 + b * w1 + ty; + a = worldTransform[0]; + b = worldTransform[3]; + c = worldTransform[1]; + d = worldTransform[4]; + tx = worldTransform[2]; + ty = worldTransform[5]; - verticies[index + 2 ] = a * w0 + c * h1 + tx; - verticies[index + 3 ] = d * h1 + b * w0 + ty; + verticies[index + 0 ] = a * w1 + c * h1 + tx; + verticies[index + 1 ] = d * h1 + b * w1 + ty; - verticies[index + 4 ] = a * w0 + c * h0 + tx; - verticies[index + 5 ] = d * h0 + b * w0 + ty; + verticies[index + 2 ] = a * w0 + c * h1 + tx; + verticies[index + 3 ] = d * h1 + b * w0 + ty; - verticies[index + 6] = a * w1 + c * h0 + tx; - verticies[index + 7] = d * h0 + b * w1 + ty; + verticies[index + 4 ] = a * w0 + c * h0 + tx; + verticies[index + 5 ] = d * h0 + b * w0 + ty; - if(displayObject.updateFrame || displayObject.texture.updateFrame) - { - this.dirtyUVS = true; + verticies[index + 6] = a * w1 + c * h0 + tx; + verticies[index + 7] = d * h0 + b * w1 + ty; - var texture = displayObject.texture; + if(displayObject.updateFrame || displayObject.texture.updateFrame) + { + this.dirtyUVS = true; - var frame = texture.frame; - var tw = texture.baseTexture.width; - var th = texture.baseTexture.height; + var texture = displayObject.texture; - uvs[index + 0] = frame.x / tw; - uvs[index +1] = frame.y / th; + var frame = texture.frame; + var tw = texture.baseTexture.width; + var th = texture.baseTexture.height; - uvs[index +2] = (frame.x + frame.width) / tw; - uvs[index +3] = frame.y / th; + uvs[index + 0] = frame.x / tw; + uvs[index +1] = frame.y / th; - uvs[index +4] = (frame.x + frame.width) / tw; - uvs[index +5] = (frame.y + frame.height) / th; + uvs[index +2] = (frame.x + frame.width) / tw; + uvs[index +3] = frame.y / th; - uvs[index +6] = frame.x / tw; - uvs[index +7] = (frame.y + frame.height) / th; + uvs[index +4] = (frame.x + frame.width) / tw; + uvs[index +5] = (frame.y + frame.height) / th; - displayObject.updateFrame = false; - } + uvs[index +6] = frame.x / tw; + uvs[index +7] = (frame.y + frame.height) / th; - // TODO this probably could do with some optimisation.... - if(displayObject.cacheAlpha != displayObject.worldAlpha) - { - displayObject.cacheAlpha = displayObject.worldAlpha; + displayObject.updateFrame = false; + } - var colorIndex = indexRun * 4; - colors[colorIndex] = colors[colorIndex + 1] = colors[colorIndex + 2] = colors[colorIndex + 3] = displayObject.worldAlpha; - this.dirtyColors = true; - } - } - else - { - index = indexRun * 8; + // TODO this probably could do with some optimisation.... + if(displayObject.cacheAlpha !== displayObject.worldAlpha) + { + displayObject.cacheAlpha = displayObject.worldAlpha; - verticies[index + 0 ] = verticies[index + 1 ] = verticies[index + 2 ] = verticies[index + 3 ] = verticies[index + 4 ] = verticies[index + 5 ] = verticies[index + 6] = verticies[index + 7] = 0; - } + var colorIndex = indexRun * 4; + colors[colorIndex] = colors[colorIndex + 1] = colors[colorIndex + 2] = colors[colorIndex + 3] = displayObject.worldAlpha; + this.dirtyColors = true; + } + } + else + { + index = indexRun * 8; - indexRun++; - displayObject = displayObject.__next; - } -} + verticies[index + 0 ] = verticies[index + 1 ] = verticies[index + 2 ] = verticies[index + 3 ] = verticies[index + 4 ] = verticies[index + 5 ] = verticies[index + 6] = verticies[index + 7] = 0; + } + + indexRun++; + displayObject = displayObject.__next; + } +}; /** * Draws the batch to the frame buffer @@ -4466,41 +4449,42 @@ PIXI.WebGLBatch.prototype.update = function() */ PIXI.WebGLBatch.prototype.render = function(start, end) { - start = start || 0; + start = start || 0; - if(end == undefined)end = this.size; - - if(this.dirty) - { - this.refresh(); - this.dirty = false; - } + if(end === undefined) + end = this.size; - if (this.size === 0)return; + if(this.dirty) + { + this.refresh(); + this.dirty = false; + } - this.update(); - var gl = this.gl; + if (this.size === 0)return; - //TODO optimize this! + this.update(); + var gl = this.gl; - var shaderProgram = PIXI.defaultShader; - - //gl.useProgram(shaderProgram); + //TODO optimize this! - // update the verts.. - gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); - // ok.. - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.verticies) + var shaderProgram = PIXI.defaultShader; + + //gl.useProgram(shaderProgram); + + // update the verts.. + gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); + // ok.. + gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.verticies); gl.vertexAttribPointer(shaderProgram.aVertexPosition, 2, gl.FLOAT, false, 0, 0); - // update the uvs - //var isDefault = (shaderProgram == PIXI.shaderProgram) + // update the uvs + //var isDefault = (shaderProgram == PIXI.shaderProgram) - gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer); + gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer); if(this.dirtyUVS) { - this.dirtyUVS = false; - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvs); + this.dirtyUVS = false; + gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvs); } gl.vertexAttribPointer(shaderProgram.aTextureCoord, 2, gl.FLOAT, false, 0, 0); @@ -4508,24 +4492,24 @@ PIXI.WebGLBatch.prototype.render = function(start, end) gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, this.texture._glTexture); - // update color! - gl.bindBuffer(gl.ARRAY_BUFFER, this.colorBuffer); + // update color! + gl.bindBuffer(gl.ARRAY_BUFFER, this.colorBuffer); - if(this.dirtyColors) + if(this.dirtyColors) { - this.dirtyColors = false; - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.colors); - } + this.dirtyColors = false; + gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.colors); + } gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0); - // dont need to upload! + // dont need to upload! gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - var len = end - start; + var len = end - start; // DRAW THAT this! gl.drawElements(gl.TRIANGLES, len * 6, gl.UNSIGNED_SHORT, start * 2 * 6 ); -} +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 @@ -4534,518 +4518,511 @@ PIXI.WebGLBatch.prototype.render = function(start, end) PIXI.WebGLFilterManager = function(transparent) { - this.transparent = transparent; - - this.filterStack = []; - this.texturePool = []; - - this.offsetX = 0; - this.offsetY = 0; - - this.initShaderBuffers(); -} + this.transparent = transparent; + + this.filterStack = []; + this.texturePool = []; + + this.offsetX = 0; + this.offsetY = 0; + + this.initShaderBuffers(); +}; // API PIXI.WebGLFilterManager.prototype.begin = function(projection, buffer) { - this.width = projection.x * 2; - this.height = -projection.y * 2; - this.buffer = buffer; -} + this.width = projection.x * 2; + this.height = -projection.y * 2; + this.buffer = buffer; +}; PIXI.WebGLFilterManager.prototype.pushFilter = function(filterBlock) { - var gl = PIXI.gl; + var gl = PIXI.gl; - // filter program - // OPTIMISATION - the first filter is free if its a simple color change? - this.filterStack.push(filterBlock); + // filter program + // OPTIMISATION - the first filter is free if its a simple color change? + this.filterStack.push(filterBlock); - var filter = filterBlock.filterPasses[0]; + var filter = filterBlock.filterPasses[0]; - + this.offsetX += filterBlock.target.filterArea.x; + this.offsetY += filterBlock.target.filterArea.y; - this.offsetX += filterBlock.target.filterArea.x; - this.offsetY += filterBlock.target.filterArea.y; - - - - - - var texture = this.texturePool.pop(); - if(!texture)texture = new PIXI.FilterTexture(this.width, this.height); - - gl.bindTexture(gl.TEXTURE_2D, texture.texture); - - this.getBounds(filterBlock.target); - - // addpadding? - //displayObject.filterArea.x + var texture = this.texturePool.pop(); + if(!texture) + { + texture = new PIXI.FilterTexture(this.width, this.height); + } + else + { + texture.resize(this.width, this.height); + } - var filterArea = filterBlock.target.filterArea; + gl.bindTexture(gl.TEXTURE_2D, texture.texture); - var padidng = filter.padding; - filterArea.x -= padidng; - filterArea.y -= padidng; - filterArea.width += padidng * 2; - filterArea.height += padidng * 2; + this.getBounds(filterBlock.target); - // cap filter to screen size.. - if(filterArea.x < 0)filterArea.x = 0; - if(filterArea.width > this.width)filterArea.width = this.width; - if(filterArea.y < 0)filterArea.y = 0; - if(filterArea.height > this.height)filterArea.height = this.height; + // addpadding? + //displayObject.filterArea.x + var filterArea = filterBlock.target.filterArea; - //gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, filterArea.width, filterArea.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); - gl.bindFramebuffer(gl.FRAMEBUFFER, texture.frameBuffer); - - // console.log(filterArea) - // set view port - gl.viewport(0, 0, filterArea.width, filterArea.height); - - PIXI.projection.x = filterArea.width/2; - PIXI.projection.y = -filterArea.height/2; - - PIXI.offset.x = -filterArea.x; - PIXI.offset.y = -filterArea.y; + var padidng = filter.padding; + filterArea.x -= padidng; + filterArea.y -= padidng; + filterArea.width += padidng * 2; + filterArea.height += padidng * 2; - //console.log(PIXI.defaultShader.projectionVector) - // update projection - gl.uniform2f(PIXI.defaultShader.projectionVector, filterArea.width/2, -filterArea.height/2); - gl.uniform2f(PIXI.defaultShader.offsetVector, -filterArea.x, -filterArea.y); - //PIXI.primitiveProgram + // cap filter to screen size.. + if(filterArea.x < 0)filterArea.x = 0; + if(filterArea.width > this.width)filterArea.width = this.width; + if(filterArea.y < 0)filterArea.y = 0; + if(filterArea.height > this.height)filterArea.height = this.height; - gl.colorMask(true, true, true, true); - gl.clearColor(0,0,0, 0); - gl.clear(gl.COLOR_BUFFER_BIT); - - //filter.texture = texture; - filterBlock._glFilterTexture = texture; + //gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, filterArea.width, filterArea.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); + gl.bindFramebuffer(gl.FRAMEBUFFER, texture.frameBuffer); - //console.log("PUSH") -} + //console.log(filterArea) + // set view port + gl.viewport(0, 0, filterArea.width, filterArea.height); + + PIXI.projection.x = filterArea.width/2; + PIXI.projection.y = -filterArea.height/2; + + PIXI.offset.x = -filterArea.x; + PIXI.offset.y = -filterArea.y; + + //console.log(PIXI.defaultShader.projectionVector) + // update projection + gl.uniform2f(PIXI.defaultShader.projectionVector, filterArea.width/2, -filterArea.height/2); + gl.uniform2f(PIXI.defaultShader.offsetVector, -filterArea.x, -filterArea.y); + //PIXI.primitiveProgram + + gl.colorMask(true, true, true, true); + gl.clearColor(0,0,0, 0); + gl.clear(gl.COLOR_BUFFER_BIT); + + //filter.texture = texture; + filterBlock._glFilterTexture = texture; + + //console.log("PUSH") +}; PIXI.WebGLFilterManager.prototype.popFilter = function() { - - var gl = PIXI.gl; - - var filterBlock = this.filterStack.pop(); + var gl = PIXI.gl; + var filterBlock = this.filterStack.pop(); + var filterArea = filterBlock.target.filterArea; + var texture = filterBlock._glFilterTexture; + + if(filterBlock.filterPasses.length > 1) + { + gl.viewport(0, 0, filterArea.width, filterArea.height); + + gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); + + this.vertexArray[0] = 0; + this.vertexArray[1] = filterArea.height; + + this.vertexArray[2] = filterArea.width; + this.vertexArray[3] = filterArea.height; + + this.vertexArray[4] = 0; + this.vertexArray[5] = 0; + + this.vertexArray[6] = filterArea.width; + this.vertexArray[7] = 0; + + gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.vertexArray); + + gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer); + // nnow set the uvs.. + this.uvArray[2] = filterArea.width/this.width; + this.uvArray[5] = filterArea.height/this.height; + this.uvArray[6] = filterArea.width/this.width; + this.uvArray[7] = filterArea.height/this.height; + + gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvArray); + + var inputTexture = texture; + var outputTexture = this.texturePool.pop(); + if(!outputTexture)outputTexture = new PIXI.FilterTexture(this.width, this.height); + + // need to clear this FBO as it may have some left over elements from a prvious filter. + gl.bindFramebuffer(gl.FRAMEBUFFER, outputTexture.frameBuffer ); + gl.clear(gl.COLOR_BUFFER_BIT); + + gl.disable(gl.BLEND); + + for (var i = 0; i < filterBlock.filterPasses.length-1; i++) + { + var filterPass = filterBlock.filterPasses[i]; + + gl.bindFramebuffer(gl.FRAMEBUFFER, outputTexture.frameBuffer ); + + // set texture + gl.activeTexture(gl.TEXTURE0); + gl.bindTexture(gl.TEXTURE_2D, inputTexture.texture); + + // draw texture.. + //filterPass.applyFilterPass(filterArea.width, filterArea.height); + this.applyFilterPass(filterPass, filterArea, filterArea.width, filterArea.height); + + // swap the textures.. + var temp = inputTexture; + inputTexture = outputTexture; + outputTexture = temp; + } + + gl.enable(gl.BLEND); + + texture = inputTexture; + this.texturePool.push(outputTexture); + } + + var filter = filterBlock.filterPasses[filterBlock.filterPasses.length-1]; + + this.offsetX -= filterArea.x; + this.offsetY -= filterArea.y; + + + var sizeX = this.width; + var sizeY = this.height; + + var offsetX = 0; + var offsetY = 0; + + var buffer = this.buffer; + + // time to render the filters texture to the previous scene + if(this.filterStack.length === 0) + { + gl.colorMask(true, true, true, this.transparent); + } + else + { + var currentFilter = this.filterStack[this.filterStack.length-1]; + filterArea = currentFilter.target.filterArea; + + sizeX = filterArea.width; + sizeY = filterArea.height; + + offsetX = filterArea.x; + offsetY = filterArea.y; + + buffer = currentFilter._glFilterTexture.frameBuffer; + } - var filterArea = filterBlock.target.filterArea; + // TODO need toremove thease global elements.. + PIXI.projection.x = sizeX/2; + PIXI.projection.y = -sizeY/2; - var texture = filterBlock._glFilterTexture; + PIXI.offset.x = offsetX; + PIXI.offset.y = offsetY; - if(filterBlock.filterPasses.length > 1) - { - gl.viewport(0, 0, filterArea.width, filterArea.height); + filterArea = filterBlock.target.filterArea; - gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); - - this.vertexArray[0] = 0; - this.vertexArray[1] = filterArea.height; - - this.vertexArray[2] = filterArea.width; - this.vertexArray[3] = filterArea.height; - - this.vertexArray[4] = 0; - this.vertexArray[5] = 0; - - this.vertexArray[6] = filterArea.width; - this.vertexArray[7] = 0; + var x = filterArea.x-offsetX; + var y = filterArea.y-offsetY; + // update the buffers.. + // make sure to flip the y! + gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.vertexArray); + this.vertexArray[0] = x; + this.vertexArray[1] = y + filterArea.height; - - gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer); - // nnow set the uvs.. - this.uvArray[2] = filterArea.width/this.width; - this.uvArray[5] = filterArea.height/this.height; - this.uvArray[6] = filterArea.width/this.width; - this.uvArray[7] = filterArea.height/this.height; - - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvArray); + this.vertexArray[2] = x + filterArea.width; + this.vertexArray[3] = y + filterArea.height; - var inputTexture = texture; - var outputTexture = this.texturePool.pop(); - if(!outputTexture)outputTexture = new PIXI.FilterTexture(this.width, this.height); - - // need to clear this FBO as it may have some left over elements from a prvious filter. - gl.bindFramebuffer(gl.FRAMEBUFFER, outputTexture.frameBuffer ); - gl.clear(gl.COLOR_BUFFER_BIT); - - gl.disable(gl.BLEND); - - for (var i = 0; i < filterBlock.filterPasses.length-1; i++) - { - var filterPass = filterBlock.filterPasses[i]; - - gl.bindFramebuffer(gl.FRAMEBUFFER, outputTexture.frameBuffer ); - - // set texture - gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, inputTexture.texture); - - // draw texture.. - //filterPass.applyFilterPass(filterArea.width, filterArea.height); - this.applyFilterPass(filterPass, filterArea, filterArea.width, filterArea.height); + this.vertexArray[4] = x; + this.vertexArray[5] = y; - // swap the textures.. - var temp = inputTexture; - inputTexture = outputTexture; - outputTexture = temp; - - }; + this.vertexArray[6] = x + filterArea.width; + this.vertexArray[7] = y; - gl.enable(gl.BLEND); + gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.vertexArray); - texture = inputTexture; - this.texturePool.push(outputTexture); - } + gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer); - var filter = filterBlock.filterPasses[filterBlock.filterPasses.length-1]; - - this.offsetX -= filterArea.x; - this.offsetY -= filterArea.y; + this.uvArray[2] = filterArea.width/this.width; + this.uvArray[5] = filterArea.height/this.height; + this.uvArray[6] = filterArea.width/this.width; + this.uvArray[7] = filterArea.height/this.height; - - var sizeX = this.width; - var sizeY = this.height; - - var offsetX = 0; - var offsetY = 0; - - var buffer = this.buffer; - - // time to render the filters texture to the previous scene - if(this.filterStack.length === 0) - { - gl.colorMask(true, true, true, this.transparent); - } - else - { - var currentFilter = this.filterStack[this.filterStack.length-1]; - var filterArea = currentFilter.target.filterArea; - - sizeX = filterArea.width; - sizeY = filterArea.height; - - offsetX = filterArea.x; - offsetY = filterArea.y; - - buffer = currentFilter._glFilterTexture.frameBuffer; - } - - + gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvArray); - // TODO need toremove thease global elements.. - PIXI.projection.x = sizeX/2; - PIXI.projection.y = -sizeY/2; + gl.viewport(0, 0, sizeX, sizeY); + // bind the buffer + gl.bindFramebuffer(gl.FRAMEBUFFER, buffer ); - PIXI.offset.x = offsetX; - PIXI.offset.y = offsetY; - - - var filterArea = filterBlock.target.filterArea; - var x = filterArea.x-offsetX; - var y = filterArea.y-offsetY; - - // update the buffers.. - // make sure to flip the y! - gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); - - this.vertexArray[0] = x; - this.vertexArray[1] = y + filterArea.height; - - this.vertexArray[2] = x + filterArea.width; - this.vertexArray[3] = y + filterArea.height; - - this.vertexArray[4] = x; - this.vertexArray[5] = y; - - this.vertexArray[6] = x + filterArea.width; - this.vertexArray[7] = y; - - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.vertexArray); - - gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer); - - this.uvArray[2] = filterArea.width/this.width; - this.uvArray[5] = filterArea.height/this.height; - this.uvArray[6] = filterArea.width/this.width; - this.uvArray[7] = filterArea.height/this.height; - - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvArray); - - gl.viewport(0, 0, sizeX, sizeY); - // bind the buffer - gl.bindFramebuffer(gl.FRAMEBUFFER, buffer ); - - // set texture + // set texture gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, texture.texture); - - // apply! - //filter.applyFilterPass(sizeX, sizeY); - this.applyFilterPass(filter, filterArea, sizeX, sizeY); + gl.bindTexture(gl.TEXTURE_2D, texture.texture); - // now restore the regular shader.. + // apply! + //filter.applyFilterPass(sizeX, sizeY); + this.applyFilterPass(filter, filterArea, sizeX, sizeY); + + // now restore the regular shader.. gl.useProgram(PIXI.defaultShader.program); - gl.uniform2f(PIXI.defaultShader.projectionVector, sizeX/2, -sizeY/2); - gl.uniform2f(PIXI.defaultShader.offsetVector, -offsetX, -offsetY); + gl.uniform2f(PIXI.defaultShader.projectionVector, sizeX/2, -sizeY/2); + gl.uniform2f(PIXI.defaultShader.offsetVector, -offsetX, -offsetY); - // return the texture to the pool - this.texturePool.push(texture); - filterBlock._glFilterTexture = null; -} + // return the texture to the pool + this.texturePool.push(texture); + filterBlock._glFilterTexture = null; +}; PIXI.WebGLFilterManager.prototype.applyFilterPass = function(filter, filterArea, width, height) { - // use program - var gl = PIXI.gl; + // use program + var gl = PIXI.gl; + var shader = filter.shader; - if(!filter.shader) - { - var shader = new PIXI.PixiShader(); - - shader.fragmentSrc = filter.fragmentSrc; - shader.uniforms = filter.uniforms; - shader.init(); - - filter.shader = shader; - } + if(!shader) + { + shader = new PIXI.PixiShader(); - var shader = filter.shader; - - // set the shader - gl.useProgram(shader.program); + shader.fragmentSrc = filter.fragmentSrc; + shader.uniforms = filter.uniforms; + shader.init(); - gl.uniform2f(shader.projectionVector, width/2, -height/2); - gl.uniform2f(shader.offsetVector, 0,0) + filter.shader = shader; + } - if(filter.uniforms.dimensions) - { - //console.log(filter.uniforms.dimensions) - filter.uniforms.dimensions.value[0] = this.width;//width; - filter.uniforms.dimensions.value[1] = this.height;//height; - filter.uniforms.dimensions.value[2] = this.vertexArray[0]; - filter.uniforms.dimensions.value[3] = this.vertexArray[5];//filterArea.height; - // console.log(this.vertexArray[5]) - } + // set the shader + gl.useProgram(shader.program); - shader.syncUniforms(); - - gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); + gl.uniform2f(shader.projectionVector, width/2, -height/2); + gl.uniform2f(shader.offsetVector, 0,0); + + if(filter.uniforms.dimensions) + { + //console.log(filter.uniforms.dimensions) + filter.uniforms.dimensions.value[0] = this.width;//width; + filter.uniforms.dimensions.value[1] = this.height;//height; + filter.uniforms.dimensions.value[2] = this.vertexArray[0]; + filter.uniforms.dimensions.value[3] = this.vertexArray[5];//filterArea.height; + // console.log(this.vertexArray[5]) + } + + shader.syncUniforms(); + + gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, 0, 0); - - gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer); + + gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer); gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, 0, 0); - + gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - - // draw the filter... + + // draw the filter... gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 ); -} +}; PIXI.WebGLFilterManager.prototype.initShaderBuffers = function() { - var gl = PIXI.gl; - - // create some buffers - this.vertexBuffer = gl.createBuffer(); - this.uvBuffer = gl.createBuffer(); - this.indexBuffer = gl.createBuffer(); - - // bind and upload the vertexs.. - // keep a refferance to the vertexFloatData.. - this.vertexArray = new Float32Array([0.0, 0.0, - 1.0, 0.0, - 0.0, 1.0, - 1.0, 1.0]); - - gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); - gl.bufferData( - gl.ARRAY_BUFFER, - this.vertexArray, + var gl = PIXI.gl; + + // create some buffers + this.vertexBuffer = gl.createBuffer(); + this.uvBuffer = gl.createBuffer(); + this.indexBuffer = gl.createBuffer(); + + // bind and upload the vertexs.. + // keep a refferance to the vertexFloatData.. + this.vertexArray = new Float32Array([0.0, 0.0, + 1.0, 0.0, + 0.0, 1.0, + 1.0, 1.0]); + + gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); + gl.bufferData( + gl.ARRAY_BUFFER, + this.vertexArray, gl.STATIC_DRAW); - - + + // bind and upload the uv buffer - this.uvArray = new Float32Array([0.0, 0.0, - 1.0, 0.0, - 0.0, 1.0, - 1.0, 1.0]); - - gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer); - gl.bufferData( - gl.ARRAY_BUFFER, - this.uvArray, + this.uvArray = new Float32Array([0.0, 0.0, + 1.0, 0.0, + 0.0, 1.0, + 1.0, 1.0]); + + gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer); + gl.bufferData( + gl.ARRAY_BUFFER, + this.uvArray, gl.STATIC_DRAW); - - // bind and upload the index - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - gl.bufferData( - gl.ELEMENT_ARRAY_BUFFER, - new Uint16Array([0, 1, 2, 1, 3, 2]), + + // bind and upload the index + gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); + gl.bufferData( + gl.ELEMENT_ARRAY_BUFFER, + new Uint16Array([0, 1, 2, 1, 3, 2]), gl.STATIC_DRAW); -} +}; PIXI.WebGLFilterManager.prototype.getBounds = function(displayObject) { - // time to get the width and height of the object! - var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index, doTest; - var a, b, c, d, tx, ty, x1, x2, x3, x4, y1, y2, y3, y4; + // time to get the width and height of the object! + var worldTransform, width, height, aX, aY, w0, w1, h0, h1, doTest; + var a, b, c, d, tx, ty, x1, x2, x3, x4, y1, y2, y3, y4; - var tempObject = displayObject.first; - var testObject = displayObject.last._iNext; - - var maxX = -Infinity; - var maxY = -Infinity; - - var minX = Infinity; - var minY = Infinity; - - do - { - // TODO can be optimized! - what if there is no scale / rotation? - - if(tempObject.visible) - { - if(tempObject instanceof PIXI.Sprite) - { - width = tempObject.texture.frame.width; - height = tempObject.texture.frame.height; + var tempObject = displayObject.first; + var testObject = displayObject.last._iNext; - // TODO trim?? - aX = tempObject.anchor.x; - aY = tempObject.anchor.y; - w0 = width * (1-aX); - w1 = width * -aX; + var maxX = -Infinity; + var maxY = -Infinity; - h0 = height * (1-aY); - h1 = height * -aY; + var minX = Infinity; + var minY = Infinity; - doTest = true; - } - else if(tempObject instanceof PIXI.Graphics) - { - tempObject.updateFilterBounds(); + do + { + // TODO can be optimized! - what if there is no scale / rotation? - var bounds = tempObject.bounds; + if(tempObject.visible) + { + if(tempObject instanceof PIXI.Sprite) + { + width = tempObject.texture.frame.width; + height = tempObject.texture.frame.height; - width = bounds.width; - height = bounds.height; + // TODO trim?? + aX = tempObject.anchor.x; + aY = tempObject.anchor.y; + w0 = width * (1-aX); + w1 = width * -aX; - w0 = bounds.x - w1 = bounds.x + bounds.width; + h0 = height * (1-aY); + h1 = height * -aY; - h0 = bounds.y - h1 = bounds.y + bounds.height; + doTest = true; + } + else if(tempObject instanceof PIXI.Graphics) + { + tempObject.updateFilterBounds(); - doTest = true; - } - } - - if(doTest) - { - worldTransform = tempObject.worldTransform; + var bounds = tempObject.bounds; - a = worldTransform[0]; - b = worldTransform[3]; - c = worldTransform[1]; - d = worldTransform[4]; - tx = worldTransform[2]; - ty = worldTransform[5]; + width = bounds.width; + height = bounds.height; - x1 = a * w1 + c * h1 + tx; - y1 = d * h1 + b * w1 + ty; + w0 = bounds.x; + w1 = bounds.x + bounds.width; - x2 = a * w0 + c * h1 + tx; - y2 = d * h1 + b * w0 + ty; + h0 = bounds.y; + h1 = bounds.y + bounds.height; - x3 = a * w0 + c * h0 + tx; - y3 = d * h0 + b * w0 + ty; + doTest = true; + } + } - x4 = a * w1 + c * h0 + tx; - y4 = d * h0 + b * w1 + ty; + if(doTest) + { + worldTransform = tempObject.worldTransform; - minX = x1 < minX ? x1 : minX; - minX = x2 < minX ? x2 : minX; - minX = x3 < minX ? x3 : minX; - minX = x4 < minX ? x4 : minX; - - minY = y1 < minY ? y1 : minY; - minY = y2 < minY ? y2 : minY; - minY = y3 < minY ? y3 : minY; - minY = y4 < minY ? y4 : minY; - - maxX = x1 > maxX ? x1 : maxX; - maxX = x2 > maxX ? x2 : maxX; - maxX = x3 > maxX ? x3 : maxX; - maxX = x4 > maxX ? x4 : maxX; - - maxY = y1 > maxY ? y1 : maxY; - maxY = y2 > maxY ? y2 : maxY; - maxY = y3 > maxY ? y3 : maxY; - maxY = y4 > maxY ? y4 : maxY; - } + a = worldTransform[0]; + b = worldTransform[3]; + c = worldTransform[1]; + d = worldTransform[4]; + tx = worldTransform[2]; + ty = worldTransform[5]; - doTest = false; - tempObject = tempObject._iNext; + x1 = a * w1 + c * h1 + tx; + y1 = d * h1 + b * w1 + ty; - } - while(tempObject != testObject) - - // maximum bounds is the size of the screen.. - //minX = minX > 0 ? minX : 0; - //minY = minY > 0 ? minY : 0; + x2 = a * w0 + c * h1 + tx; + y2 = d * h1 + b * w0 + ty; - displayObject.filterArea.x = minX; - displayObject.filterArea.y = minY; + x3 = a * w0 + c * h0 + tx; + y3 = d * h0 + b * w0 + ty; -// console.log(maxX+ " : " + minX) - displayObject.filterArea.width = maxX - minX; - displayObject.filterArea.height = maxY - minY; -} + x4 = a * w1 + c * h0 + tx; + y4 = d * h0 + b * w1 + ty; + + minX = x1 < minX ? x1 : minX; + minX = x2 < minX ? x2 : minX; + minX = x3 < minX ? x3 : minX; + minX = x4 < minX ? x4 : minX; + + minY = y1 < minY ? y1 : minY; + minY = y2 < minY ? y2 : minY; + minY = y3 < minY ? y3 : minY; + minY = y4 < minY ? y4 : minY; + + maxX = x1 > maxX ? x1 : maxX; + maxX = x2 > maxX ? x2 : maxX; + maxX = x3 > maxX ? x3 : maxX; + maxX = x4 > maxX ? x4 : maxX; + + maxY = y1 > maxY ? y1 : maxY; + maxY = y2 > maxY ? y2 : maxY; + maxY = y3 > maxY ? y3 : maxY; + maxY = y4 > maxY ? y4 : maxY; + } + + doTest = false; + tempObject = tempObject._iNext; + + } + while(tempObject !== testObject); + + // maximum bounds is the size of the screen.. + //minX = minX > 0 ? minX : 0; + //minY = minY > 0 ? minY : 0; + + displayObject.filterArea.x = minX; + displayObject.filterArea.y = minY; + +// console.log(maxX+ " : " + minX) + displayObject.filterArea.width = maxX - minX; + displayObject.filterArea.height = maxY - minY; +}; PIXI.FilterTexture = function(width, height) { - var gl = PIXI.gl; - + var gl = PIXI.gl; + // next time to create a frame buffer and texture - this.frameBuffer = gl.createFramebuffer(); + this.frameBuffer = gl.createFramebuffer(); this.texture = gl.createTexture(); gl.bindTexture(gl.TEXTURE_2D, this.texture); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer ); - - gl.bindFramebuffer(gl.FRAMEBUFFER, this.frameBuffer ); - gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.texture, 0); - - this.resize(width, height); -} + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer ); + + gl.bindFramebuffer(gl.FRAMEBUFFER, this.frameBuffer ); + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.texture, 0); + + this.resize(width, height); +}; PIXI.FilterTexture.prototype.resize = function(width, height) { - this.width = width; - this.height = height; + if(this.width === width && this.height === height) return; - var gl = PIXI.gl; + this.width = width; + this.height = height; + + var gl = PIXI.gl; + + gl.bindTexture(gl.TEXTURE_2D, this.texture); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); + +}; - gl.bindTexture(gl.TEXTURE_2D, this.texture); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); - -} /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -5057,8 +5034,8 @@ PIXI.FilterTexture.prototype.resize = function(width, height) */ PIXI.WebGLGraphics = function() { - -} + +}; /** * Renders the graphics object @@ -5071,62 +5048,61 @@ PIXI.WebGLGraphics = function() */ PIXI.WebGLGraphics.renderGraphics = function(graphics, projection) { - var gl = PIXI.gl; - - if(!graphics._webGL)graphics._webGL = {points:[], indices:[], lastIndex:0, - buffer:gl.createBuffer(), - indexBuffer:gl.createBuffer()}; - - if(graphics.dirty) - { - graphics.dirty = false; - - if(graphics.clearDirty) - { - graphics.clearDirty = false; - - graphics._webGL.lastIndex = 0; - graphics._webGL.points = []; - graphics._webGL.indices = []; - - } - - PIXI.WebGLGraphics.updateGraphics(graphics); - } - - PIXI.activatePrimitiveShader(); - - // This could be speeded up fo sure! - var m = PIXI.mat3.clone(graphics.worldTransform); - - PIXI.mat3.transpose(m); - - // set the matrix transform for the - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); + var gl = PIXI.gl; - gl.uniformMatrix3fv(PIXI.primitiveShader.translationMatrix, false, m); - - gl.uniform2f(PIXI.primitiveShader.projectionVector, projection.x, -projection.y); - gl.uniform2f(PIXI.primitiveShader.offsetVector, -PIXI.offset.x, -PIXI.offset.y); - - gl.uniform1f(PIXI.primitiveShader.alpha, graphics.worldAlpha); - gl.bindBuffer(gl.ARRAY_BUFFER, graphics._webGL.buffer); - - gl.vertexAttribPointer(PIXI.primitiveShader.aVertexPosition, 2, gl.FLOAT, false, 4 * 6, 0); - gl.vertexAttribPointer(PIXI.primitiveShader.colorAttribute, 4, gl.FLOAT, false,4 * 6, 2 * 4); - - // set the index buffer! - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.indexBuffer); - + if(!graphics._webGL)graphics._webGL = {points:[], indices:[], lastIndex:0, + buffer:gl.createBuffer(), + indexBuffer:gl.createBuffer()}; - gl.drawElements(gl.TRIANGLE_STRIP, graphics._webGL.indices.length, gl.UNSIGNED_SHORT, 0 ); - - PIXI.deactivatePrimitiveShader(); - - - // return to default shader... -// PIXI.activateShader(PIXI.defaultShader); -} + if(graphics.dirty) + { + graphics.dirty = false; + + if(graphics.clearDirty) + { + graphics.clearDirty = false; + + graphics._webGL.lastIndex = 0; + graphics._webGL.points = []; + graphics._webGL.indices = []; + + } + + PIXI.WebGLGraphics.updateGraphics(graphics); + } + + PIXI.activatePrimitiveShader(); + + // This could be speeded up fo sure! + var m = PIXI.mat3.clone(graphics.worldTransform); + + PIXI.mat3.transpose(m); + + // set the matrix transform for the + gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); + + gl.uniformMatrix3fv(PIXI.primitiveShader.translationMatrix, false, m); + + gl.uniform2f(PIXI.primitiveShader.projectionVector, projection.x, -projection.y); + gl.uniform2f(PIXI.primitiveShader.offsetVector, -PIXI.offset.x, -PIXI.offset.y); + + gl.uniform1f(PIXI.primitiveShader.alpha, graphics.worldAlpha); + gl.bindBuffer(gl.ARRAY_BUFFER, graphics._webGL.buffer); + + gl.vertexAttribPointer(PIXI.primitiveShader.aVertexPosition, 2, gl.FLOAT, false, 4 * 6, 0); + gl.vertexAttribPointer(PIXI.primitiveShader.colorAttribute, 4, gl.FLOAT, false,4 * 6, 2 * 4); + + // set the index buffer! + gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.indexBuffer); + + + gl.drawElements(gl.TRIANGLE_STRIP, graphics._webGL.indices.length, gl.UNSIGNED_SHORT, 0 ); + + PIXI.deactivatePrimitiveShader(); + + // return to default shader... +// PIXI.activateShader(PIXI.defaultShader); +}; /** * Updates the graphics object @@ -5138,47 +5114,47 @@ PIXI.WebGLGraphics.renderGraphics = function(graphics, projection) */ PIXI.WebGLGraphics.updateGraphics = function(graphics) { - for (var i=graphics._webGL.lastIndex; i < graphics.graphicsData.length; i++) - { - var data = graphics.graphicsData[i]; - - if(data.type == PIXI.Graphics.POLY) - { - if(data.fill) - { - if(data.points.length>3) - PIXI.WebGLGraphics.buildPoly(data, graphics._webGL); - } - - if(data.lineWidth > 0) - { - PIXI.WebGLGraphics.buildLine(data, graphics._webGL); - } - } - else if(data.type == PIXI.Graphics.RECT) - { - PIXI.WebGLGraphics.buildRectangle(data, graphics._webGL); - } - else if(data.type == PIXI.Graphics.CIRC || data.type == PIXI.Graphics.ELIP) - { - PIXI.WebGLGraphics.buildCircle(data, graphics._webGL); - } - }; - - graphics._webGL.lastIndex = graphics.graphicsData.length; - - var gl = PIXI.gl; + for (var i = graphics._webGL.lastIndex; i < graphics.graphicsData.length; i++) + { + var data = graphics.graphicsData[i]; - graphics._webGL.glPoints = new Float32Array(graphics._webGL.points); - - gl.bindBuffer(gl.ARRAY_BUFFER, graphics._webGL.buffer); - gl.bufferData(gl.ARRAY_BUFFER, graphics._webGL.glPoints, gl.STATIC_DRAW); - - graphics._webGL.glIndicies = new Uint16Array(graphics._webGL.indices); - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.indexBuffer); + if(data.type === PIXI.Graphics.POLY) + { + if(data.fill) + { + if(data.points.length>3) + PIXI.WebGLGraphics.buildPoly(data, graphics._webGL); + } + + if(data.lineWidth > 0) + { + PIXI.WebGLGraphics.buildLine(data, graphics._webGL); + } + } + else if(data.type === PIXI.Graphics.RECT) + { + PIXI.WebGLGraphics.buildRectangle(data, graphics._webGL); + } + else if(data.type === PIXI.Graphics.CIRC || data.type === PIXI.Graphics.ELIP); + { + PIXI.WebGLGraphics.buildCircle(data, graphics._webGL); + } + } + + graphics._webGL.lastIndex = graphics.graphicsData.length; + + var gl = PIXI.gl; + + graphics._webGL.glPoints = new Float32Array(graphics._webGL.points); + + gl.bindBuffer(gl.ARRAY_BUFFER, graphics._webGL.buffer); + gl.bufferData(gl.ARRAY_BUFFER, graphics._webGL.glPoints, gl.STATIC_DRAW); + + graphics._webGL.glIndicies = new Uint16Array(graphics._webGL.indices); + + gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.indexBuffer); gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.glIndicies, gl.STATIC_DRAW); -} +}; /** * Builds a rectangle to draw @@ -5191,59 +5167,58 @@ PIXI.WebGLGraphics.updateGraphics = function(graphics) */ PIXI.WebGLGraphics.buildRectangle = function(graphicsData, webGLData) { - // --- // - // need to convert points to a nice regular data - // - var rectData = graphicsData.points; - var x = rectData[0]; - var y = rectData[1]; - var width = rectData[2]; - var height = rectData[3]; - - - if(graphicsData.fill) - { - var color = HEXtoRGB(graphicsData.fillColor); - var alpha = graphicsData.fillAlpha; - - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var verts = webGLData.points; - var indices = webGLData.indices; - - var vertPos = verts.length/6; - - // start - verts.push(x, y); - verts.push(r, g, b, alpha); - - verts.push(x + width, y); - verts.push(r, g, b, alpha); - - verts.push(x , y + height); - verts.push(r, g, b, alpha); - - verts.push(x + width, y + height); - verts.push(r, g, b, alpha); - - // insert 2 dead triangles.. - indices.push(vertPos, vertPos, vertPos+1, vertPos+2, vertPos+3, vertPos+3) - } - - if(graphicsData.lineWidth) - { - graphicsData.points = [x, y, - x + width, y, - x + width, y + height, - x, y + height, - x, y]; - - PIXI.WebGLGraphics.buildLine(graphicsData, webGLData); - } - -} + // --- // + // need to convert points to a nice regular data + // + var rectData = graphicsData.points; + var x = rectData[0]; + var y = rectData[1]; + var width = rectData[2]; + var height = rectData[3]; + + + if(graphicsData.fill) + { + var color = PIXI.hex2rgb(graphicsData.fillColor); + var alpha = graphicsData.fillAlpha; + + var r = color[0] * alpha; + var g = color[1] * alpha; + var b = color[2] * alpha; + + var verts = webGLData.points; + var indices = webGLData.indices; + + var vertPos = verts.length/6; + + // start + verts.push(x, y); + verts.push(r, g, b, alpha); + + verts.push(x + width, y); + verts.push(r, g, b, alpha); + + verts.push(x , y + height); + verts.push(r, g, b, alpha); + + verts.push(x + width, y + height); + verts.push(r, g, b, alpha); + + // insert 2 dead triangles.. + indices.push(vertPos, vertPos, vertPos+1, vertPos+2, vertPos+3, vertPos+3); + } + + if(graphicsData.lineWidth) + { + graphicsData.points = [x, y, + x + width, y, + x + width, y + height, + x, y + height, + x, y]; + + PIXI.WebGLGraphics.buildLine(graphicsData, webGLData); + } +}; /** * Builds a circle to draw @@ -5256,62 +5231,63 @@ PIXI.WebGLGraphics.buildRectangle = function(graphicsData, webGLData) */ PIXI.WebGLGraphics.buildCircle = function(graphicsData, webGLData) { - // --- // - // need to convert points to a nice regular data - // - var rectData = graphicsData.points; - var x = rectData[0]; - var y = rectData[1]; - var width = rectData[2]; - var height = rectData[3]; - - var totalSegs = 40; - var seg = (Math.PI * 2) / totalSegs ; - - if(graphicsData.fill) - { - var color = HEXtoRGB(graphicsData.fillColor); - var alpha = graphicsData.fillAlpha; + // --- // + // need to convert points to a nice regular data + // + var rectData = graphicsData.points; + var x = rectData[0]; + var y = rectData[1]; + var width = rectData[2]; + var height = rectData[3]; - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var verts = webGLData.points; - var indices = webGLData.indices; - - var vecPos = verts.length/6; - - indices.push(vecPos); - - for (var i=0; i < totalSegs + 1 ; i++) - { - verts.push(x,y, r, g, b, alpha); - - verts.push(x + Math.sin(seg * i) * width, - y + Math.cos(seg * i) * height, - r, g, b, alpha); - - indices.push(vecPos++, vecPos++); - }; - - indices.push(vecPos-1); - } - - if(graphicsData.lineWidth) - { - graphicsData.points = []; - - for (var i=0; i < totalSegs + 1; i++) - { - graphicsData.points.push(x + Math.sin(seg * i) * width, - y + Math.cos(seg * i) * height) - }; - - PIXI.WebGLGraphics.buildLine(graphicsData, webGLData); - } - -} + var totalSegs = 40; + var seg = (Math.PI * 2) / totalSegs ; + + var i = 0; + + if(graphicsData.fill) + { + var color = PIXI.hex2rgb(graphicsData.fillColor); + var alpha = graphicsData.fillAlpha; + + var r = color[0] * alpha; + var g = color[1] * alpha; + var b = color[2] * alpha; + + var verts = webGLData.points; + var indices = webGLData.indices; + + var vecPos = verts.length/6; + + indices.push(vecPos); + + for (i = 0; i < totalSegs + 1 ; i++) + { + verts.push(x,y, r, g, b, alpha); + + verts.push(x + Math.sin(seg * i) * width, + y + Math.cos(seg * i) * height, + r, g, b, alpha); + + indices.push(vecPos++, vecPos++); + } + + indices.push(vecPos-1); + } + + if(graphicsData.lineWidth) + { + graphicsData.points = []; + + for (i = 0; i < totalSegs + 1; i++) + { + graphicsData.points.push(x + Math.sin(seg * i) * width, + y + Math.cos(seg * i) * height); + } + + PIXI.WebGLGraphics.buildLine(graphicsData, webGLData); + } +}; /** * Builds a line to draw @@ -5324,205 +5300,204 @@ PIXI.WebGLGraphics.buildCircle = function(graphicsData, webGLData) */ PIXI.WebGLGraphics.buildLine = function(graphicsData, webGLData) { - // TODO OPTIMISE! - - var wrap = true; - var points = graphicsData.points; - if(points.length === 0)return; - - // if the line width is an odd number add 0.5 to align to a whole pixel - if(graphicsData.lineWidth%2) - { - for (var i = 0; i < points.length; i++) { - points[i] += 0.5; - }; - } + // TODO OPTIMISE! + var i = 0; - // get first and last point.. figure out the middle! - var firstPoint = new PIXI.Point( points[0], points[1] ); - var lastPoint = new PIXI.Point( points[points.length - 2], points[points.length - 1] ); - - // if the first point is the last point - goona have issues :) - if(firstPoint.x == lastPoint.x && firstPoint.y == lastPoint.y) - { - points.pop(); - points.pop(); - - lastPoint = new PIXI.Point( points[points.length - 2], points[points.length - 1] ); - - var midPointX = lastPoint.x + (firstPoint.x - lastPoint.x) *0.5; - var midPointY = lastPoint.y + (firstPoint.y - lastPoint.y) *0.5; - - points.unshift(midPointX, midPointY); - points.push(midPointX, midPointY) - } - - var verts = webGLData.points; - var indices = webGLData.indices; - var length = points.length / 2; - var indexCount = points.length; - var indexStart = verts.length/6; - - // DRAW the Line - var width = graphicsData.lineWidth / 2; - - // sort color - var color = HEXtoRGB(graphicsData.lineColor); - var alpha = graphicsData.lineAlpha; - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var p1x, p1y, p2x, p2y, p3x, p3y; - var perpx, perpy, perp2x, perp2y, perp3x, perp3y; - var ipx, ipy; - var a1, b1, c1, a2, b2, c2; - var denom, pdist, dist; - - p1x = points[0]; - p1y = points[1]; - - p2x = points[2]; - p2y = points[3]; - - perpx = -(p1y - p2y); - perpy = p1x - p2x; - - dist = Math.sqrt(perpx*perpx + perpy*perpy); - - perpx /= dist; - perpy /= dist; - perpx *= width; - perpy *= width; - - // start - verts.push(p1x - perpx , p1y - perpy, - r, g, b, alpha); - - verts.push(p1x + perpx , p1y + perpy, - r, g, b, alpha); - - for (var i = 1; i < length-1; i++) - { - p1x = points[(i-1)*2]; - p1y = points[(i-1)*2 + 1]; - - p2x = points[(i)*2] - p2y = points[(i)*2 + 1] - - p3x = points[(i+1)*2]; - p3y = points[(i+1)*2 + 1]; - - perpx = -(p1y - p2y); - perpy = p1x - p2x; - - dist = Math.sqrt(perpx*perpx + perpy*perpy); - perpx /= dist; - perpy /= dist; - perpx *= width; - perpy *= width; + var points = graphicsData.points; + if(points.length === 0)return; - perp2x = -(p2y - p3y); - perp2y = p2x - p3x; - - dist = Math.sqrt(perp2x*perp2x + perp2y*perp2y); - perp2x /= dist; - perp2y /= dist; - perp2x *= width; - perp2y *= width; - - a1 = (-perpy + p1y) - (-perpy + p2y); - b1 = (-perpx + p2x) - (-perpx + p1x); - c1 = (-perpx + p1x) * (-perpy + p2y) - (-perpx + p2x) * (-perpy + p1y); - a2 = (-perp2y + p3y) - (-perp2y + p2y); - b2 = (-perp2x + p2x) - (-perp2x + p3x); - c2 = (-perp2x + p3x) * (-perp2y + p2y) - (-perp2x + p2x) * (-perp2y + p3y); - - denom = a1*b2 - a2*b1; + // if the line width is an odd number add 0.5 to align to a whole pixel + if(graphicsData.lineWidth%2) + { + for (i = 0; i < points.length; i++) { + points[i] += 0.5; + } + } - if(Math.abs(denom) < 0.1 ) - { - - denom+=10.1; - verts.push(p2x - perpx , p2y - perpy, - r, g, b, alpha); - - verts.push(p2x + perpx , p2y + perpy, - r, g, b, alpha); - - continue; - } - - px = (b1*c2 - b2*c1)/denom; - py = (a2*c1 - a1*c2)/denom; - - - pdist = (px -p2x) * (px -p2x) + (py -p2y) + (py -p2y); - + // get first and last point.. figure out the middle! + var firstPoint = new PIXI.Point( points[0], points[1] ); + var lastPoint = new PIXI.Point( points[points.length - 2], points[points.length - 1] ); - if(pdist > 140 * 140) - { - perp3x = perpx - perp2x; - perp3y = perpy - perp2y; - - dist = Math.sqrt(perp3x*perp3x + perp3y*perp3y); - perp3x /= dist; - perp3y /= dist; - perp3x *= width; - perp3y *= width; - - verts.push(p2x - perp3x, p2y -perp3y); - verts.push(r, g, b, alpha); - - verts.push(p2x + perp3x, p2y +perp3y); - verts.push(r, g, b, alpha); - - verts.push(p2x - perp3x, p2y -perp3y); - verts.push(r, g, b, alpha); - - indexCount++; - } - else - { + // if the first point is the last point - goona have issues :) + if(firstPoint.x === lastPoint.x && firstPoint.y === lastPoint.y) + { + points.pop(); + points.pop(); - verts.push(px , py); - verts.push(r, g, b, alpha); - - verts.push(p2x - (px-p2x), p2y - (py - p2y)); - verts.push(r, g, b, alpha); - } - } - - p1x = points[(length-2)*2] - p1y = points[(length-2)*2 + 1] - - p2x = points[(length-1)*2] - p2y = points[(length-1)*2 + 1] - - perpx = -(p1y - p2y) - perpy = p1x - p2x; - - dist = Math.sqrt(perpx*perpx + perpy*perpy); - perpx /= dist; - perpy /= dist; - perpx *= width; - perpy *= width; - - verts.push(p2x - perpx , p2y - perpy) - verts.push(r, g, b, alpha); - - verts.push(p2x + perpx , p2y + perpy) - verts.push(r, g, b, alpha); - - indices.push(indexStart); - - for (var i=0; i < indexCount; i++) - { - indices.push(indexStart++); - }; - - indices.push(indexStart-1); -} + lastPoint = new PIXI.Point( points[points.length - 2], points[points.length - 1] ); + + var midPointX = lastPoint.x + (firstPoint.x - lastPoint.x) *0.5; + var midPointY = lastPoint.y + (firstPoint.y - lastPoint.y) *0.5; + + points.unshift(midPointX, midPointY); + points.push(midPointX, midPointY); + } + + var verts = webGLData.points; + var indices = webGLData.indices; + var length = points.length / 2; + var indexCount = points.length; + var indexStart = verts.length/6; + + // DRAW the Line + var width = graphicsData.lineWidth / 2; + + // sort color + var color = PIXI.hex2rgb(graphicsData.lineColor); + var alpha = graphicsData.lineAlpha; + var r = color[0] * alpha; + var g = color[1] * alpha; + var b = color[2] * alpha; + + var px, py, p1x, p1y, p2x, p2y, p3x, p3y; + var perpx, perpy, perp2x, perp2y, perp3x, perp3y; + var a1, b1, c1, a2, b2, c2; + var denom, pdist, dist; + + p1x = points[0]; + p1y = points[1]; + + p2x = points[2]; + p2y = points[3]; + + perpx = -(p1y - p2y); + perpy = p1x - p2x; + + dist = Math.sqrt(perpx*perpx + perpy*perpy); + + perpx /= dist; + perpy /= dist; + perpx *= width; + perpy *= width; + + // start + verts.push(p1x - perpx , p1y - perpy, + r, g, b, alpha); + + verts.push(p1x + perpx , p1y + perpy, + r, g, b, alpha); + + for (i = 1; i < length-1; i++) + { + p1x = points[(i-1)*2]; + p1y = points[(i-1)*2 + 1]; + + p2x = points[(i)*2]; + p2y = points[(i)*2 + 1]; + + p3x = points[(i+1)*2]; + p3y = points[(i+1)*2 + 1]; + + perpx = -(p1y - p2y); + perpy = p1x - p2x; + + dist = Math.sqrt(perpx*perpx + perpy*perpy); + perpx /= dist; + perpy /= dist; + perpx *= width; + perpy *= width; + + perp2x = -(p2y - p3y); + perp2y = p2x - p3x; + + dist = Math.sqrt(perp2x*perp2x + perp2y*perp2y); + perp2x /= dist; + perp2y /= dist; + perp2x *= width; + perp2y *= width; + + a1 = (-perpy + p1y) - (-perpy + p2y); + b1 = (-perpx + p2x) - (-perpx + p1x); + c1 = (-perpx + p1x) * (-perpy + p2y) - (-perpx + p2x) * (-perpy + p1y); + a2 = (-perp2y + p3y) - (-perp2y + p2y); + b2 = (-perp2x + p2x) - (-perp2x + p3x); + c2 = (-perp2x + p3x) * (-perp2y + p2y) - (-perp2x + p2x) * (-perp2y + p3y); + + denom = a1*b2 - a2*b1; + + if(Math.abs(denom) < 0.1 ) + { + + denom+=10.1; + verts.push(p2x - perpx , p2y - perpy, + r, g, b, alpha); + + verts.push(p2x + perpx , p2y + perpy, + r, g, b, alpha); + + continue; + } + + px = (b1*c2 - b2*c1)/denom; + py = (a2*c1 - a1*c2)/denom; + + + pdist = (px -p2x) * (px -p2x) + (py -p2y) + (py -p2y); + + + if(pdist > 140 * 140) + { + perp3x = perpx - perp2x; + perp3y = perpy - perp2y; + + dist = Math.sqrt(perp3x*perp3x + perp3y*perp3y); + perp3x /= dist; + perp3y /= dist; + perp3x *= width; + perp3y *= width; + + verts.push(p2x - perp3x, p2y -perp3y); + verts.push(r, g, b, alpha); + + verts.push(p2x + perp3x, p2y +perp3y); + verts.push(r, g, b, alpha); + + verts.push(p2x - perp3x, p2y -perp3y); + verts.push(r, g, b, alpha); + + indexCount++; + } + else + { + + verts.push(px , py); + verts.push(r, g, b, alpha); + + verts.push(p2x - (px-p2x), p2y - (py - p2y)); + verts.push(r, g, b, alpha); + } + } + + p1x = points[(length-2)*2]; + p1y = points[(length-2)*2 + 1]; + + p2x = points[(length-1)*2]; + p2y = points[(length-1)*2 + 1]; + + perpx = -(p1y - p2y); + perpy = p1x - p2x; + + dist = Math.sqrt(perpx*perpx + perpy*perpy); + perpx /= dist; + perpy /= dist; + perpx *= width; + perpy *= width; + + verts.push(p2x - perpx , p2y - perpy); + verts.push(r, g, b, alpha); + + verts.push(p2x + perpx , p2y + perpy); + verts.push(r, g, b, alpha); + + indices.push(indexStart); + + for (i = 0; i < indexCount; i++) + { + indices.push(indexStart++); + } + + indices.push(indexStart-1); +}; /** * Builds a polygon to draw @@ -5535,49 +5510,43 @@ PIXI.WebGLGraphics.buildLine = function(graphicsData, webGLData) */ PIXI.WebGLGraphics.buildPoly = function(graphicsData, webGLData) { - var points = graphicsData.points; - if(points.length < 6)return; - - // get first and last point.. figure out the middle! - var verts = webGLData.points; - var indices = webGLData.indices; - - var length = points.length / 2; - - // sort color - var color = HEXtoRGB(graphicsData.fillColor); - var alpha = graphicsData.fillAlpha; - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var triangles = PIXI.PolyK.Triangulate(points); - - var vertPos = verts.length / 6; - - for (var i=0; i < triangles.length; i+=3) - { - indices.push(triangles[i] + vertPos); - indices.push(triangles[i] + vertPos); - indices.push(triangles[i+1] + vertPos); - indices.push(triangles[i+2] +vertPos); - indices.push(triangles[i+2] + vertPos); - }; - - for (var i = 0; i < length; i++) - { - verts.push(points[i * 2], points[i * 2 + 1], - r, g, b, alpha); - }; -} + var points = graphicsData.points; + if(points.length < 6)return; -function HEXtoRGB(hex) { - return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255]; -} + // get first and last point.. figure out the middle! + var verts = webGLData.points; + var indices = webGLData.indices; + var length = points.length / 2; + // sort color + var color = PIXI.hex2rgb(graphicsData.fillColor); + var alpha = graphicsData.fillAlpha; + var r = color[0] * alpha; + var g = color[1] * alpha; + var b = color[2] * alpha; + var triangles = PIXI.PolyK.Triangulate(points); + var vertPos = verts.length / 6; + + var i = 0; + + for (i = 0; i < triangles.length; i+=3) + { + indices.push(triangles[i] + vertPos); + indices.push(triangles[i] + vertPos); + indices.push(triangles[i+1] + vertPos); + indices.push(triangles[i+2] +vertPos); + indices.push(triangles[i+2] + vertPos); + } + + for (i = 0; i < length; i++) + { + verts.push(points[i * 2], points[i * 2 + 1], + r, g, b, alpha); + } +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 @@ -5587,7 +5556,7 @@ PIXI._defaultFrame = new PIXI.Rectangle(0,0,1,1); // an instance of the gl context.. // only one at the moment :/ -PIXI.gl; +PIXI.gl = null; /** * the WebGLRenderer is draws the stage and all its content onto a webGL enabled canvas. This renderer @@ -5602,68 +5571,68 @@ PIXI.gl; * @param view {Canvas} the canvas to use as a view, optional * @param transparent=false {Boolean} the transparency of the render view, default false * @param antialias=false {Boolean} sets antialias (only applicable in chrome at the moment) - * + * */ PIXI.WebGLRenderer = function(width, height, view, transparent, antialias) { - // do a catch.. only 1 webGL renderer.. + // do a catch.. only 1 webGL renderer.. - this.transparent = !!transparent; + this.transparent = !!transparent; - this.width = width || 800; - this.height = height || 600; + this.width = width || 800; + this.height = height || 600; - this.view = view || document.createElement( 'canvas' ); + this.view = view || document.createElement( 'canvas' ); this.view.width = this.width; - this.view.height = this.height; + this.view.height = this.height; - // deal with losing context.. + // deal with losing context.. var scope = this; - this.view.addEventListener('webglcontextlost', function(event) { scope.handleContextLost(event); }, false) - this.view.addEventListener('webglcontextrestored', function(event) { scope.handleContextRestored(event); }, false) + this.view.addEventListener('webglcontextlost', function(event) { scope.handleContextLost(event); }, false); + this.view.addEventListener('webglcontextrestored', function(event) { scope.handleContextRestored(event); }, false); - this.batchs = []; + this.batchs = []; - var options = { - alpha: this.transparent, - antialias:!!antialias, // SPEED UP?? - premultipliedAlpha:false, - stencil:true - } + var options = { + alpha: this.transparent, + antialias:!!antialias, // SPEED UP?? + premultipliedAlpha:false, + stencil:true + }; - //try 'experimental-webgl' - try { - PIXI.gl = this.gl = this.view.getContext("experimental-webgl", options); - } catch (e) { - //try 'webgl' - try { - PIXI.gl = this.gl = this.view.getContext("webgl", options); - } catch (e) { - // fail, not able to get a context - throw new Error(" This browser does not support webGL. Try using the canvas renderer" + this); - } - } + //try 'experimental-webgl' + try { + PIXI.gl = this.gl = this.view.getContext('experimental-webgl', options); + } catch (e) { + //try 'webgl' + try { + PIXI.gl = this.gl = this.view.getContext('webgl', options); + } catch (e2) { + // fail, not able to get a context + throw new Error(' This browser does not support webGL. Try using the canvas renderer' + this); + } + } PIXI.initDefaultShaders(); - - + + // PIXI.activateDefaultShader(); var gl = this.gl; - + gl.useProgram(PIXI.defaultShader.program); PIXI.WebGLRenderer.gl = gl; this.batch = new PIXI.WebGLBatch(gl); - gl.disable(gl.DEPTH_TEST); - gl.disable(gl.CULL_FACE); + gl.disable(gl.DEPTH_TEST); + gl.disable(gl.CULL_FACE); gl.enable(gl.BLEND); - gl.colorMask(true, true, true, this.transparent); + gl.colorMask(true, true, true, this.transparent); PIXI.projection = new PIXI.Point(400, 300); PIXI.offset = new PIXI.Point(0, 0); @@ -5673,11 +5642,11 @@ PIXI.WebGLRenderer = function(width, height, view, transparent, antialias) this.resize(this.width, this.height); this.contextLost = false; - //PIXI.pushShader(PIXI.defaultShader); + //PIXI.pushShader(PIXI.defaultShader); this.stageRenderGroup = new PIXI.WebGLRenderGroup(this.gl, this.transparent); // this.stageRenderGroup. = this.transparent -} +}; // constructor PIXI.WebGLRenderer.prototype.constructor = PIXI.WebGLRenderer; @@ -5688,19 +5657,19 @@ PIXI.WebGLRenderer.prototype.constructor = PIXI.WebGLRenderer; * @static * @method getBatch * @return {WebGLBatch} - * @private + * @private */ PIXI.WebGLRenderer.getBatch = function() { - if(PIXI._batchs.length === 0) - { - return new PIXI.WebGLBatch(PIXI.WebGLRenderer.gl); - } - else - { - return PIXI._batchs.pop(); - } -} + if(PIXI._batchs.length === 0) + { + return new PIXI.WebGLBatch(PIXI.WebGLRenderer.gl); + } + else + { + return PIXI._batchs.pop(); + } +}; /** * Puts a batch back into the pool @@ -5712,9 +5681,9 @@ PIXI.WebGLRenderer.getBatch = function() */ PIXI.WebGLRenderer.returnBatch = function(batch) { - batch.clean(); - PIXI._batchs.push(batch); -} + batch.clean(); + PIXI._batchs.push(batch); +}; /** * Renders the stage to its webGL view @@ -5724,68 +5693,68 @@ PIXI.WebGLRenderer.returnBatch = function(batch) */ PIXI.WebGLRenderer.prototype.render = function(stage) { - if(this.contextLost)return; - - - // if rendering a new stage clear the batchs.. - if(this.__stage !== stage) - { - // TODO make this work - // dont think this is needed any more? - this.__stage = stage; - this.stageRenderGroup.setRenderable(stage); - } + if(this.contextLost)return; - // update any textures - PIXI.WebGLRenderer.updateTextures(); - - // update the scene graph - PIXI.visibleCount++; - stage.updateTransform(); - - var gl = this.gl; - - // -- Does this need to be set every frame? -- // - gl.colorMask(true, true, true, this.transparent); - gl.viewport(0, 0, this.width, this.height); - - gl.bindFramebuffer(gl.FRAMEBUFFER, null); - - gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent); - gl.clear(gl.COLOR_BUFFER_BIT); - // HACK TO TEST - - this.stageRenderGroup.backgroundColor = stage.backgroundColorSplit; - - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; - - this.stageRenderGroup.render(PIXI.projection); - - // interaction - // run interaction! - if(stage.interactive) - { - //need to add some events! - if(!stage._interactiveEventsAdded) - { - stage._interactiveEventsAdded = true; - stage.interactionManager.setTarget(this); - } - } - - // after rendering lets confirm all frames that have been uodated.. - if(PIXI.Texture.frameUpdates.length > 0) - { - for (var i=0; i < PIXI.Texture.frameUpdates.length; i++) - { - PIXI.Texture.frameUpdates[i].updateFrame = false; - }; - - PIXI.Texture.frameUpdates = []; - } -} + // if rendering a new stage clear the batchs.. + if(this.__stage !== stage) + { + // TODO make this work + // dont think this is needed any more? + this.__stage = stage; + this.stageRenderGroup.setRenderable(stage); + } + + // update any textures + PIXI.WebGLRenderer.updateTextures(); + + // update the scene graph + PIXI.visibleCount++; + stage.updateTransform(); + + var gl = this.gl; + + // -- Does this need to be set every frame? -- // + gl.colorMask(true, true, true, this.transparent); + gl.viewport(0, 0, this.width, this.height); + + gl.bindFramebuffer(gl.FRAMEBUFFER, null); + + gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent); + gl.clear(gl.COLOR_BUFFER_BIT); + + // HACK TO TEST + + this.stageRenderGroup.backgroundColor = stage.backgroundColorSplit; + + PIXI.projection.x = this.width/2; + PIXI.projection.y = -this.height/2; + + this.stageRenderGroup.render(PIXI.projection); + + // interaction + // run interaction! + if(stage.interactive) + { + //need to add some events! + if(!stage._interactiveEventsAdded) + { + stage._interactiveEventsAdded = true; + stage.interactionManager.setTarget(this); + } + } + + // after rendering lets confirm all frames that have been uodated.. + if(PIXI.Texture.frameUpdates.length > 0) + { + for (var i=0; i < PIXI.Texture.frameUpdates.length; i++) + { + PIXI.Texture.frameUpdates[i].updateFrame = false; + } + + PIXI.Texture.frameUpdates = []; + } +}; /** * Updates the textures loaded into this webgl renderer @@ -5796,12 +5765,18 @@ PIXI.WebGLRenderer.prototype.render = function(stage) */ PIXI.WebGLRenderer.updateTextures = function() { - //TODO break this out into a texture manager... - for (var i=0; i < PIXI.texturesToUpdate.length; i++) PIXI.WebGLRenderer.updateTexture(PIXI.texturesToUpdate[i]); - for (var i=0; i < PIXI.texturesToDestroy.length; i++) PIXI.WebGLRenderer.destroyTexture(PIXI.texturesToDestroy[i]); - PIXI.texturesToUpdate = []; - PIXI.texturesToDestroy = []; -} + var i = 0; + + //TODO break this out into a texture manager... + for (i = 0; i < PIXI.texturesToUpdate.length; i++) + PIXI.WebGLRenderer.updateTexture(PIXI.texturesToUpdate[i]); + + for (i = 0; i < PIXI.texturesToDestroy.length; i++) + PIXI.WebGLRenderer.destroyTexture(PIXI.texturesToDestroy[i]); + + PIXI.texturesToUpdate = []; + PIXI.texturesToDestroy = []; +}; /** * Updates a loaded webgl texture @@ -5813,39 +5788,39 @@ PIXI.WebGLRenderer.updateTextures = function() */ PIXI.WebGLRenderer.updateTexture = function(texture) { - //TODO break this out into a texture manager... - var gl = PIXI.gl; - - if(!texture._glTexture) - { - texture._glTexture = gl.createTexture(); - } + //TODO break this out into a texture manager... + var gl = PIXI.gl; - if(texture.hasLoaded) - { - gl.bindTexture(gl.TEXTURE_2D, texture._glTexture); - gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true); + if(!texture._glTexture) + { + texture._glTexture = gl.createTexture(); + } - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); + if(texture.hasLoaded) + { + gl.bindTexture(gl.TEXTURE_2D, texture._glTexture); + gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true); - // reguler... + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, texture.scaleMode === PIXI.BaseTexture.SCALE_MODE.LINEAR ? gl.LINEAR : gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === PIXI.BaseTexture.SCALE_MODE.LINEAR ? gl.LINEAR : gl.NEAREST); - if(!texture._powerOf2) - { - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - } - else - { - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); - } + // reguler... - gl.bindTexture(gl.TEXTURE_2D, null); - } -} + if(!texture._powerOf2) + { + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + } + else + { + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); + } + + gl.bindTexture(gl.TEXTURE_2D, null); + } +}; /** * Destroys a loaded webgl texture @@ -5856,15 +5831,15 @@ PIXI.WebGLRenderer.updateTexture = function(texture) */ PIXI.WebGLRenderer.destroyTexture = function(texture) { - //TODO break this out into a texture manager... - var gl = PIXI.gl; + //TODO break this out into a texture manager... + var gl = PIXI.gl; - if(texture._glTexture) - { - texture._glTexture = gl.createTexture(); - gl.deleteTexture(gl.TEXTURE_2D, texture._glTexture); - } -} + if(texture._glTexture) + { + texture._glTexture = gl.createTexture(); + gl.deleteTexture(gl.TEXTURE_2D, texture._glTexture); + } +}; /** * resizes the webGL view to the specified width and height @@ -5875,27 +5850,27 @@ PIXI.WebGLRenderer.destroyTexture = function(texture) */ PIXI.WebGLRenderer.prototype.resize = function(width, height) { - this.width = width; - this.height = height; + this.width = width; + this.height = height; - this.view.width = width; - this.view.height = height; + this.view.width = width; + this.view.height = height; - this.gl.viewport(0, 0, this.width, this.height); + this.gl.viewport(0, 0, this.width, this.height); - //var projectionMatrix = this.projectionMatrix; + //var projectionMatrix = this.projectionMatrix; - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; - - //PIXI.size.x = this.width/2; - //PIXI.size.y = -this.height/2; + PIXI.projection.x = this.width/2; + PIXI.projection.y = -this.height/2; -// projectionMatrix[0] = 2/this.width; -// projectionMatrix[5] = -2/this.height; -// projectionMatrix[12] = -1; -// projectionMatrix[13] = 1; -} + //PIXI.size.x = this.width/2; + //PIXI.size.y = -this.height/2; + +// projectionMatrix[0] = 2/this.width; +// projectionMatrix[5] = -2/this.height; +// projectionMatrix[12] = -1; +// projectionMatrix[13] = 1; +}; /** * Handles a lost webgl context @@ -5906,9 +5881,9 @@ PIXI.WebGLRenderer.prototype.resize = function(width, height) */ PIXI.WebGLRenderer.prototype.handleContextLost = function(event) { - event.preventDefault(); - this.contextLost = true; -} + event.preventDefault(); + this.contextLost = true; +}; /** * Handles a restored webgl context @@ -5917,31 +5892,31 @@ PIXI.WebGLRenderer.prototype.handleContextLost = function(event) * @param event {Event} * @private */ -PIXI.WebGLRenderer.prototype.handleContextRestored = function(event) +PIXI.WebGLRenderer.prototype.handleContextRestored = function() { - this.gl = this.view.getContext("experimental-webgl", { - alpha: true + this.gl = this.view.getContext('experimental-webgl', { + alpha: true }); - this.initShaders(); + this.initShaders(); - for(var key in PIXI.TextureCache) - { - var texture = PIXI.TextureCache[key].baseTexture; - texture._glTexture = null; - PIXI.WebGLRenderer.updateTexture(texture); - }; + for(var key in PIXI.TextureCache) + { + var texture = PIXI.TextureCache[key].baseTexture; + texture._glTexture = null; + PIXI.WebGLRenderer.updateTexture(texture); + } - for (var i=0; i < this.batchs.length; i++) - { - this.batchs[i].restoreLostContext(this.gl)// - this.batchs[i].dirty = true; - }; + for (var i=0; i < this.batchs.length; i++) + { + this.batchs[i].restoreLostContext(this.gl); + this.batchs[i].dirty = true; + } - PIXI._restoreBatchs(this.gl); + PIXI._restoreBatchs(this.gl); - this.contextLost = false; -} + this.contextLost = false; +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 @@ -6720,7 +6695,7 @@ PIXI.WebGLRenderGroup.prototype.removeObject = function(displayObject) // ok so.. check to see if you adjacent batchs should be joined. // TODO may optimise? - if(index === 0 || index == this.batchs.length-1) + if(index == 0 || index == this.batchs.length-1) { // wha - eva! just get of the empty batch! this.batchs.splice(index, 1); @@ -6793,7 +6768,7 @@ PIXI.WebGLRenderGroup.prototype.initTilingSprite = function(sprite) gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, sprite._indexBuffer); gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, sprite.indices, gl.STATIC_DRAW); -// return ( (x > 0) && ((x & (x - 1)) === 0) ); +// return ( (x > 0) && ((x & (x - 1)) == 0) ); if(sprite.texture.baseTexture._glTexture) { @@ -6979,73 +6954,70 @@ PIXI.WebGLRenderGroup.prototype.initStrip = function(strip) * @author Mat Groves http://matgroves.com/ @Doormat23 */ - -PIXI.initDefaultShaders = function() +PIXI.initDefaultShaders = function() { - PIXI.primitiveShader = new PIXI.PrimitiveShader(); - PIXI.primitiveShader.init(); + PIXI.primitiveShader = new PIXI.PrimitiveShader(); + PIXI.primitiveShader.init(); - PIXI.stripShader = new PIXI.StripShader(); - PIXI.stripShader.init(); + PIXI.stripShader = new PIXI.StripShader(); + PIXI.stripShader.init(); - PIXI.defaultShader = new PIXI.PixiShader(); - PIXI.defaultShader.init(); + PIXI.defaultShader = new PIXI.PixiShader(); + PIXI.defaultShader.init(); - var gl = PIXI.gl; - var shaderProgram = PIXI.defaultShader.program; - + var gl = PIXI.gl; + var shaderProgram = PIXI.defaultShader.program; - gl.useProgram(shaderProgram); - - gl.enableVertexAttribArray(PIXI.defaultShader.aVertexPosition); - gl.enableVertexAttribArray(PIXI.defaultShader.colorAttribute); - gl.enableVertexAttribArray(PIXI.defaultShader.aTextureCoord); -} + gl.useProgram(shaderProgram); + + gl.enableVertexAttribArray(PIXI.defaultShader.aVertexPosition); + gl.enableVertexAttribArray(PIXI.defaultShader.colorAttribute); + gl.enableVertexAttribArray(PIXI.defaultShader.aTextureCoord); +}; PIXI.activatePrimitiveShader = function() { - var gl = PIXI.gl; - - gl.useProgram(PIXI.primitiveShader.program); - - gl.disableVertexAttribArray(PIXI.defaultShader.aVertexPosition); - gl.disableVertexAttribArray(PIXI.defaultShader.colorAttribute); - gl.disableVertexAttribArray(PIXI.defaultShader.aTextureCoord); + var gl = PIXI.gl; - gl.enableVertexAttribArray(PIXI.primitiveShader.aVertexPosition); - gl.enableVertexAttribArray(PIXI.primitiveShader.colorAttribute); -} + gl.useProgram(PIXI.primitiveShader.program); + + gl.disableVertexAttribArray(PIXI.defaultShader.aVertexPosition); + gl.disableVertexAttribArray(PIXI.defaultShader.colorAttribute); + gl.disableVertexAttribArray(PIXI.defaultShader.aTextureCoord); + + gl.enableVertexAttribArray(PIXI.primitiveShader.aVertexPosition); + gl.enableVertexAttribArray(PIXI.primitiveShader.colorAttribute); +}; PIXI.deactivatePrimitiveShader = function() { - var gl = PIXI.gl; + var gl = PIXI.gl; - gl.useProgram(PIXI.defaultShader.program); - - gl.disableVertexAttribArray(PIXI.primitiveShader.aVertexPosition); - gl.disableVertexAttribArray(PIXI.primitiveShader.colorAttribute); + gl.useProgram(PIXI.defaultShader.program); - gl.enableVertexAttribArray(PIXI.defaultShader.aVertexPosition); - gl.enableVertexAttribArray(PIXI.defaultShader.colorAttribute); - gl.enableVertexAttribArray(PIXI.defaultShader.aTextureCoord); + gl.disableVertexAttribArray(PIXI.primitiveShader.aVertexPosition); + gl.disableVertexAttribArray(PIXI.primitiveShader.colorAttribute); -} + gl.enableVertexAttribArray(PIXI.defaultShader.aVertexPosition); + gl.enableVertexAttribArray(PIXI.defaultShader.colorAttribute); + gl.enableVertexAttribArray(PIXI.defaultShader.aTextureCoord); +}; PIXI.activateStripShader = function() { - var gl = PIXI.gl; - - gl.useProgram(PIXI.stripShader.program); + var gl = PIXI.gl; + + gl.useProgram(PIXI.stripShader.program); // gl.disableVertexAttribArray(PIXI.defaultShader.aTextureCoord); -} +}; PIXI.deactivateStripShader = function() { - var gl = PIXI.gl; + var gl = PIXI.gl; - gl.useProgram(PIXI.defaultShader.program); - //gl.enableVertexAttribArray(PIXI.defaultShader.aTextureCoord); -} + gl.useProgram(PIXI.defaultShader.program); + //gl.enableVertexAttribArray(PIXI.defaultShader.aTextureCoord); +}; /* @@ -7054,55 +7026,54 @@ SHADER COMPILER HELPERS PIXI.CompileVertexShader = function(gl, shaderSrc) { - return PIXI._CompileShader(gl, shaderSrc, gl.VERTEX_SHADER); -} + return PIXI._CompileShader(gl, shaderSrc, gl.VERTEX_SHADER); +}; PIXI.CompileFragmentShader = function(gl, shaderSrc) { - return PIXI._CompileShader(gl, shaderSrc, gl.FRAGMENT_SHADER); -} + return PIXI._CompileShader(gl, shaderSrc, gl.FRAGMENT_SHADER); +}; PIXI._CompileShader = function(gl, shaderSrc, shaderType) { - var src = shaderSrc.join("\n"); - var shader = gl.createShader(shaderType); - gl.shaderSource(shader, src); - gl.compileShader(shader); + var src = shaderSrc.join("\n"); + var shader = gl.createShader(shaderType); + gl.shaderSource(shader, src); + gl.compileShader(shader); - if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) { - console.log(gl.getShaderInfoLog(shader)); - return null; - } - - return shader; -} + if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) { + window.console.log(gl.getShaderInfoLog(shader)); + return null; + } + return shader; +}; PIXI.compileProgram = function(vertexSrc, fragmentSrc) { - var gl = PIXI.gl; - var fragmentShader = PIXI.CompileFragmentShader(gl, fragmentSrc); - var vertexShader = PIXI.CompileVertexShader(gl, vertexSrc); - - var shaderProgram = gl.createProgram(); - + var gl = PIXI.gl; + var fragmentShader = PIXI.CompileFragmentShader(gl, fragmentSrc); + var vertexShader = PIXI.CompileVertexShader(gl, vertexSrc); + + var shaderProgram = gl.createProgram(); + gl.attachShader(shaderProgram, vertexShader); gl.attachShader(shaderProgram, fragmentShader); gl.linkProgram(shaderProgram); if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) { - console.log("Could not initialise shaders"); + window.console.log("Could not initialise shaders"); } - return shaderProgram; -} + return shaderProgram; +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ /** - * A Text Object will create a line(s) of text using bitmap font. To split a line you can use "\n", "\r" or "\r\n" + * A Text Object will create a line(s) of text using bitmap font. To split a line you can use '\n', '\r' or '\r\n' * You can generate the fnt files using * http://www.angelcode.com/products/bmfont/ for windows or * http://www.bmglyph.com/ for mac. @@ -7112,8 +7083,8 @@ PIXI.compileProgram = function(vertexSrc, fragmentSrc) * @constructor * @param text {String} The copy that you would like the text to display * @param style {Object} The style parameters - * @param style.font {String} The size (optional) and bitmap font id (required) eq "Arial" or "20px Arial" (must have loaded previously) - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") + * @param style.font {String} The size (optional) and bitmap font id (required) eq 'Arial' or '20px Arial' (must have loaded previously) + * @param [style.align='left'] {String} An alignment of the multiline text ('left', 'center' or 'right') */ PIXI.BitmapText = function(text, style) { @@ -7122,8 +7093,7 @@ PIXI.BitmapText = function(text, style) this.setText(text); this.setStyle(style); this.updateText(); - this.dirty = false - + this.dirty = false; }; // constructor @@ -7138,7 +7108,7 @@ PIXI.BitmapText.prototype.constructor = PIXI.BitmapText; */ PIXI.BitmapText.prototype.setText = function(text) { - this.text = text || " "; + this.text = text || ' '; this.dirty = true; }; @@ -7147,16 +7117,16 @@ PIXI.BitmapText.prototype.setText = function(text) * * @method setStyle * @param style {Object} The style parameters - * @param style.font {String} The size (optional) and bitmap font id (required) eq "Arial" or "20px Arial" (must have loaded previously) - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") + * @param style.font {String} The size (optional) and bitmap font id (required) eq 'Arial' or '20px Arial' (must have loaded previously) + * @param [style.align='left'] {String} An alignment of the multiline text ('left', 'center' or 'right') */ PIXI.BitmapText.prototype.setStyle = function(style) { style = style || {}; - style.align = style.align || "left"; + style.align = style.align || 'left'; this.style = style; - var font = style.font.split(" "); + var font = style.font.split(' '); this.fontName = font[font.length - 1]; this.fontSize = font.length >= 2 ? parseInt(font[font.length - 2], 10) : PIXI.BitmapText.fonts[this.fontName].size; @@ -7199,7 +7169,7 @@ PIXI.BitmapText.prototype.updateText = function() if(prevCharCode && charData[prevCharCode]) { - pos.x += charData.kerning[prevCharCode]; + pos.x += charData.kerning[prevCharCode]; } chars.push({texture:charData.texture, line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)}); pos.x += charData.xAdvance; @@ -7214,11 +7184,11 @@ PIXI.BitmapText.prototype.updateText = function() for(i = 0; i <= line; i++) { var alignOffset = 0; - if(this.style.align == "right") + if(this.style.align === 'right') { alignOffset = maxLineWidth - lineWidths[i]; } - else if(this.style.align == "center") + else if(this.style.align === 'center') { alignOffset = (maxLineWidth - lineWidths[i]) / 2; } @@ -7227,14 +7197,14 @@ PIXI.BitmapText.prototype.updateText = function() for(i = 0; i < chars.length; i++) { - var c = new PIXI.Sprite(chars[i].texture)//PIXI.Sprite.fromFrame(chars[i].charCode); + var c = new PIXI.Sprite(chars[i].texture); //PIXI.Sprite.fromFrame(chars[i].charCode); c.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale; c.position.y = chars[i].position.y * scale; c.scale.x = c.scale.y = scale; this.addChild(c); } - this.width = pos.x * scale; + this.width = maxLineWidth * scale; this.height = (pos.y + data.lineHeight) * scale; }; @@ -7246,8 +7216,8 @@ PIXI.BitmapText.prototype.updateText = function() */ PIXI.BitmapText.prototype.updateTransform = function() { - if(this.dirty) - { + if(this.dirty) + { while(this.children.length > 0) { this.removeChild(this.getChildAt(0)); @@ -7255,9 +7225,9 @@ PIXI.BitmapText.prototype.updateTransform = function() this.updateText(); this.dirty = false; - } + } - PIXI.DisplayObjectContainer.prototype.updateTransform.call(this); + PIXI.DisplayObjectContainer.prototype.updateTransform.call(this); }; PIXI.BitmapText.fonts = {}; @@ -7267,25 +7237,25 @@ PIXI.BitmapText.fonts = {}; */ /** - * A Text Object will create a line(s) of text to split a line you can use "\n" + * A Text Object will create a line(s) of text to split a line you can use '\n' * * @class Text * @extends Sprite * @constructor * @param text {String} The copy that you would like the text to display * @param [style] {Object} The style parameters - * @param [style.font] {String} default "bold 20pt Arial" The style and size of the font - * @param [style.fill="black"] {Object} A canvas fillstyle that will be used on the text eg "red", "#00FF00" - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") - * @param [style.stroke] {String} A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00" + * @param [style.font] {String} default 'bold 20pt Arial' The style and size of the font + * @param [style.fill='black'] {Object} A canvas fillstyle that will be used on the text eg 'red', '#00FF00' + * @param [style.align='left'] {String} An alignment of the multiline text ('left', 'center' or 'right') + * @param [style.stroke] {String} A canvas fillstyle that will be used on the text stroke eg 'blue', '#FCFF00' * @param [style.strokeThickness=0] {Number} A number that represents the thickness of the stroke. Default is 0 (no stroke) * @param [style.wordWrap=false] {Boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {Number} The width at which text will wrap */ PIXI.Text = function(text, style) { - this.canvas = document.createElement("canvas"); - this.context = this.canvas.getContext("2d"); + this.canvas = document.createElement('canvas'); + this.context = this.canvas.getContext('2d'); PIXI.Sprite.call(this, PIXI.Texture.fromCanvas(this.canvas)); this.setText(text); @@ -7304,10 +7274,10 @@ PIXI.Text.prototype.constructor = PIXI.Text; * * @method setStyle * @param [style] {Object} The style parameters - * @param [style.font="bold 20pt Arial"] {String} The style and size of the font - * @param [style.fill="black"] {Object} A canvas fillstyle that will be used on the text eg "red", "#00FF00" - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") - * @param [style.stroke="black"] {String} A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00" + * @param [style.font='bold 20pt Arial'] {String} The style and size of the font + * @param [style.fill='black'] {Object} A canvas fillstyle that will be used on the text eg 'red', '#00FF00' + * @param [style.align='left'] {String} An alignment of the multiline text ('left', 'center' or 'right') + * @param [style.stroke='black'] {String} A canvas fillstyle that will be used on the text stroke eg 'blue', '#FCFF00' * @param [style.strokeThickness=0] {Number} A number that represents the thickness of the stroke. Default is 0 (no stroke) * @param [style.wordWrap=false] {Boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {Number} The width at which text will wrap @@ -7315,10 +7285,10 @@ PIXI.Text.prototype.constructor = PIXI.Text; PIXI.Text.prototype.setStyle = function(style) { style = style || {}; - style.font = style.font || "bold 20pt Arial"; - style.fill = style.fill || "black"; - style.align = style.align || "left"; - style.stroke = style.stroke || "black"; //provide a default, see: https://github.com/GoodBoyDigital/pixi.js/issues/136 + style.font = style.font || 'bold 20pt Arial'; + style.fill = style.fill || 'black'; + style.align = style.align || 'left'; + style.stroke = style.stroke || 'black'; //provide a default, see: https://github.com/GoodBoyDigital/pixi.js/issues/136 style.strokeThickness = style.strokeThickness || 0; style.wordWrap = style.wordWrap || false; style.wordWrapWidth = style.wordWrapWidth || 100; @@ -7327,14 +7297,14 @@ PIXI.Text.prototype.setStyle = function(style) }; /** - * Set the copy for the text object. To split a line you can use "\n" + * Set the copy for the text object. To split a line you can use '\n' * - * @methos setText + * @method setText * @param {String} text The copy that you would like the text to display */ PIXI.Text.prototype.setText = function(text) { - this.text = text.toString() || " "; + this.text = text.toString() || ' '; this.dirty = true; }; @@ -7346,65 +7316,65 @@ PIXI.Text.prototype.setText = function(text) */ PIXI.Text.prototype.updateText = function() { - this.context.font = this.style.font; + this.context.font = this.style.font; - var outputText = this.text; + var outputText = this.text; - // word wrap - // preserve original text - if(this.style.wordWrap)outputText = this.wordWrap(this.text); + // word wrap + // preserve original text + if(this.style.wordWrap)outputText = this.wordWrap(this.text); - //split text into lines - var lines = outputText.split(/(?:\r\n|\r|\n)/); + //split text into lines + var lines = outputText.split(/(?:\r\n|\r|\n)/); - //calculate text width - var lineWidths = []; - var maxLineWidth = 0; - for (var i = 0; i < lines.length; i++) - { - var lineWidth = this.context.measureText(lines[i]).width; - lineWidths[i] = lineWidth; - maxLineWidth = Math.max(maxLineWidth, lineWidth); - } - this.canvas.width = maxLineWidth + this.style.strokeThickness; + //calculate text width + var lineWidths = []; + var maxLineWidth = 0; + for (var i = 0; i < lines.length; i++) + { + var lineWidth = this.context.measureText(lines[i]).width; + lineWidths[i] = lineWidth; + maxLineWidth = Math.max(maxLineWidth, lineWidth); + } + this.canvas.width = maxLineWidth + this.style.strokeThickness; - //calculate text height - var lineHeight = this.determineFontHeight("font: " + this.style.font + ";") + this.style.strokeThickness; - this.canvas.height = lineHeight * lines.length; + //calculate text height + var lineHeight = this.determineFontHeight('font: ' + this.style.font + ';') + this.style.strokeThickness; + this.canvas.height = lineHeight * lines.length; - //set canvas text styles - this.context.fillStyle = this.style.fill; - this.context.font = this.style.font; + //set canvas text styles + this.context.fillStyle = this.style.fill; + this.context.font = this.style.font; - this.context.strokeStyle = this.style.stroke; - this.context.lineWidth = this.style.strokeThickness; + this.context.strokeStyle = this.style.stroke; + this.context.lineWidth = this.style.strokeThickness; - this.context.textBaseline = "top"; + this.context.textBaseline = 'top'; - //draw lines line by line - for (i = 0; i < lines.length; i++) - { - var linePosition = new PIXI.Point(this.style.strokeThickness / 2, this.style.strokeThickness / 2 + i * lineHeight); + //draw lines line by line + for (i = 0; i < lines.length; i++) + { + var linePosition = new PIXI.Point(this.style.strokeThickness / 2, this.style.strokeThickness / 2 + i * lineHeight); - if(this.style.align == "right") - { - linePosition.x += maxLineWidth - lineWidths[i]; - } - else if(this.style.align == "center") - { - linePosition.x += (maxLineWidth - lineWidths[i]) / 2; - } + if(this.style.align === 'right') + { + linePosition.x += maxLineWidth - lineWidths[i]; + } + else if(this.style.align === 'center') + { + linePosition.x += (maxLineWidth - lineWidths[i]) / 2; + } - if(this.style.stroke && this.style.strokeThickness) - { - this.context.strokeText(lines[i], linePosition.x, linePosition.y); - } + if(this.style.stroke && this.style.strokeThickness) + { + this.context.strokeText(lines[i], linePosition.x, linePosition.y); + } - if(this.style.fill) - { - this.context.fillText(lines[i], linePosition.x, linePosition.y); - } - } + if(this.style.fill) + { + this.context.fillText(lines[i], linePosition.x, linePosition.y); + } + } this.updateTexture(); }; @@ -7422,7 +7392,7 @@ PIXI.Text.prototype.updateTexture = function() this.texture.frame.width = this.canvas.width; this.texture.frame.height = this.canvas.height; - this._width = this.canvas.width; + this._width = this.canvas.width; this._height = this.canvas.height; PIXI.texturesToUpdate.push(this.texture.baseTexture); @@ -7436,13 +7406,13 @@ PIXI.Text.prototype.updateTexture = function() */ PIXI.Text.prototype.updateTransform = function() { - if(this.dirty) - { - this.updateText(); - this.dirty = false; - } + if(this.dirty) + { + this.updateText(); + this.dirty = false; + } - PIXI.Sprite.prototype.updateTransform.call(this); + PIXI.Sprite.prototype.updateTransform.call(this); }; /* @@ -7455,26 +7425,26 @@ PIXI.Text.prototype.updateTransform = function() */ PIXI.Text.prototype.determineFontHeight = function(fontStyle) { - // build a little reference dictionary so if the font style has been used return a - // cached version... - var result = PIXI.Text.heightCache[fontStyle]; + // build a little reference dictionary so if the font style has been used return a + // cached version... + var result = PIXI.Text.heightCache[fontStyle]; - if(!result) - { - var body = document.getElementsByTagName("body")[0]; - var dummy = document.createElement("div"); - var dummyText = document.createTextNode("M"); - dummy.appendChild(dummyText); - dummy.setAttribute("style", fontStyle + ';position:absolute;top:0;left:0'); - body.appendChild(dummy); + if(!result) + { + var body = document.getElementsByTagName('body')[0]; + var dummy = document.createElement('div'); + var dummyText = document.createTextNode('M'); + dummy.appendChild(dummyText); + dummy.setAttribute('style', fontStyle + ';position:absolute;top:0;left:0'); + body.appendChild(dummy); - result = dummy.offsetHeight; - PIXI.Text.heightCache[fontStyle] = result; + result = dummy.offsetHeight; + PIXI.Text.heightCache[fontStyle] = result; - body.removeChild(dummy); - } + body.removeChild(dummy); + } - return result; + return result; }; /** @@ -7487,38 +7457,38 @@ PIXI.Text.prototype.determineFontHeight = function(fontStyle) */ PIXI.Text.prototype.wordWrap = function(text) { - // Greedy wrapping algorithm that will wrap words as the line grows longer - // than its horizontal bounds. - var result = ""; - var lines = text.split("\n"); - for (var i = 0; i < lines.length; i++) - { - var spaceLeft = this.style.wordWrapWidth; - var words = lines[i].split(" "); - for (var j = 0; j < words.length; j++) - { - var wordWidth = this.context.measureText(words[j]).width; - var wordWidthWithSpace = wordWidth + this.context.measureText(" ").width; - if(wordWidthWithSpace > spaceLeft) - { - // Skip printing the newline if it's the first word of the line that is - // greater than the word wrap width. - if(j > 0) - { - result += "\n"; - } - result += words[j] + " "; - spaceLeft = this.style.wordWrapWidth - wordWidth; - } - else - { - spaceLeft -= wordWidthWithSpace; - result += words[j] + " "; - } - } - result += "\n"; - } - return result; + // Greedy wrapping algorithm that will wrap words as the line grows longer + // than its horizontal bounds. + var result = ''; + var lines = text.split('\n'); + for (var i = 0; i < lines.length; i++) + { + var spaceLeft = this.style.wordWrapWidth; + var words = lines[i].split(' '); + for (var j = 0; j < words.length; j++) + { + var wordWidth = this.context.measureText(words[j]).width; + var wordWidthWithSpace = wordWidth + this.context.measureText(' ').width; + if(wordWidthWithSpace > spaceLeft) + { + // Skip printing the newline if it's the first word of the line that is + // greater than the word wrap width. + if(j > 0) + { + result += '\n'; + } + result += words[j] + ' '; + spaceLeft = this.style.wordWrapWidth - wordWidth; + } + else + { + spaceLeft -= wordWidthWithSpace; + result += words[j] + ' '; + } + } + result += '\n'; + } + return result; }; /** @@ -7529,10 +7499,10 @@ PIXI.Text.prototype.wordWrap = function(text) */ PIXI.Text.prototype.destroy = function(destroyTexture) { - if(destroyTexture) - { - this.texture.destroy(); - } + if(destroyTexture) + { + this.texture.destroy(); + } }; @@ -7554,85 +7524,94 @@ PIXI.texturesToDestroy = []; * @constructor * @param source {String} the source object (image or canvas) */ -PIXI.BaseTexture = function(source) +PIXI.BaseTexture = function(source, scaleMode) { - PIXI.EventTarget.call( this ); + PIXI.EventTarget.call( this ); - /** - * [read-only] The width of the base texture set when the image has loaded - * - * @property width - * @type Number - * @readOnly - */ - this.width = 100; + /** + * [read-only] The width of the base texture set when the image has loaded + * + * @property width + * @type Number + * @readOnly + */ + this.width = 100; - /** - * [read-only] The height of the base texture set when the image has loaded - * - * @property height - * @type Number - * @readOnly - */ - this.height = 100; + /** + * [read-only] The height of the base texture set when the image has loaded + * + * @property height + * @type Number + * @readOnly + */ + this.height = 100; - /** - * [read-only] Describes if the base texture has loaded or not - * - * @property hasLoaded - * @type Boolean - * @readOnly - */ - this.hasLoaded = false; + /** + * The scale mode to apply when scaling this texture + * @property scaleMode + * @type PIXI.BaseTexture.SCALE_MODE + * @default PIXI.BaseTexture.SCALE_MODE.LINEAR + */ + this.scaleMode = scaleMode || PIXI.BaseTexture.SCALE_MODE.DEFAULT; - /** - * The source that is loaded to create the texture - * - * @property source - * @type Image - */ - this.source = source; + /** + * [read-only] Describes if the base texture has loaded or not + * + * @property hasLoaded + * @type Boolean + * @readOnly + */ + this.hasLoaded = false; - if(!source)return; + /** + * The source that is loaded to create the texture + * + * @property source + * @type Image + */ + this.source = source; - if(this.source instanceof Image || this.source instanceof HTMLImageElement) - { - if(this.source.complete) - { - this.hasLoaded = true; - this.width = this.source.width; - this.height = this.source.height; + if(!source)return; - PIXI.texturesToUpdate.push(this); - } - else - { + if(this.source instanceof Image || this.source instanceof HTMLImageElement) + { + if(this.source.complete) + { + this.hasLoaded = true; + this.width = this.source.width; + this.height = this.source.height; - var scope = this; - this.source.onload = function(){ + PIXI.texturesToUpdate.push(this); + } + else + { - scope.hasLoaded = true; - scope.width = scope.source.width; - scope.height = scope.source.height; + var scope = this; + this.source.onload = function() { - // add it to somewhere... - PIXI.texturesToUpdate.push(scope); - scope.dispatchEvent( { type: 'loaded', content: scope } ); - } - // this.image.src = imageUrl; - } - } - else - { - this.hasLoaded = true; - this.width = this.source.width; - this.height = this.source.height; + scope.hasLoaded = true; + scope.width = scope.source.width; + scope.height = scope.source.height; - PIXI.texturesToUpdate.push(this); - } + // add it to somewhere... + PIXI.texturesToUpdate.push(scope); + scope.dispatchEvent( { type: 'loaded', content: scope } ); + }; + //this.image.src = imageUrl; + } + } + else + { + this.hasLoaded = true; + this.width = this.source.width; + this.height = this.source.height; - this._powerOf2 = false; -} + PIXI.texturesToUpdate.push(this); + } + + this.imageUrl = null; + this._powerOf2 = false; +}; PIXI.BaseTexture.prototype.constructor = PIXI.BaseTexture; @@ -7643,13 +7622,29 @@ PIXI.BaseTexture.prototype.constructor = PIXI.BaseTexture; */ PIXI.BaseTexture.prototype.destroy = function() { - if(this.source instanceof Image) - { - this.source.src = null; - } - this.source = null; - PIXI.texturesToDestroy.push(this); -} + if(this.source instanceof Image) + { + if (this.imageUrl in PIXI.BaseTextureCache) + delete PIXI.BaseTextureCache[this.imageUrl]; + this.imageUrl = null; + this.source.src = null; + } + this.source = null; + PIXI.texturesToDestroy.push(this); +}; + +/** + * + * + * @method destroy + */ + +PIXI.BaseTexture.prototype.updateSourceImage = function(newSrc) +{ + this.hasLoaded = false; + this.source.src = null; + this.source.src = newSrc; +}; /** * Helper function that returns a base texture based on an image url @@ -7660,26 +7655,32 @@ PIXI.BaseTexture.prototype.destroy = function() * @param imageUrl {String} The image url of the texture * @return BaseTexture */ -PIXI.BaseTexture.fromImage = function(imageUrl, crossorigin) +PIXI.BaseTexture.fromImage = function(imageUrl, crossorigin, scaleMode) { - var baseTexture = PIXI.BaseTextureCache[imageUrl]; - if(!baseTexture) - { - // new Image() breaks tex loading in some versions of Chrome. - // See https://code.google.com/p/chromium/issues/detail?id=238071 - var image = new Image();//document.createElement('img'); - if (crossorigin) - { - image.crossOrigin = ''; - } - image.src = imageUrl; - baseTexture = new PIXI.BaseTexture(image); - PIXI.BaseTextureCache[imageUrl] = baseTexture; - } + var baseTexture = PIXI.BaseTextureCache[imageUrl]; + if(!baseTexture) + { + // new Image() breaks tex loading in some versions of Chrome. + // See https://code.google.com/p/chromium/issues/detail?id=238071 + var image = new Image();//document.createElement('img'); + if (crossorigin) + { + image.crossOrigin = ''; + } + image.src = imageUrl; + baseTexture = new PIXI.BaseTexture(image, scaleMode); + baseTexture.imageUrl = imageUrl; + PIXI.BaseTextureCache[imageUrl] = baseTexture; + } - return baseTexture; -} + return baseTexture; +}; +PIXI.BaseTexture.SCALE_MODE = { + DEFAULT: 0, //default to LINEAR + LINEAR: 0, + NEAREST: 1 +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -7699,56 +7700,56 @@ PIXI.FrameCache = {}; */ PIXI.Texture = function(baseTexture, frame) { - PIXI.EventTarget.call( this ); + PIXI.EventTarget.call( this ); - if(!frame) - { - this.noFrame = true; - frame = new PIXI.Rectangle(0,0,1,1); - } + if(!frame) + { + this.noFrame = true; + frame = new PIXI.Rectangle(0,0,1,1); + } - if(baseTexture instanceof PIXI.Texture) - baseTexture = baseTexture.baseTexture; + if(baseTexture instanceof PIXI.Texture) + baseTexture = baseTexture.baseTexture; - /** - * The base texture of this texture - * - * @property baseTexture - * @type BaseTexture - */ - this.baseTexture = baseTexture; + /** + * The base texture of this texture + * + * @property baseTexture + * @type BaseTexture + */ + this.baseTexture = baseTexture; - /** - * The frame specifies the region of the base texture that this texture uses - * - * @property frame - * @type Rectangle - */ - this.frame = frame; + /** + * The frame specifies the region of the base texture that this texture uses + * + * @property frame + * @type Rectangle + */ + this.frame = frame; - /** - * The trim point - * - * @property trim - * @type Point - */ - this.trim = new PIXI.Point(); + /** + * The trim point + * + * @property trim + * @type Point + */ + this.trim = new PIXI.Point(); - this.scope = this; + this.scope = this; - if(baseTexture.hasLoaded) - { - if(this.noFrame)frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height); - //console.log(frame) + if(baseTexture.hasLoaded) + { + if(this.noFrame)frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height); + //console.log(frame) - this.setFrame(frame); - } - else - { - var scope = this; - baseTexture.addEventListener( 'loaded', function(){ scope.onBaseTextureLoaded()} ); - } -} + this.setFrame(frame); + } + else + { + var scope = this; + baseTexture.addEventListener('loaded', function(){ scope.onBaseTextureLoaded(); }); + } +}; PIXI.Texture.prototype.constructor = PIXI.Texture; @@ -7759,18 +7760,18 @@ PIXI.Texture.prototype.constructor = PIXI.Texture; * @param event * @private */ -PIXI.Texture.prototype.onBaseTextureLoaded = function(event) +PIXI.Texture.prototype.onBaseTextureLoaded = function() { - var baseTexture = this.baseTexture; - baseTexture.removeEventListener( 'loaded', this.onLoaded ); + var baseTexture = this.baseTexture; + baseTexture.removeEventListener( 'loaded', this.onLoaded ); - if(this.noFrame)this.frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height); - this.noFrame = false; - this.width = this.frame.width; - this.height = this.frame.height; + if(this.noFrame)this.frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height); + this.noFrame = false; + this.width = this.frame.width; + this.height = this.frame.height; - this.scope.dispatchEvent( { type: 'update', content: this } ); -} + this.scope.dispatchEvent( { type: 'update', content: this } ); +}; /** * Destroys this texture @@ -7780,8 +7781,8 @@ PIXI.Texture.prototype.onBaseTextureLoaded = function(event) */ PIXI.Texture.prototype.destroy = function(destroyBase) { - if(destroyBase)this.baseTexture.destroy(); -} + if(destroyBase) this.baseTexture.destroy(); +}; /** * Specifies the rectangle region of the baseTexture @@ -7791,20 +7792,20 @@ PIXI.Texture.prototype.destroy = function(destroyBase) */ PIXI.Texture.prototype.setFrame = function(frame) { - this.frame = frame; - this.width = frame.width; - this.height = frame.height; + this.frame = frame; + this.width = frame.width; + this.height = frame.height; - if(frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error("Texture Error: frame does not fit inside the base Texture dimensions " + this); - } + if(frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) + { + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); + } - this.updateFrame = true; + this.updateFrame = true; - PIXI.Texture.frameUpdates.push(this); - //this.dispatchEvent( { type: 'update', content: this } ); -} + PIXI.Texture.frameUpdates.push(this); + //this.dispatchEvent( { type: 'update', content: this } ); +}; /** * Helper function that returns a texture based on an image url @@ -7816,18 +7817,18 @@ PIXI.Texture.prototype.setFrame = function(frame) * @param crossorigin {Boolean} Whether requests should be treated as crossorigin * @return Texture */ -PIXI.Texture.fromImage = function(imageUrl, crossorigin) +PIXI.Texture.fromImage = function(imageUrl, crossorigin, scaleMode) { - var texture = PIXI.TextureCache[imageUrl]; + var texture = PIXI.TextureCache[imageUrl]; - if(!texture) - { - texture = new PIXI.Texture(PIXI.BaseTexture.fromImage(imageUrl, crossorigin)); - PIXI.TextureCache[imageUrl] = texture; - } + if(!texture) + { + texture = new PIXI.Texture(PIXI.BaseTexture.fromImage(imageUrl, crossorigin, scaleMode)); + PIXI.TextureCache[imageUrl] = texture; + } - return texture; -} + return texture; +}; /** * Helper function that returns a texture based on a frame id @@ -7840,10 +7841,10 @@ PIXI.Texture.fromImage = function(imageUrl, crossorigin) */ PIXI.Texture.fromFrame = function(frameId) { - var texture = PIXI.TextureCache[frameId]; - if(!texture)throw new Error("The frameId '"+ frameId +"' does not exist in the texture cache " + this); - return texture; -} + var texture = PIXI.TextureCache[frameId]; + if(!texture) throw new Error('The frameId "' + frameId + '" does not exist in the texture cache ' + this); + return texture; +}; /** * Helper function that returns a texture based on a canvas element @@ -7854,11 +7855,11 @@ PIXI.Texture.fromFrame = function(frameId) * @param canvas {Canvas} The canvas element source of the texture * @return Texture */ -PIXI.Texture.fromCanvas = function(canvas) +PIXI.Texture.fromCanvas = function(canvas, scaleMode) { - var baseTexture = new PIXI.BaseTexture(canvas); - return new PIXI.Texture(baseTexture); -} + var baseTexture = new PIXI.BaseTexture(canvas, scaleMode); + return new PIXI.Texture(baseTexture); +}; /** @@ -7871,8 +7872,8 @@ PIXI.Texture.fromCanvas = function(canvas) */ PIXI.Texture.addTextureToCache = function(texture, id) { - PIXI.TextureCache[id] = texture; -} + PIXI.TextureCache[id] = texture; +}; /** * Remove a texture from the textureCache. @@ -7884,14 +7885,15 @@ PIXI.Texture.addTextureToCache = function(texture, id) */ PIXI.Texture.removeTextureFromCache = function(id) { - var texture = PIXI.TextureCache[id] - PIXI.TextureCache[id] = null; - return texture; -} + var texture = PIXI.TextureCache[id]; + PIXI.TextureCache[id] = null; + return texture; +}; // this is more for webGL.. it contains updated frames.. PIXI.Texture.frameUpdates = []; +PIXI.Texture.SCALE_MODE = PIXI.BaseTexture.SCALE_MODE; /** * @author Mat Groves http://matgroves.com/ @Doormat23 @@ -7900,24 +7902,24 @@ PIXI.Texture.frameUpdates = []; /** A RenderTexture is a special texture that allows any pixi displayObject to be rendered to it. - __Hint__: All DisplayObjects (exmpl. Sprites) that renders on RenderTexture should be preloaded. - Otherwise black rectangles will be drawn instead. - + __Hint__: All DisplayObjects (exmpl. Sprites) that renders on RenderTexture should be preloaded. + Otherwise black rectangles will be drawn instead. + RenderTexture takes snapshot of DisplayObject passed to render method. If DisplayObject is passed to render method, position and rotation of it will be ignored. For example: - - var renderTexture = new PIXI.RenderTexture(800, 600); - var sprite = PIXI.Sprite.fromImage("spinObj_01.png"); - sprite.position.x = 800/2; - sprite.position.y = 600/2; - sprite.anchor.x = 0.5; - sprite.anchor.y = 0.5; - renderTexture.render(sprite); + + var renderTexture = new PIXI.RenderTexture(800, 600); + var sprite = PIXI.Sprite.fromImage("spinObj_01.png"); + sprite.position.x = 800/2; + sprite.position.y = 600/2; + sprite.anchor.x = 0.5; + sprite.anchor.y = 0.5; + renderTexture.render(sprite); Sprite in this case will be rendered to 0,0 position. To render this sprite at center DisplayObjectContainer should be used: - var doc = new PIXI.DisplayObjectContainer(); - doc.addChild(sprite); - renderTexture.render(doc); // Renders to center of renderTexture + var doc = new PIXI.DisplayObjectContainer(); + doc.addChild(sprite); + renderTexture.render(doc); // Renders to center of renderTexture @class RenderTexture @extends Texture @@ -7927,24 +7929,24 @@ PIXI.Texture.frameUpdates = []; */ PIXI.RenderTexture = function(width, height) { - PIXI.EventTarget.call( this ); + PIXI.EventTarget.call( this ); - this.width = width || 100; - this.height = height || 100; + this.width = width || 100; + this.height = height || 100; - this.indetityMatrix = PIXI.mat3.create(); + this.indetityMatrix = PIXI.mat3.create(); - this.frame = new PIXI.Rectangle(0, 0, this.width, this.height); + this.frame = new PIXI.Rectangle(0, 0, this.width, this.height); - if(PIXI.gl) - { - this.initWebGL(); - } - else - { - this.initCanvas(); - } -} + if(PIXI.gl) + { + this.initWebGL(); + } + else + { + this.initCanvas(); + } +}; PIXI.RenderTexture.prototype = Object.create( PIXI.Texture.prototype ); PIXI.RenderTexture.prototype.constructor = PIXI.RenderTexture; @@ -7957,65 +7959,65 @@ PIXI.RenderTexture.prototype.constructor = PIXI.RenderTexture; */ PIXI.RenderTexture.prototype.initWebGL = function() { - var gl = PIXI.gl; - this.glFramebuffer = gl.createFramebuffer(); + var gl = PIXI.gl; + this.glFramebuffer = gl.createFramebuffer(); - gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); + gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); this.glFramebuffer.width = this.width; - this.glFramebuffer.height = this.height; + this.glFramebuffer.height = this.height; - this.baseTexture = new PIXI.BaseTexture(); + this.baseTexture = new PIXI.BaseTexture(); - this.baseTexture.width = this.width; - this.baseTexture.height = this.height; + this.baseTexture.width = this.width; + this.baseTexture.height = this.height; this.baseTexture._glTexture = gl.createTexture(); gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - this.baseTexture.isRender = true; + this.baseTexture.isRender = true; - gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); - gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.baseTexture._glTexture, 0); + gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.baseTexture._glTexture, 0); - // create a projection matrix.. - this.projection = new PIXI.Point(this.width/2 , -this.height/2); + // create a projection matrix.. + this.projection = new PIXI.Point(this.width/2 , -this.height/2); - // set the correct render function.. - this.render = this.renderWebGL; -} + // set the correct render function.. + this.render = this.renderWebGL; +}; PIXI.RenderTexture.prototype.resize = function(width, height) { - this.width = width; - this.height = height; - - if(PIXI.gl) - { - this.projection.x = this.width/2 - this.projection.y = -this.height/2; - - var gl = PIXI.gl; - gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); - } - else - { - - this.frame.width = this.width - this.frame.height = this.height; - this.renderer.resize(this.width, this.height); - } -} + this.width = width; + this.height = height; + + if(PIXI.gl) + { + this.projection.x = this.width / 2; + this.projection.y = -this.height / 2; + + var gl = PIXI.gl; + gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); + } + else + { + + this.frame.width = this.width; + this.frame.height = this.height; + this.renderer.resize(this.width, this.height); + } +}; /** * Initializes the canvas data for this texture @@ -8025,13 +8027,13 @@ PIXI.RenderTexture.prototype.resize = function(width, height) */ PIXI.RenderTexture.prototype.initCanvas = function() { - this.renderer = new PIXI.CanvasRenderer(this.width, this.height, null, 0); + this.renderer = new PIXI.CanvasRenderer(this.width, this.height, null, 0); - this.baseTexture = new PIXI.BaseTexture(this.renderer.view); - this.frame = new PIXI.Rectangle(0, 0, this.width, this.height); + this.baseTexture = new PIXI.BaseTexture(this.renderer.view); + this.frame = new PIXI.Rectangle(0, 0, this.width, this.height); - this.render = this.renderCanvas; -} + this.render = this.renderCanvas; +}; /** * This function will draw the display object to the texture. @@ -8043,67 +8045,67 @@ PIXI.RenderTexture.prototype.initCanvas = function() */ PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, position, clear) { - var gl = PIXI.gl; + var gl = PIXI.gl; - // enable the alpha color mask.. - gl.colorMask(true, true, true, true); + // enable the alpha color mask.. + gl.colorMask(true, true, true, true); - gl.viewport(0, 0, this.width, this.height); + gl.viewport(0, 0, this.width, this.height); - gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); + gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); - if(clear) - { - gl.clearColor(0,0,0, 0); - gl.clear(gl.COLOR_BUFFER_BIT); - } + if(clear) + { + gl.clearColor(0,0,0, 0); + gl.clear(gl.COLOR_BUFFER_BIT); + } - // THIS WILL MESS WITH HIT TESTING! - var children = displayObject.children; + // THIS WILL MESS WITH HIT TESTING! + var children = displayObject.children; - //TODO -? create a new one??? dont think so! - var originalWorldTransform = displayObject.worldTransform; - displayObject.worldTransform = PIXI.mat3.create();//sthis.indetityMatrix; - // modify to flip... - displayObject.worldTransform[4] = -1; - displayObject.worldTransform[5] = this.projection.y * -2; + //TODO -? create a new one??? dont think so! + var originalWorldTransform = displayObject.worldTransform; + displayObject.worldTransform = PIXI.mat3.create();//sthis.indetityMatrix; + // modify to flip... + displayObject.worldTransform[4] = -1; + displayObject.worldTransform[5] = this.projection.y * -2; - if(position) - { - displayObject.worldTransform[2] = position.x; - displayObject.worldTransform[5] -= position.y; - } - - PIXI.visibleCount++; - displayObject.vcount = PIXI.visibleCount; - - for(var i=0,j=children.length; i>1; - if(n<3) return []; - var tgs = []; - var avl = []; - for(var i=0; i> 1; + if(n < 3) return []; - var i = 0; - var al = n; - while(al > 3) - { - var i0 = avl[(i+0)%al]; - var i1 = avl[(i+1)%al]; - var i2 = avl[(i+2)%al]; + var tgs = []; + var avl = []; + for(var i = 0; i < n; i++) avl.push(i); - var ax = p[2*i0], ay = p[2*i0+1]; - var bx = p[2*i1], by = p[2*i1+1]; - var cx = p[2*i2], cy = p[2*i2+1]; + i = 0; + var al = n; + while(al > 3) + { + var i0 = avl[(i+0)%al]; + var i1 = avl[(i+1)%al]; + var i2 = avl[(i+2)%al]; - var earFound = false; - if(PIXI.PolyK._convex(ax, ay, bx, by, cx, cy, sign)) - { - earFound = true; - for(var j=0; j 3*al) - { - // need to flip flip reverse it! - // reset! - if(sign) - { - var tgs = []; - avl = []; - for(var i=0; i 3*al) + { + // need to flip flip reverse it! + // reset! + if(sign) + { + tgs = []; + avl = []; + for(i = 0; i < n; i++) avl.push(i); + + i = 0; + al = n; + + sign = false; + } + else + { + window.console.log("PIXI Warning: shape too complex to fill"); + return []; + } + } + } + + tgs.push(avl[0], avl[1], avl[2]); + return tgs; +}; /** * Checks if a point is within a triangle @@ -8326,26 +8339,26 @@ PIXI.PolyK.Triangulate = function(p) */ PIXI.PolyK._PointInTriangle = function(px, py, ax, ay, bx, by, cx, cy) { - var v0x = cx-ax; - var v0y = cy-ay; - var v1x = bx-ax; - var v1y = by-ay; - var v2x = px-ax; - var v2y = py-ay; + var v0x = cx-ax; + var v0y = cy-ay; + var v1x = bx-ax; + var v1y = by-ay; + var v2x = px-ax; + var v2y = py-ay; - var dot00 = v0x*v0x+v0y*v0y; - var dot01 = v0x*v1x+v0y*v1y; - var dot02 = v0x*v2x+v0y*v2y; - var dot11 = v1x*v1x+v1y*v1y; - var dot12 = v1x*v2x+v1y*v2y; + var dot00 = v0x*v0x+v0y*v0y; + var dot01 = v0x*v1x+v0y*v1y; + var dot02 = v0x*v2x+v0y*v2y; + var dot11 = v1x*v1x+v1y*v1y; + var dot12 = v1x*v2x+v1y*v2y; - var invDenom = 1 / (dot00 * dot11 - dot01 * dot01); - var u = (dot11 * dot02 - dot01 * dot12) * invDenom; - var v = (dot00 * dot12 - dot01 * dot02) * invDenom; + var invDenom = 1 / (dot00 * dot11 - dot01 * dot01); + var u = (dot11 * dot02 - dot01 * dot12) * invDenom; + var v = (dot00 * dot12 - dot01 * dot02) * invDenom; - // Check if point is in triangle - return (u >= 0) && (v >= 0) && (u + v < 1); -} + // Check if point is in triangle + return (u >= 0) && (v >= 0) && (u + v < 1); +}; /** * Checks if a shape is convex @@ -8356,8 +8369,8 @@ PIXI.PolyK._PointInTriangle = function(px, py, ax, ay, bx, by, cx, cy) */ PIXI.PolyK._convex = function(ax, ay, bx, by, cx, cy, sign) { - return ((ay-by)*(cx-bx) + (bx-ax)*(cy-by) >= 0) == sign; -} + return ((ay-by)*(cx-bx) + (bx-ax)*(cy-by) >= 0) === sign; +}; /** * @author Richard Davey @@ -8568,28 +8581,28 @@ Phaser.Camera.prototype = { if (this.deadzone) { - this._edge = this.target.x - this.deadzone.x; + this._edge = this.target.bounds.x - this.deadzone.x; if (this.view.x > this._edge) { this.view.x = this._edge; } - this._edge = this.target.x + this.target.width - this.deadzone.x - this.deadzone.width; + this._edge = this.target.bounds.right - this.deadzone.x - this.deadzone.width; if (this.view.x < this._edge) { this.view.x = this._edge; } - this._edge = this.target.y - this.deadzone.y; + this._edge = this.target.bounds.y - this.deadzone.y; if (this.view.y > this._edge) { this.view.y = this._edge; } - this._edge = this.target.y + this.target.height - this.deadzone.y - this.deadzone.height; + this._edge = this.target.bounds.bottom - this.deadzone.y - this.deadzone.height; if (this.view.y < this._edge) { @@ -8605,7 +8618,7 @@ Phaser.Camera.prototype = { setBoundsToWorld: function () { - this.bounds.setTo(this.game.world.x, this.game.world.y, this.game.world.width, this.game.world.height); + this.bounds.setTo(this.game.world.bounds.x, this.game.world.bounds.y, this.game.world.bounds.width, this.game.world.bounds.height); }, @@ -8683,6 +8696,8 @@ Phaser.Camera.prototype = { }; +Phaser.Camera.prototype.constructor = Phaser.Camera; + /** * The Cameras x coordinate. This value is automatically clamped if it falls outside of the World bounds. * @name Phaser.Camera#x @@ -8933,6 +8948,8 @@ Phaser.State.prototype = { }; +Phaser.State.prototype.constructor = Phaser.State; + /* jshint newcap: false */ /** @@ -8967,7 +8984,7 @@ Phaser.StateManager = function (game, pendingState) { */ this._pendingState = null; - if (pendingState !== null) + if (typeof pendingState !== 'undefined' && pendingState !== null) { this._pendingState = pendingState; } @@ -9215,7 +9232,8 @@ Phaser.StateManager.prototype = { }, /** - * Description. + * Checks i a given phaser state is valid. + * State must exist and have at least one callback function registered.. * @method Phaser.StateManager#checkState * @param {string} key - The key of the state you want to check. * @return {boolean} Description. @@ -9282,7 +9300,7 @@ Phaser.StateManager.prototype = { * Sets the current State. Should not be called directly (use StateManager.start) * @method Phaser.StateManager#setCurrentState * @param {string} key - State key. - * @protected + * @private */ setCurrentState: function (key) { @@ -9312,6 +9330,17 @@ Phaser.StateManager.prototype = { }, + /** + * Gets the current State. + * + * @method Phaser.StateManager#getCurrentState + * @return Phaser.State + * @public + */ + getCurrentState: function() { + return this.states[this.current]; + }, + /** * @method Phaser.StateManager#loadComplete * @protected @@ -9448,6 +9477,8 @@ Phaser.StateManager.prototype = { }; +Phaser.StateManager.prototype.constructor = Phaser.StateManager; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -9602,6 +9633,9 @@ Phaser.LinkedList.prototype = { } }; + +Phaser.LinkedList.prototype.constructor = Phaser.LinkedList; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -9905,6 +9939,8 @@ Phaser.Signal.prototype = { }; +Phaser.Signal.prototype.constructor = Phaser.Signal; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -10068,6 +10104,8 @@ Phaser.SignalBinding.prototype = { }; +Phaser.SignalBinding.prototype.constructor = Phaser.SignalBinding; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -10194,6 +10232,8 @@ Phaser.Filter.prototype = { }; +Phaser.Filter.prototype.constructor = Phaser.Filter; + /** * @name Phaser.Filter#width * @property {number} width - The width (resolution uniform) @@ -10348,6 +10388,8 @@ Phaser.Plugin.prototype = { }; +Phaser.Plugin.prototype.constructor = Phaser.Plugin; + /* jshint newcap: false */ /** @@ -10646,6 +10688,8 @@ Phaser.PluginManager.prototype = { }; +Phaser.PluginManager.prototype.constructor = Phaser.PluginManager; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -10672,7 +10716,6 @@ Phaser.Stage = function (game, width, height) { /** * @property {string} game - Background color of the stage (defaults to black). Set via the public backgroundColor property. * @private - * @default 'rgb(0,0,0)' */ this._backgroundColor = 'rgb(0,0,0)'; @@ -10682,10 +10725,9 @@ Phaser.Stage = function (game, width, height) { this.offset = new Phaser.Point(); /** - * @property {HTMLCanvasElement} canvas - Reference to the newly created <canvas> element. + * @property {HTMLCanvasElement} canvas - Reference to the newly created `canvas` element. */ - this.canvas = Phaser.Canvas.create(width, height); - this.canvas.style['-webkit-full-screen'] = 'width: 100%; height: 100%'; + this.canvas = null; /** * @property {PIXI.Stage} _stage - The Pixi Stage which is hooked to the renderer. @@ -10695,11 +10737,21 @@ Phaser.Stage = function (game, width, height) { this._stage.name = '_stage_root'; this._stage.interactive = false; + /** + * @property {PIXI.Stage} display - The Pixi Stage which is hooked to the renderer. + */ + this.display = this._stage; + /** * @property {number} scaleMode - The current scaleMode. */ this.scaleMode = Phaser.StageScaleMode.NO_SCALE; + /* + * @property {number} fullScreenScaleMode - Scale mode to be used in fullScreen + */ + this.fullScreenScaleMode = Phaser.StageScaleMode.NO_SCALE; + /** * @property {Phaser.StageScaleMode} scale - The scale of the current running game. */ @@ -10710,6 +10762,12 @@ Phaser.Stage = function (game, width, height) { */ this.aspectRatio = width / height; + /** + * @property {boolean} disableVisibilityChange - By default if the browser tab loses focus the game will pause. You can stop that behaviour by setting this property to true. + * @default + */ + this.disableVisibilityChange = false; + /** * @property {number} _nextOffsetCheck - The time to run the next offset check. * @private @@ -10722,10 +10780,73 @@ Phaser.Stage = function (game, width, height) { */ this.checkOffsetInterval = 2500; + if (game.config) + { + this.parseConfig(game.config); + } + else + { + this.canvas = Phaser.Canvas.create(width, height); + this.canvas.style['-webkit-full-screen'] = 'width: 100%; height: 100%'; + } + }; Phaser.Stage.prototype = { + /** + * Parses a Game configuration object. + * + * @method Phaser.Stage#parseConfig + * @protected + */ + parseConfig: function (config) { + + if (config['canvasID']) + { + this.canvas = Phaser.Canvas.create(this.game.width, this.game.height, config['canvasID']); + } + else + { + this.canvas = Phaser.Canvas.create(this.game.width, this.game.height); + } + + if (config['canvasStyle']) + { + this.canvas.stlye = config['canvasStyle']; + } + else + { + this.canvas.style['-webkit-full-screen'] = 'width: 100%; height: 100%'; + } + + if (config['checkOffsetInterval']) + { + this.checkOffsetInterval = config['checkOffsetInterval']; + } + + if (config['disableVisibilityChange']) + { + this.disableVisibilityChange = config['disableVisibilityChange']; + } + + if (config['fullScreenScaleMode']) + { + this.fullScreenScaleMode = config['fullScreenScaleMode']; + } + + if (config['scaleMode']) + { + this.scaleMode = config['scaleMode']; + } + + if (config['backgroundColor']) + { + this.backgroundColor = config['backgroundColor']; + } + + }, + /** * Initialises the stage and adds the event listeners. * @method Phaser.Stage#boot @@ -10801,6 +10922,8 @@ Phaser.Stage.prototype = { }; +Phaser.Stage.prototype.constructor = Phaser.Stage; + /** * @name Phaser.Stage#backgroundColor * @property {number|string} backgroundColor - Gets and sets the background color of the stage. The color can be given as a number: 0xff0000 or a hex string: '#ff0000' @@ -10850,32 +10973,32 @@ Object.defineProperty(Phaser.Stage.prototype, "backgroundColor", { * @classdesc A Group is a container for display objects that allows for fast pooling, recycling and collision checks. * @constructor * @param {Phaser.Game} game - A reference to the currently running game. -* @param {*} parent - The parent Group or DisplayObjectContainer that will hold this group, if any. +* @param {*} parent - The parent Group or DisplayObjectContainer that will hold this group, if any. If undefined it will use game.world. * @param {string} [name=group] - A name for this Group. Not used internally but useful for debugging. * @param {boolean} [useStage=false] - Should the DisplayObjectContainer this Group creates be added to the World (default, false) or direct to the Stage (true). */ Phaser.Group = function (game, parent, name, useStage) { - if (typeof parent === 'undefined' || typeof parent === null) + /** + * @property {Phaser.Game} game - A reference to the currently running Game. + */ + this.game = game; + + if (typeof parent === 'undefined') { parent = game.world; } + /** + * @property {string} name - A name for this Group. Not used internally but useful for debugging. + */ + this.name = name || 'group'; + if (typeof useStage === 'undefined') { useStage = false; } - /** - * @property {Phaser.Game} game - A reference to the currently running Game. - */ - this.game = game; - - /** - * @property {string} name - A name for this Group. Not used internally but useful for debugging. - */ - this.name = name || 'group'; - if (useStage) { this._container = this.game.stage._stage; @@ -10911,6 +11034,12 @@ Phaser.Group = function (game, parent, name, useStage) { */ this.type = Phaser.GROUP; + /** + * @property {boolean} alive - The alive property is useful for Groups that are children of other Groups and need to be included/excluded in checks like forEachAlive. + * @default + */ + this.alive = true; + /** * @property {boolean} exists - If exists is true the the Group is updated, otherwise it is skipped. * @default @@ -10918,9 +11047,17 @@ Phaser.Group = function (game, parent, name, useStage) { this.exists = true; /** - * @property {Phaser.Point} scale - Replaces the PIXI.Point with a slightly more flexible one. + * @property {Phaser.Group} group - The parent Group of this Group, if a child of another. */ - this.scale = new Phaser.Point(1, 1); + this.group = null; + + // Replaces the PIXI.Point with a slightly more flexible one. + this._container.scale = new Phaser.Point(1, 1); + + /** + * @property {Phaser.Point} scale - The scane of the Group container. + */ + this.scale = this._container.scale; /** * The cursor is a simple way to iterate through the objects in a Group using the Group.next and Group.previous functions. @@ -10978,16 +11115,27 @@ Phaser.Group.prototype = { if (child.group !== this) { - child.group = this; - - if (child.events) + if (child.type && child.type === Phaser.GROUP) { - child.events.onAddedToGroup.dispatch(child, this); + child.group = this; + + this._container.addChild(child._container); + + child._container.updateTransform(); } + else + { + child.group = this; - this._container.addChild(child); + if (child.events) + { + child.events.onAddedToGroup.dispatch(child, this); + } - child.updateTransform(); + this._container.addChild(child); + + child.updateTransform(); + } if (this.cursor === null) { @@ -11012,16 +11160,27 @@ Phaser.Group.prototype = { if (child.group !== this) { - child.group = this; - - if (child.events) + if (child.type && child.type === Phaser.GROUP) { - child.events.onAddedToGroup.dispatch(child, this); + child.group = this; + + this._container.addChildAt(child._container, index); + + child._container.updateTransform(); } + else + { + child.group = this; - this._container.addChildAt(child, index); + if (child.events) + { + child.events.onAddedToGroup.dispatch(child, this); + } - child.updateTransform(); + this._container.addChildAt(child, index); + + child.updateTransform(); + } if (this.cursor === null) { @@ -11060,7 +11219,7 @@ Phaser.Group.prototype = { */ create: function (x, y, key, frame, exists) { - if (typeof exists == 'undefined') { exists = true; } + if (typeof exists === 'undefined') { exists = true; } var child = new Phaser.Sprite(this.game, x, y, key, frame); @@ -11100,7 +11259,7 @@ Phaser.Group.prototype = { */ createMultiple: function (quantity, key, frame, exists) { - if (typeof exists == 'undefined') { exists = false; } + if (typeof exists === 'undefined') { exists = false; } for (var i = 0; i < quantity; i++) { @@ -11172,6 +11331,11 @@ Phaser.Group.prototype = { }, + /** + * Internal test. + * + * @method Phaser.Group#childTest + */ childTest: function (prefix, child) { var s = prefix + ' next: '; @@ -11200,6 +11364,11 @@ Phaser.Group.prototype = { }, + /** + * Internal test. + * + * @method Phaser.Group#swapIndex + */ swapIndex: function (index1, index2) { var child1 = this.getAt(index1); @@ -11471,6 +11640,32 @@ Phaser.Group.prototype = { }, + /** + * This function allows you to quickly set a property on a single child of this Group to a new value. + * The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication. + * + * @method Phaser.Group#set + * @param {Phaser.Sprite} child - The child to set the property on. + * @param {string} key - The property, as a string, to be set. For example: 'body.velocity.x' + * @param {*} value - The value that will be set. + * @param {boolean} [checkAlive=false] - If set then the child will only be updated if alive=true. + * @param {boolean} [checkVisible=false] - If set then the child will only be updated if visible=true. + * @param {number} [operation=0] - Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it. + */ + set: function (child, key, value, checkAlive, checkVisible, operation) { + + key = key.split('.'); + + if (typeof checkAlive === 'undefined') { checkAlive = false; } + if (typeof checkVisible === 'undefined') { checkVisible = false; } + + if ((checkAlive === false || (checkAlive && child.alive)) && (checkVisible === false || (checkVisible && child.visible))) + { + this.setProperty(child, key, value, operation); + } + + }, + /** * This function allows you to quickly set the same property across all children of this Group to a new value. * The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication. @@ -11606,7 +11801,7 @@ Phaser.Group.prototype = { }, /** - * Calls a function on all of the children that have exists=true in this Group. + * Returns a reference to a function that exists on a child of the Group based on the given callback array. * * @method Phaser.Group#callbackFromArray * @param {object} child - The object to inspect. @@ -11664,7 +11859,7 @@ Phaser.Group.prototype = { * * @method Phaser.Group#callAll * @param {string} method - A string containing the name of the function that will be called. The function must exist on the child. - * @param {string} [context=''] - A string containing the context under which the method will be executed. Leave to '' to default to the child. + * @param {string} [context=null] - A string containing the context under which the method will be executed. Set to null to default to the child. * @param {...*} parameter - Additional parameters that will be passed to the method. */ callAll: function (method, context) { @@ -11881,12 +12076,13 @@ Phaser.Group.prototype = { * @param {number} returnType - How to return the data from this method. Either Phaser.Group.RETURN_NONE, Phaser.Group.RETURN_TOTAL or Phaser.Group.RETURN_CHILD. * @param {function} [callback=null] - Optional function that will be called on each matching child. Each child of the Group will be passed to it as its first parameter. * @param {Object} [callbackContext] - The context in which the function should be called (usually 'this'). + * @return {any} Returns either a numeric total (if RETURN_TOTAL was specified) or the child object. */ iterate: function (key, value, returnType, callback, callbackContext, args) { - if (returnType == Phaser.Group.RETURN_TOTAL && this._container.children.length === 0) + if (returnType === Phaser.Group.RETURN_TOTAL && this._container.children.length === 0) { - return -1; + return 0; } if (typeof callback === 'undefined') @@ -11912,7 +12108,7 @@ Phaser.Group.prototype = { callback.apply(callbackContext, args); } - if (returnType == Phaser.Group.RETURN_CHILD) + if (returnType === Phaser.Group.RETURN_CHILD) { return currentNode; } @@ -11923,11 +12119,11 @@ Phaser.Group.prototype = { while (currentNode != this._container.last._iNext); } - if (returnType == Phaser.Group.RETURN_TOTAL) + if (returnType === Phaser.Group.RETURN_TOTAL) { return total; } - else if (returnType == Phaser.Group.RETURN_CHILD) + else if (returnType === Phaser.Group.RETURN_CHILD) { return null; } @@ -11982,7 +12178,7 @@ Phaser.Group.prototype = { * Call this function to find out how many members of the group are alive. * * @method Phaser.Group#countLiving - * @return {number} The number of children flagged as alive. Returns -1 if Group is empty. + * @return {number} The number of children flagged as alive. */ countLiving: function () { @@ -11994,7 +12190,7 @@ Phaser.Group.prototype = { * Call this function to find out how many members of the group are dead. * * @method Phaser.Group#countDead - * @return {number} The number of children flagged as dead. Returns -1 if Group is empty. + * @return {number} The number of children flagged as dead. */ countDead: function () { @@ -12138,11 +12334,31 @@ Phaser.Group.prototype = { * Destroys this Group. Removes all children, then removes the container from the display list and nulls references. * * @method Phaser.Group#destroy + * @param {boolean} [destroyChildren=false] - Should every child of this Group have its destroy method called? */ - destroy: function () { + destroy: function (destroyChildren) { - this.removeAll(); + if (typeof destroyChildren === 'undefined') { destroyChildren = false; } + if (destroyChildren) + { + if (this._container.children.length > 0) + { + do + { + if (this._container.children[0].group) + { + this._container.children[0].destroy(); + } + } + while (this._container.children.length > 0); + } + } + else + { + this.removeAll(); + } + this._container.parent.removeChild(this._container); this._container = null; @@ -12295,30 +12511,48 @@ Phaser.Group.prototype = { }; +Phaser.Group.prototype.constructor = Phaser.Group; + /** * @name Phaser.Group#total -* @property {number} total - The total number of children in this Group, regardless of their alive state. +* @property {number} total - The total number of children in this Group who have a state of exists = true. * @readonly */ Object.defineProperty(Phaser.Group.prototype, "total", { get: function () { - return this.iterate('exists', true, Phaser.Group.RETURN_TOTAL); - // return this._container.children.length; + + if (this._container) + { + return this.iterate('exists', true, Phaser.Group.RETURN_TOTAL); + } + else + { + return 0; + } + } }); /** * @name Phaser.Group#length -* @property {number} length - The number of children in this Group. +* @property {number} length - The total number of children in this Group, regardless of their exists/alive status. * @readonly */ Object.defineProperty(Phaser.Group.prototype, "length", { get: function () { - return this.iterate('exists', true, Phaser.Group.RETURN_TOTAL); - // return this._container.children.length; + + if (this._container) + { + return this._container.children.length; + } + else + { + return 0; + } + } }); @@ -12441,6 +12675,7 @@ Object.defineProperty(Phaser.Group.prototype, "alpha", { * the world at world-based coordinates. By default a world is created the same size as your Stage. * * @class Phaser.World +* @extends Phaser.Group * @constructor * @param {Phaser.Game} game - Reference to the current game instance. */ @@ -12448,11 +12683,6 @@ Phaser.World = function (game) { Phaser.Group.call(this, game, null, '__world', false); - /** - * @property {Phaser.Point} scale - Replaces the PIXI.Point with a slightly more flexible one. - */ - this.scale = new Phaser.Point(1, 1); - /** * The World has no fixed size, but it does have a bounds outside of which objects are no longer considered as being "in world" and you should use this to clean-up the display list and purge dead objects. * By default we set the Bounds to be from 0,0 to Game.width,Game.height. I.e. it will match the size given to the game constructor with 0,0 representing the top-left of the display. @@ -12493,6 +12723,33 @@ Phaser.World.prototype.boot = function () { } +/** +* This is called automatically every frame, and is where main logic happens. +* +* @method Phaser.World#update +*/ +Phaser.World.prototype.preUpdate = function () { + + if (this.game.stage._stage.first._iNext) + { + var currentNode = this.game.stage._stage.first._iNext; + + do + { + // If preUpdate exists, and it returns false, skip PIXI child objects + if (currentNode['preUpdate'] && !currentNode.preUpdate()) + { + currentNode = currentNode.last._iNext; + } else { + currentNode = currentNode._iNext; + } + + } + while (currentNode != this.game.stage._stage.last._iNext) + } + +} + /** * This is called automatically every frame, and is where main logic happens. * @@ -12505,28 +12762,14 @@ Phaser.World.prototype.update = function () { if (this.game.stage._stage.first._iNext) { var currentNode = this.game.stage._stage.first._iNext; - var skipChildren; do { - skipChildren = false; - - if (currentNode['preUpdate']) - { - skipChildren = (currentNode.preUpdate() === false); - } - - if (currentNode['update']) - { - skipChildren = (currentNode.update() === false) || skipChildren; - } - - if (skipChildren) + // If update exists, and it returns false, skip PIXI child objects + if (currentNode['update'] && !currentNode.update()) { currentNode = currentNode.last._iNext; - } - else - { + } else { currentNode = currentNode._iNext; } @@ -12542,6 +12785,8 @@ Phaser.World.prototype.update = function () { */ Phaser.World.prototype.postUpdate = function () { + this.camera.update(); + if (this.game.stage._stage.first._iNext) { var currentNode = this.game.stage._stage.first._iNext; @@ -12557,13 +12802,11 @@ Phaser.World.prototype.postUpdate = function () { } while (currentNode != this.game.stage._stage.last._iNext) } - - this.camera.update(); } /** * Updates the size of this world. Note that this doesn't modify the world x/y coordinates, just the width and height. -* If you need to adjust the bounds of the world +* * @method Phaser.World#setBounds * @param {number} x - Top left most corner of the world. * @param {number} y - Top left most corner of the world. @@ -12572,10 +12815,22 @@ Phaser.World.prototype.postUpdate = function () { */ Phaser.World.prototype.setBounds = function (x, y, width, height) { + if (width < this.game.width) + { + width = this.game.width; + } + + if (height < this.game.height) + { + height = this.game.height; + } + this.bounds.setTo(x, y, width, height); if (this.camera.bounds) { + // The Camera can never be smaller than the game size + this.camera.bounds.setTo(x, y, width, height); } @@ -12733,64 +12988,68 @@ Object.defineProperty(Phaser.World.prototype, "visible", { * @param {number} [width=800] - The width of your game in game pixels. * @param {number} [height=600] - The height of your game in game pixels. * @param {number} [renderer=Phaser.AUTO] - Which renderer to use: Phaser.AUTO will auto-detect, Phaser.WEBGL, Phaser.CANVAS or Phaser.HEADLESS (no rendering at all). -* @param {HTMLElement} [parent=''] - The Games DOM parent. -* @param {any} [state=null] - Description. +* @param {string|HTMLElement} [parent=''] - The DOM element into which this games canvas will be injected. Either a DOM ID (string) or the element itself. +* @param {object} [state=null] - The default state object. A object consisting of Phaser.State functions (preload, create, update, render) or null. * @param {boolean} [transparent=false] - Use a transparent canvas background or not. * @param {boolean} [antialias=true] - Anti-alias graphics. */ Phaser.Game = function (width, height, renderer, parent, state, transparent, antialias) { - width = width || 800; - height = height || 600; - renderer = renderer || Phaser.AUTO; - parent = parent || ''; - state = state || null; - - if (typeof transparent == 'undefined') { transparent = false; } - if (typeof antialias == 'undefined') { antialias = true; } - /** * @property {number} id - Phaser Game ID (for when Pixi supports multiple instances). */ this.id = Phaser.GAMES.push(this) - 1; /** - * @property {HTMLElement} parent - The Games DOM parent. + * @property {object} config - The Phaser.Game configuration object. */ - this.parent = parent; + this.config = null; - // Do some more intelligent size parsing here, so they can set "100%" for example, maybe pass the scale mode in here too? + /** + * @property {HTMLElement} parent - The Games DOM parent. + * @default + */ + this.parent = ''; /** * @property {number} width - The Game width (in pixels). + * @default */ - this.width = width; + this.width = 800; /** * @property {number} height - The Game height (in pixels). + * @default */ - this.height = height; + this.height = 600; /** * @property {boolean} transparent - Use a transparent canvas background or not. + * @default */ - this.transparent = transparent; + this.transparent = false; /** * @property {boolean} antialias - Anti-alias graphics (in WebGL this helps with edges, in Canvas2D it retains pixel-art quality). + * @default */ - this.antialias = antialias; + this.antialias = true; /** * @property {number} renderer - The Pixi Renderer * @default */ - this.renderer = null; + this.renderer = Phaser.AUTO; + + /** + * @property {number} renderType - The Renderer this Phaser.Game will use. Either Phaser.RENDERER_AUTO, Phaser.RENDERER_CANVAS or Phaser.RENDERER_WEBGL. + */ + this.renderType = Phaser.AUTO; /** * @property {number} state - The StateManager. */ - this.state = new Phaser.StateManager(this, state); + this.state = null; /** * @property {boolean} _paused - Is game paused? @@ -12799,11 +13058,6 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant */ this._paused = false; - /** - * @property {number} renderType - The Renderer this Phaser.Game will use. Either Phaser.RENDERER_AUTO, Phaser.RENDERER_CANVAS or Phaser.RENDERER_WEBGL. - */ - this.renderType = renderer; - /** * @property {boolean} _loadComplete - Whether load complete loading or not. * @private @@ -12943,6 +13197,47 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant */ this.particles = null; + // Parse the configuration object (if any) + if (arguments.length === 1 && typeof arguments[0] === 'object') + { + this.parseConfig(arguments[0]); + } + else + { + if (typeof width !== 'undefined') + { + this.width = width; + } + + if (typeof height !== 'undefined') + { + this.height = height; + } + + if (typeof renderer !== 'undefined') + { + this.renderer = renderer; + this.renderType = renderer; + } + + if (typeof parent !== 'undefined') + { + this.parent = parent; + } + + if (typeof transparent !== 'undefined') + { + this.transparent = transparent; + } + + if (typeof antialias !== 'undefined') + { + this.antialias = antialias; + } + + this.state = new Phaser.StateManager(this, state); + } + var _this = this; this._onBoot = function () { @@ -12965,6 +13260,99 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant Phaser.Game.prototype = { + /** + * Parses a Game configuration object. + * + * @method Phaser.Game#parseConfig + * @protected + */ + parseConfig: function (config) { + + this.config = config; + + if (config['width']) + { + this.width = this.parseDimension(config['width'], 0); + } + + if (config['height']) + { + this.height = this.parseDimension(config['height'], 1); + } + + if (config['renderer']) + { + this.renderer = config['renderer']; + this.renderType = config['renderer']; + } + + if (config['parent']) + { + this.parent = config['parent']; + } + + if (config['transparent']) + { + this.transparent = config['transparent']; + } + + if (config['antialias']) + { + this.antialias = config['antialias']; + } + + var state = null; + + if (config['state']) + { + state = config['state']; + } + + this.state = new Phaser.StateManager(this, state); + + }, + + /** + * Get dimension. + * + * @method Phaser.Game#parseDimension + * @protected + */ + parseDimension: function (size, dimension) { + + var f = 0; + var px = 0; + + if (typeof size === 'string') + { + // %? + if (size.substr(-1) === '%') + { + f = parseInt(size, 10) / 100; + + if (dimension === 0) + { + px = window.innerWidth * f; + } + else + { + px = window.innerHeight * f; + } + } + else + { + px = parseInt(size, 10); + } + } + else + { + px = size; + } + + return px; + + }, + /** * Initialize engine sub modules and start the game. * @@ -13014,6 +13402,7 @@ Phaser.Game.prototype = { this.net = new Phaser.Net(this); this.debug = new Phaser.Utils.Debug(this); + this.time.boot(); this.stage.boot(); this.world.boot(); this.input.boot(); @@ -13088,6 +13477,14 @@ Phaser.Game.prototype = { */ setUpRenderer: function () { + /* + if (this.device.trident) + { + // Pixi WebGL renderer on IE11 doesn't work correctly with masks, if you need them you may want to comment this block out + this.renderType = Phaser.CANVAS; + } + */ + if (this.renderType === Phaser.HEADLESS || this.renderType === Phaser.CANVAS || (this.renderType === Phaser.AUTO && this.device.webGL === false)) { if (this.device.canvas) @@ -13156,14 +13553,15 @@ Phaser.Game.prototype = { { this.plugins.preUpdate(); this.physics.preUpdate(); + this.world.preUpdate(); this.stage.update(); this.input.update(); this.tweens.update(); this.sound.update(); - this.world.update(); - this.particles.update(); this.state.update(); + this.world.update(); + this.particles.update(); this.plugins.update(); this.world.postUpdate(); @@ -13209,6 +13607,8 @@ Phaser.Game.prototype = { }; +Phaser.Game.prototype.constructor = Phaser.Game; + /** * The paused state of the Game. A paused game doesn't update any of its subsystems. * When a game is paused the onPause event is dispatched. When it is resumed the onResume event is dispatched. @@ -13556,6 +13956,13 @@ Phaser.Input.prototype = { */ mspointer: null, + /** + * The Gamepad Input manager. + * @property {Phaser.Gamepad} gamepad - The Gamepad Input manager. + * @default + */ + gamepad: null, + /** * A Signal that is dispatched each time a pointer is pressed down. * @property {Phaser.Signal} onDown @@ -13605,6 +14012,7 @@ Phaser.Input.prototype = { this.keyboard = new Phaser.Keyboard(this.game); this.touch = new Phaser.Touch(this.game); this.mspointer = new Phaser.MSPointer(this.game); + this.gamepad = new Phaser.Gamepad(this.game); this.onDown = new Phaser.Signal(); this.onUp = new Phaser.Signal(); @@ -13644,6 +14052,7 @@ Phaser.Input.prototype = { this.keyboard.stop(); this.touch.stop(); this.mspointer.stop(); + this.gamepad.stop(); }, @@ -13697,6 +14106,8 @@ Phaser.Input.prototype = { this._oldPosition.copyFrom(this.position); this.mousePointer.update(); + if (this.gamepad.active) { this.gamepad.update(); } + this.pointer1.update(); this.pointer2.update(); @@ -13728,6 +14139,7 @@ Phaser.Input.prototype = { this.keyboard.reset(); this.mousePointer.reset(); + this.gamepad.reset(); for (var i = 1; i <= 10; i++) { @@ -13738,7 +14150,11 @@ Phaser.Input.prototype = { } this.currentPointers = 0; - this.game.stage.canvas.style.cursor = "default"; + + if (this.game.canvas.style.cursor !== 'none') + { + this.game.canvas.style.cursor = 'default'; + } if (hard === true) { @@ -13935,6 +14351,8 @@ Phaser.Input.prototype = { }; +Phaser.Input.prototype.constructor = Phaser.Input; + /** * The X coordinate of the most recently active pointer. This value takes game scaling into account automatically. See Pointer.screenX/clientX for source values. * @name Phaser.Input#x @@ -14220,6 +14638,8 @@ Phaser.Key.prototype = { }; +Phaser.Key.prototype.constructor = Phaser.Key; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -14322,7 +14742,7 @@ Phaser.Keyboard.prototype = { * The Key object can then be polled, have events attached to it, etc. * * @method Phaser.Keyboard#addKey - * @param {number} keycode - The keycode of the key, i.e. Phaser.Keyboard.UP or Phaser.Keyboard.SPACE_BAR + * @param {number} keycode - The keycode of the key, i.e. Phaser.Keyboard.UP or Phaser.Keyboard.SPACEBAR * @return {Phaser.Key} The Key object which you can store locally and reference directly. */ addKey: function (keycode) { @@ -14339,7 +14759,7 @@ Phaser.Keyboard.prototype = { * Removes a Key object from the Keyboard manager. * * @method Phaser.Keyboard#removeKey - * @param {number} keycode - The keycode of the key to remove, i.e. Phaser.Keyboard.UP or Phaser.Keyboard.SPACE_BAR + * @param {number} keycode - The keycode of the key to remove, i.e. Phaser.Keyboard.UP or Phaser.Keyboard.SPACEBAR */ removeKey: function (keycode) { @@ -14561,7 +14981,7 @@ Phaser.Keyboard.prototype = { /** * Returns the "just pressed" state of the key. Just pressed is considered true if the key was pressed down within the duration given (default 250ms) * @method Phaser.Keyboard#justPressed - * @param {number} keycode - The keycode of the key to remove, i.e. Phaser.Keyboard.UP or Phaser.Keyboard.SPACE_BAR + * @param {number} keycode - The keycode of the key to remove, i.e. Phaser.Keyboard.UP or Phaser.Keyboard.SPACEBAR * @param {number} [duration=250] - The duration below which the key is considered as being just pressed. * @return {boolean} True if the key is just pressed otherwise false. */ @@ -14580,8 +15000,8 @@ Phaser.Keyboard.prototype = { /** * Returns the "just released" state of the Key. Just released is considered as being true if the key was released within the duration given (default 250ms) - * @method Phaser.Keyboard#justPressed - * @param {number} keycode - The keycode of the key to remove, i.e. Phaser.Keyboard.UP or Phaser.Keyboard.SPACE_BAR + * @method Phaser.Keyboard#justReleased + * @param {number} keycode - The keycode of the key to remove, i.e. Phaser.Keyboard.UP or Phaser.Keyboard.SPACEBAR * @param {number} [duration=250] - The duration below which the key is considered as being just released. * @return {boolean} True if the key is just released otherwise false. */ @@ -14601,7 +15021,7 @@ Phaser.Keyboard.prototype = { /** * Returns true of the key is currently pressed down. Note that it can only detect key presses on the web browser. * @method Phaser.Keyboard#isDown - * @param {number} keycode - The keycode of the key to remove, i.e. Phaser.Keyboard.UP or Phaser.Keyboard.SPACE_BAR + * @param {number} keycode - The keycode of the key to remove, i.e. Phaser.Keyboard.UP or Phaser.Keyboard.SPACEBAR * @return {boolean} True if the key is currently down. */ isDown: function (keycode) { @@ -14617,6 +15037,8 @@ Phaser.Keyboard.prototype = { }; +Phaser.Keyboard.prototype.constructor = Phaser.Keyboard; + Phaser.Keyboard.A = "A".charCodeAt(0); Phaser.Keyboard.B = "B".charCodeAt(0); Phaser.Keyboard.C = "C".charCodeAt(0); @@ -14786,7 +15208,8 @@ Phaser.Mouse = function (game) { this.pointerLock = new Phaser.Signal(); /** - * @property {MouseEvent} event - The browser mouse event. + * @property {MouseEvent} event - The browser mouse DOM event. Will be set to null if no mouse event has ever been received. + * @default */ this.event = null; @@ -15045,6 +15468,8 @@ Phaser.Mouse.prototype = { }; +Phaser.Mouse.prototype.constructor = Phaser.Mouse; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -15213,6 +15638,9 @@ Phaser.MSPointer.prototype = { } }; + +Phaser.MSPointer.prototype.constructor = Phaser.MSPointer; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -15422,7 +15850,7 @@ Phaser.Pointer.prototype = { } // Fix to stop rogue browser plugins from blocking the visibility state event - if (this.game.paused === true && this.game.stage.scale.incorrectOrientation === false) + if (this.game.stage.disableVisibilityChange === false && this.game.paused && this.game.stage.scale.incorrectOrientation === false) { this.game.paused = false; return this; @@ -15798,6 +16226,8 @@ Phaser.Pointer.prototype = { }; +Phaser.Pointer.prototype.constructor = Phaser.Pointer; + /** * How long the Pointer has been depressed on the touchscreen. If not currently down it returns -1. * @name Phaser.Pointer#duration @@ -15920,7 +16350,8 @@ Phaser.Touch = function (game) { this.preventDefault = true; /** - * @property {TouchEvent} event - The browser touch event. + * @property {TouchEvent} event - The browser touch DOM event. Will be set to null if no touch event has ever been received. + * @default */ this.event = null; @@ -16233,6 +16664,9 @@ Phaser.Touch.prototype = { } }; + +Phaser.Touch.prototype.constructor = Phaser.Touch; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -16263,36 +16697,6 @@ Phaser.InputHandler = function (sprite) { */ this.enabled = false; - /** - * @property {Description} parent - Description. - * @default - */ - // this.parent = null; - - /** - * @property {Description} next - Linked List - * @default - */ - // this.next = null; - - /** - * @property {Description} prev - Description. - * @default - */ - // this.prev = null; - - /** - * @property {Description} last - Description. - * @default - */ - // this.last = this; - - /** - * @property {Description} first - Description. - * @default - */ - // this.first = this; - /** * @property {number} priorityID - The PriorityID controls which Sprite receives an Input event first if they should overlap. * @default @@ -16359,6 +16763,18 @@ Phaser.InputHandler = function (sprite) { */ this.snapY = 0; + /** + * @property {number} snapOffsetX - This defines the top-left X coordinate of the snap grid. + * @default + */ + this.snapOffsetX = 0; + + /** + * @property {number} snapOffsetY - This defines the top-left Y coordinate of the snap grid.. + * @default + */ + this.snapOffsetY = 0; + /** * @property {number} pixelPerfect - Should we use pixel perfect hit detection? Warning: expensive. Only enable if you really need it! * @default @@ -16434,8 +16850,6 @@ Phaser.InputHandler.prototype = { */ start: function (priority, useHandCursor) { - console.log('InputHandler start'); - priority = priority || 0; if (typeof useHandCursor == 'undefined') { useHandCursor = false; } @@ -16851,7 +17265,7 @@ Phaser.InputHandler.prototype = { if (this.useHandCursor && this._pointerData[pointer.id].isDragged === false) { - this.game.stage.canvas.style.cursor = "pointer"; + this.game.canvas.style.cursor = "pointer"; } this.sprite.events.onInputOver.dispatch(this.sprite, pointer); @@ -16872,7 +17286,7 @@ Phaser.InputHandler.prototype = { if (this.useHandCursor && this._pointerData[pointer.id].isDragged === false) { - this.game.stage.canvas.style.cursor = "default"; + this.game.canvas.style.cursor = "default"; } if (this.sprite && this.sprite.events) @@ -16933,15 +17347,18 @@ Phaser.InputHandler.prototype = { // Only release the InputUp signal if the pointer is still over this sprite if (this.checkPointerOver(pointer)) { - //console.log('releasedHandler: ' + Date.now()); - this.sprite.events.onInputUp.dispatch(this.sprite, pointer); + // Release the inputUp signal and provide optional parameter if pointer is still over the sprite or not + this.sprite.events.onInputUp.dispatch(this.sprite, pointer, true); } else { + // Release the inputUp signal and provide optional parameter if pointer is still over the sprite or not + this.sprite.events.onInputUp.dispatch(this.sprite, pointer, false); + // Pointer outside the sprite? Reset the cursor if (this.useHandCursor) { - this.game.stage.canvas.style.cursor = "default"; + this.game.canvas.style.cursor = "default"; } } @@ -16968,30 +17385,61 @@ Phaser.InputHandler.prototype = { return false; } - if (this.allowHorizontalDrag) + if (this.sprite.fixedToCamera) { - this.sprite.x = pointer.x + this._dragPoint.x + this.dragOffset.x; - } + if (this.allowHorizontalDrag) + { + this.sprite.cameraOffset.x = pointer.x + this._dragPoint.x + this.dragOffset.x; + } - if (this.allowVerticalDrag) - { - this.sprite.y = pointer.y + this._dragPoint.y + this.dragOffset.y; - } + if (this.allowVerticalDrag) + { + this.sprite.cameraOffset.y = pointer.y + this._dragPoint.y + this.dragOffset.y; + } - if (this.boundsRect) - { - this.checkBoundsRect(); - } + if (this.boundsRect) + { + this.checkBoundsRect(); + } - if (this.boundsSprite) - { - this.checkBoundsSprite(); - } + if (this.boundsSprite) + { + this.checkBoundsSprite(); + } - if (this.snapOnDrag) + if (this.snapOnDrag) + { + this.sprite.cameraOffset.x = Math.round((this.sprite.cameraOffset.x - (this.snapOffsetX % this.snapX)) / this.snapX) * this.snapX + (this.snapOffsetX % this.snapX); + this.sprite.cameraOffset.y = Math.round((this.sprite.cameraOffset.y - (this.snapOffsetY % this.snapY)) / this.snapY) * this.snapY + (this.snapOffsetY % this.snapY); + } + } + else { - this.sprite.x = Math.round(this.sprite.x / this.snapX) * this.snapX; - this.sprite.y = Math.round(this.sprite.y / this.snapY) * this.snapY; + if (this.allowHorizontalDrag) + { + this.sprite.x = pointer.x + this._dragPoint.x + this.dragOffset.x; + } + + if (this.allowVerticalDrag) + { + this.sprite.y = pointer.y + this._dragPoint.y + this.dragOffset.y; + } + + if (this.boundsRect) + { + this.checkBoundsRect(); + } + + if (this.boundsSprite) + { + this.checkBoundsSprite(); + } + + if (this.snapOnDrag) + { + this.sprite.x = Math.round((this.sprite.x - (this.snapOffsetX % this.snapX)) / this.snapX) * this.snapX + (this.snapOffsetX % this.snapX); + this.sprite.y = Math.round((this.sprite.y - (this.snapOffsetY % this.snapY)) / this.snapY) * this.snapY + (this.snapOffsetY % this.snapY); + } } return true; @@ -17171,14 +17619,29 @@ Phaser.InputHandler.prototype = { this._draggedPointerID = pointer.id; this._pointerData[pointer.id].isDragged = true; - if (this.dragFromCenter) + if (this.sprite.fixedToCamera) { - this.sprite.centerOn(pointer.x, pointer.y); - this._dragPoint.setTo(this.sprite.x - pointer.x, this.sprite.y - pointer.y); + if (this.dragFromCenter) + { + this.sprite.centerOn(pointer.x, pointer.y); + this._dragPoint.setTo(this.sprite.cameraOffset.x - pointer.x, this.sprite.cameraOffset.y - pointer.y); + } + else + { + this._dragPoint.setTo(this.sprite.cameraOffset.x - pointer.x, this.sprite.cameraOffset.y - pointer.y); + } } else { - this._dragPoint.setTo(this.sprite.x - pointer.x, this.sprite.y - pointer.y); + if (this.dragFromCenter) + { + this.sprite.centerOn(pointer.x, pointer.y); + this._dragPoint.setTo(this.sprite.x - pointer.x, this.sprite.y - pointer.y); + } + else + { + this._dragPoint.setTo(this.sprite.x - pointer.x, this.sprite.y - pointer.y); + } } this.updateDrag(pointer); @@ -17205,8 +17668,16 @@ Phaser.InputHandler.prototype = { if (this.snapOnRelease) { - this.sprite.x = Math.round(this.sprite.x / this.snapX) * this.snapX; - this.sprite.y = Math.round(this.sprite.y / this.snapY) * this.snapY; + if (this.sprite.fixedToCamera) + { + this.sprite.cameraOffset.x = Math.round((this.sprite.cameraOffset.x - (this.snapOffsetX % this.snapX)) / this.snapX) * this.snapX + (this.snapOffsetX % this.snapX); + this.sprite.cameraOffset.y = Math.round((this.sprite.cameraOffset.y - (this.snapOffsetY % this.snapY)) / this.snapY) * this.snapY + (this.snapOffsetY % this.snapY); + } + else + { + this.sprite.x = Math.round((this.sprite.x - (this.snapOffsetX % this.snapX)) / this.snapX) * this.snapX + (this.snapOffsetX % this.snapX); + this.sprite.y = Math.round((this.sprite.y - (this.snapOffsetY % this.snapY)) / this.snapY) * this.snapY + (this.snapOffsetY % this.snapY); + } } this.sprite.events.onDragStop.dispatch(this.sprite, pointer); @@ -17243,14 +17714,20 @@ Phaser.InputHandler.prototype = { * @param {number} snapY - The height of the grid cell to snap to. * @param {boolean} [onDrag=true] - If true the sprite will snap to the grid while being dragged. * @param {boolean} [onRelease=false] - If true the sprite will snap to the grid when released. + * @param {number} [snapOffsetX=0] - Used to offset the top-left starting point of the snap grid. + * @param {number} [snapOffsetX=0] - Used to offset the top-left starting point of the snap grid. */ - enableSnap: function (snapX, snapY, onDrag, onRelease) { + enableSnap: function (snapX, snapY, onDrag, onRelease, snappOffsetX, snappOffsetY) { if (typeof onDrag == 'undefined') { onDrag = true; } if (typeof onRelease == 'undefined') { onRelease = false; } + if (typeof snapOffsetX == 'undefined') { snapOffsetX = 0; } + if (typeof snapOffsetY == 'undefined') { snapOffsetY = 0; } this.snapX = snapX; this.snapY = snapY; + this.snapOffsetX = snapOffsetX; + this.snapOffsetY = snapOffsetY; this.snapOnDrag = onDrag; this.snapOnRelease = onRelease; @@ -17273,22 +17750,45 @@ Phaser.InputHandler.prototype = { */ checkBoundsRect: function () { - if (this.sprite.x < this.boundsRect.left) + if (this.sprite.fixedToCamera) { - this.sprite.x = this.boundsRect.x; - } - else if ((this.sprite.x + this.sprite.width) > this.boundsRect.right) - { - this.sprite.x = this.boundsRect.right - this.sprite.width; - } + if (this.sprite.cameraOffset.x < this.boundsRect.left) + { + this.sprite.cameraOffset.x = this.boundsRect.cameraOffset.x; + } + else if ((this.sprite.cameraOffset.x + this.sprite.width) > this.boundsRect.right) + { + this.sprite.cameraOffset.x = this.boundsRect.right - this.sprite.width; + } - if (this.sprite.y < this.boundsRect.top) - { - this.sprite.y = this.boundsRect.top; + if (this.sprite.cameraOffset.y < this.boundsRect.top) + { + this.sprite.cameraOffset.y = this.boundsRect.top; + } + else if ((this.sprite.cameraOffset.y + this.sprite.height) > this.boundsRect.bottom) + { + this.sprite.cameraOffset.y = this.boundsRect.bottom - this.sprite.height; + } } - else if ((this.sprite.y + this.sprite.height) > this.boundsRect.bottom) + else { - this.sprite.y = this.boundsRect.bottom - this.sprite.height; + if (this.sprite.x < this.boundsRect.left) + { + this.sprite.x = this.boundsRect.x; + } + else if ((this.sprite.x + this.sprite.width) > this.boundsRect.right) + { + this.sprite.x = this.boundsRect.right - this.sprite.width; + } + + if (this.sprite.y < this.boundsRect.top) + { + this.sprite.y = this.boundsRect.top; + } + else if ((this.sprite.y + this.sprite.height) > this.boundsRect.bottom) + { + this.sprite.y = this.boundsRect.bottom - this.sprite.height; + } } }, @@ -17299,27 +17799,1378 @@ Phaser.InputHandler.prototype = { */ checkBoundsSprite: function () { - if (this.sprite.x < this.boundsSprite.x) + if (this.sprite.fixedToCamera && this.boundsSprite.fixedToCamera) { - this.sprite.x = this.boundsSprite.x; - } - else if ((this.sprite.x + this.sprite.width) > (this.boundsSprite.x + this.boundsSprite.width)) - { - this.sprite.x = (this.boundsSprite.x + this.boundsSprite.width) - this.sprite.width; - } + if (this.sprite.cameraOffset.x < this.boundsSprite.camerOffset.x) + { + this.sprite.cameraOffset.x = this.boundsSprite.camerOffset.x; + } + else if ((this.sprite.cameraOffset.x + this.sprite.width) > (this.boundsSprite.camerOffset.x + this.boundsSprite.width)) + { + this.sprite.cameraOffset.x = (this.boundsSprite.camerOffset.x + this.boundsSprite.width) - this.sprite.width; + } - if (this.sprite.y < this.boundsSprite.y) - { - this.sprite.y = this.boundsSprite.y; + if (this.sprite.cameraOffset.y < this.boundsSprite.camerOffset.y) + { + this.sprite.cameraOffset.y = this.boundsSprite.camerOffset.y; + } + else if ((this.sprite.cameraOffset.y + this.sprite.height) > (this.boundsSprite.camerOffset.y + this.boundsSprite.height)) + { + this.sprite.cameraOffset.y = (this.boundsSprite.camerOffset.y + this.boundsSprite.height) - this.sprite.height; + } } - else if ((this.sprite.y + this.sprite.height) > (this.boundsSprite.y + this.boundsSprite.height)) + else { - this.sprite.y = (this.boundsSprite.y + this.boundsSprite.height) - this.sprite.height; + if (this.sprite.x < this.boundsSprite.x) + { + this.sprite.x = this.boundsSprite.x; + } + else if ((this.sprite.x + this.sprite.width) > (this.boundsSprite.x + this.boundsSprite.width)) + { + this.sprite.x = (this.boundsSprite.x + this.boundsSprite.width) - this.sprite.width; + } + + if (this.sprite.y < this.boundsSprite.y) + { + this.sprite.y = this.boundsSprite.y; + } + else if ((this.sprite.y + this.sprite.height) > (this.boundsSprite.y + this.boundsSprite.height)) + { + this.sprite.y = (this.boundsSprite.y + this.boundsSprite.height) - this.sprite.height; + } } } }; + +Phaser.InputHandler.prototype.constructor = Phaser.InputHandler; + +/** +* @author @karlmacklin +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +*/ + +/** +* The Gamepad class handles looking after gamepad input for your game. +* Remember to call gamepad.start(); expecting input! +* +* HTML5 GAMEPAD API SUPPORT IS AT AN EXPERIMENTAL STAGE! +* At moment of writing this (end of 2013) only Chrome supports parts of it out of the box. Firefox supports it +* via prefs flags (about:config, search gamepad). The browsers map the same controllers differently. +* This class has constans for Windows 7 Chrome mapping of +* XBOX 360 controller. +* +* @class Phaser.Gamepad +* @constructor +* @param {Phaser.Game} game - A reference to the currently running game. +*/ +Phaser.Gamepad = function (game) { + + /** + * @property {Phaser.Game} game - Local reference to game. + */ + this.game = game; + + /** + * @property {Array} _gamepads - The four Phaser Gamepads. + * @private + */ + this._gamepads = [ + new Phaser.SinglePad(game, this), + new Phaser.SinglePad(game, this), + new Phaser.SinglePad(game, this), + new Phaser.SinglePad(game, this) + ]; + + /** + * @property {Object} _gamepadIndexMap - Maps the browsers gamepad indices to our Phaser Gamepads + * @private + */ + this._gamepadIndexMap = {}; + + /** + * @property {Array} _rawPads - The raw state of the gamepads from the browser + * @private + */ + this._rawPads = []; + + /** + * @property {boolean} _active - Private flag for whether or not the API is polled + * @private + * @default + */ + this._active = false; + + /** + * You can disable all Gamepad Input by setting disabled to true. While true all new input related events will be ignored. + * @property {boolean} disabled - The disabled state of the Gamepad. + * @default + */ + this.disabled = false; + + /** + * Whether or not gamepads are supported in the current browser. Note that as of Dec. 2013 this check is actually not accurate at all due to poor implementation. + * @property {boolean} _gamepadSupportAvailable - Are gamepads supported in this browser or not? + * @private + */ + this._gamepadSupportAvailable = !!navigator.webkitGetGamepads || !!navigator.webkitGamepads || (navigator.userAgent.indexOf('Firefox/') != -1); + + /** + * Used to check for differences between earlier polls and current state of gamepads. + * @property {Array} _prevRawGamepadTypes + * @private + * @default + */ + this._prevRawGamepadTypes = []; + + /** + * Used to check for differences between earlier polls and current state of gamepads. + * @property {Array} _prevTimestamps + * @private + * @default + */ + this._prevTimestamps = []; + + /** + * @property {Object} callbackContext - The context under which the callbacks are run. + */ + this.callbackContext = this; + + /** + * @property {function} onConnectCallback - This callback is invoked every time any gamepad is connected + */ + this.onConnectCallback = null; + + /** + * @property {function} onDisconnectCallback - This callback is invoked every time any gamepad is disconnected + */ + this.onDisconnectCallback = null; + + /** + * @property {function} onDownCallback - This callback is invoked every time any gamepad button is pressed down. + */ + this.onDownCallback = null; + + /** + * @property {function} onUpCallback - This callback is invoked every time any gamepad button is released. + */ + this.onUpCallback = null; + + /** + * @property {function} onAxisCallback - This callback is invoked every time any gamepad axis is changed. + */ + this.onAxisCallback = null; + + /** + * @property {function} onFloatCallback - This callback is invoked every time any gamepad button is changed to a value where value > 0 and value < 1. + */ + this.onFloatCallback = null; + + /** + * @property {function} _ongamepadconnected - Private callback for Firefox gamepad connection handling + * @private + */ + this._ongamepadconnected = null; + + /** + * @property {function} _gamepaddisconnected - Private callback for Firefox gamepad connection handling + * @private + */ + this._gamepaddisconnected = null; +}; + +Phaser.Gamepad.prototype = { + + /** + * Add callbacks to the main Gamepad handler to handle connect/disconnect/button down/button up/axis change/float value buttons + * @method Phaser.Gamepad#addCallbacks + * @param {Object} context - The context under which the callbacks are run. + * @param {Object} callbacks - Object that takes six different callback methods: + * onConnectCallback, onDisconnectCallback, onDownCallback, onUpCallback, onAxisCallback, onFloatCallback + */ + addCallbacks: function (context, callbacks) { + + if (typeof callbacks !== 'undefined') + { + this.onConnectCallback = (typeof callbacks.onConnect === 'function') ? callbacks.onConnect : this.onConnectCallback; + this.onDisconnectCallback = (typeof callbacks.onDisconnect === 'function') ? callbacks.onDisconnect : this.onDisconnectCallback; + this.onDownCallback = (typeof callbacks.onDown === 'function') ? callbacks.onDown : this.onDownCallback; + this.onUpCallback = (typeof callbacks.onUp === 'function') ? callbacks.onUp : this.onUpCallback; + this.onAxisCallback = (typeof callbacks.onAxis === 'function') ? callbacks.onAxis : this.onAxisCallback; + this.onFloatCallback = (typeof callbacks.onFloat === 'function') ? callbacks.onFloat : this.onFloatCallback; + } + + }, + + /** + * Starts the Gamepad event handling. + * This MUST be called manually before Phaser will start polling the Gamepad API. + * + * @method Phaser.Gamepad#start + */ + start: function () { + + this._active = true; + var _this = this; + + this._ongamepadconnected = function(event) { + var newPad = event.gamepad; + _this._rawPads.push(newPad); + _this._gamepads[newPad.index].connect(newPad); + }; + + window.addEventListener('gamepadconnected', this._ongamepadconnected, false); + + this._ongamepaddisconnected = function(event) { + + var removedPad = event.gamepad; + + for (var i in _this._rawPads) + { + if (_this._rawPads[i].index === removedPad.index) + { + _this._rawPads.splice(i,1); + } + } + _this._gamepads[removedPad.index].disconnect(); + }; + + window.addEventListener('gamepaddisconnected', this._ongamepaddisconnected, false); + + }, + + /** + * Main gamepad update loop. Should not be called manually. + * @method Phaser.Gamepad#update + * @private + */ + update: function () { + + this._pollGamepads(); + + for (var i = 0; i < this._gamepads.length; i++) + { + if (this._gamepads[i]._connected) + { + this._gamepads[i].pollStatus(); + } + } + + }, + + /** + * Updating connected gamepads (for Google Chrome). + * Should not be called manually. + * @method Phaser.Gamepad#_pollGamepads + * @private + */ + _pollGamepads: function () { + + var rawGamepads = (navigator.webkitGetGamepads && navigator.webkitGetGamepads()) || navigator.webkitGamepads; + + if (rawGamepads) + { + this._rawPads = []; + + var gamepadsChanged = false; + + for (var i = 0; i < rawGamepads.length; i++) + { + if (typeof rawGamepads[i] !== this._prevRawGamepadTypes[i]) + { + gamepadsChanged = true; + this._prevRawGamepadTypes[i] = typeof rawGamepads[i]; + } + + if (rawGamepads[i]) + { + this._rawPads.push(rawGamepads[i]); + } + + // Support max 4 pads at the moment + if (i === 3) + { + break; + } + } + + if (gamepadsChanged) + { + var validConnections = { rawIndices: {}, padIndices: {} }; + var singlePad; + + for (var j = 0; j < this._gamepads.length; j++) + { + singlePad = this._gamepads[j]; + + if (singlePad.connected) + { + for (var k = 0; k < this._rawPads.length; k++) + { + if (this._rawPads[k].index === singlePad.index) + { + validConnections.rawIndices[singlePad.index] = true; + validConnections.padIndices[j] = true; + } + } + } + } + + for (var l = 0; l < this._gamepads.length; l++) + { + singlePad = this._gamepads[l]; + + if (validConnections.padIndices[l]) + { + continue; + } + + if (this._rawPads.length < 1) + { + singlePad.disconnect(); + } + + for (var m = 0; m < this._rawPads.length; m++) + { + if (validConnections.padIndices[l]) + { + break; + } + + var rawPad = this._rawPads[m]; + + if (rawPad) + { + if (validConnections.rawIndices[rawPad.index]) + { + singlePad.disconnect(); + continue; + } + else + { + singlePad.connect(rawPad); + validConnections.rawIndices[rawPad.index] = true; + validConnections.padIndices[l] = true; + } + } + else + { + singlePad.disconnect(); + } + } + } + } + } + }, + + /** + * Sets the deadZone variable for all four gamepads + * @method Phaser.Gamepad#setDeadZones + */ + setDeadZones: function (value) { + + for (var i = 0; i < this._gamepads.length; i++) + { + this._gamepads[i].deadZone = value; + } + + }, + + /** + * Stops the Gamepad event handling. + * + * @method Phaser.Gamepad#stop + */ + stop: function () { + + this._active = false; + + window.removeEventListener('gamepadconnected', this._ongamepadconnected); + window.removeEventListener('gamepaddisconnected', this._ongamepaddisconnected); + + }, + + /** + * Reset all buttons/axes of all gamepads + * @method Phaser.Gamepad#reset + */ + reset: function () { + + this.update(); + + for (var i = 0; i < this._gamepads.length; i++) + { + this._gamepads[i].reset(); + } + + }, + + /** + * Returns the "just pressed" state of a button from ANY gamepad connected. Just pressed is considered true if the button was pressed down within the duration given (default 250ms). + * @method Phaser.Gamepad#justPressed + * @param {number} buttonCode - The buttonCode of the button to check for. + * @param {number} [duration=250] - The duration below which the button is considered as being just pressed. + * @return {boolean} True if the button is just pressed otherwise false. + */ + justPressed: function (buttonCode, duration) { + + for (var i = 0; i < this._gamepads.length; i++) + { + if (this._gamepads[i].justPressed(buttonCode, duration) === true) + { + return true; + } + } + + return false; + + }, + + /** + * Returns the "just released" state of a button from ANY gamepad connected. Just released is considered as being true if the button was released within the duration given (default 250ms). + * @method Phaser.Gamepad#justPressed + * @param {number} buttonCode - The buttonCode of the button to check for. + * @param {number} [duration=250] - The duration below which the button is considered as being just released. + * @return {boolean} True if the button is just released otherwise false. + */ + justReleased: function (buttonCode, duration) { + + for (var i = 0; i < this._gamepads.length; i++) + { + if (this._gamepads[i].justReleased(buttonCode, duration) === true) + { + return true; + } + } + + return false; + + }, + + /** + * Returns true if the button is currently pressed down, on ANY gamepad. + * @method Phaser.Gamepad#isDown + * @param {number} buttonCode - The buttonCode of the button to check for. + * @return {boolean} True if a button is currently down. + */ + isDown: function (buttonCode) { + + for (var i = 0; i < this._gamepads.length; i++) + { + if (this._gamepads[i].isDown(buttonCode) === true) + { + return true; + } + } + + return false; + } + +}; + +Phaser.Gamepad.prototype.constructor = Phaser.Gamepad; + +/** +* If the gamepad input is active or not - if not active it should not be updated from Input.js +* @name Phaser.Gamepad#active +* @property {boolean} active - If the gamepad input is active or not. +* @readonly +*/ +Object.defineProperty(Phaser.Gamepad.prototype, "active", { + + get: function () { + return this._active; + } + +}); + +/** +* Whether or not gamepads are supported in current browser. +* @name Phaser.Gamepad#supported +* @property {boolean} supported - Whether or not gamepads are supported in current browser. +* @readonly +*/ +Object.defineProperty(Phaser.Gamepad.prototype, "supported", { + + get: function () { + return this._gamepadSupportAvailable; + } + +}); + +/** +* How many live gamepads are currently connected. +* @name Phaser.Gamepad#padsConnected +* @property {boolean} padsConnected - How many live gamepads are currently connected. +* @readonly +*/ +Object.defineProperty(Phaser.Gamepad.prototype, "padsConnected", { + + get: function () { + return this._rawPads.length; + } + +}); + +/** +* Gamepad #1 +* @name Phaser.Gamepad#pad1 +* @property {boolean} pad1 - Gamepad #1; +* @readonly +*/ +Object.defineProperty(Phaser.Gamepad.prototype, "pad1", { + + get: function () { + return this._gamepads[0]; + } + +}); + +/** +* Gamepad #2 +* @name Phaser.Gamepad#pad2 +* @property {boolean} pad2 - Gamepad #2 +* @readonly +*/ +Object.defineProperty(Phaser.Gamepad.prototype, "pad2", { + + get: function () { + return this._gamepads[1]; + } + +}); + +/** +* Gamepad #3 +* @name Phaser.Gamepad#pad3 +* @property {boolean} pad3 - Gamepad #3 +* @readonly +*/ +Object.defineProperty(Phaser.Gamepad.prototype, "pad3", { + + get: function () { + return this._gamepads[2]; + } + +}); + +/** +* Gamepad #4 +* @name Phaser.Gamepad#pad4 +* @property {boolean} pad4 - Gamepad #4 +* @readonly +*/ +Object.defineProperty(Phaser.Gamepad.prototype, "pad4", { + + get: function () { + return this._gamepads[3]; + } + +}); + +Phaser.Gamepad.BUTTON_0 = 0; +Phaser.Gamepad.BUTTON_1 = 1; +Phaser.Gamepad.BUTTON_2 = 2; +Phaser.Gamepad.BUTTON_3 = 3; +Phaser.Gamepad.BUTTON_4 = 4; +Phaser.Gamepad.BUTTON_5 = 5; +Phaser.Gamepad.BUTTON_6 = 6; +Phaser.Gamepad.BUTTON_7 = 7; +Phaser.Gamepad.BUTTON_8 = 8; +Phaser.Gamepad.BUTTON_9 = 9; +Phaser.Gamepad.BUTTON_10 = 10; +Phaser.Gamepad.BUTTON_11 = 11; +Phaser.Gamepad.BUTTON_12 = 12; +Phaser.Gamepad.BUTTON_13 = 13; +Phaser.Gamepad.BUTTON_14 = 14; +Phaser.Gamepad.BUTTON_15 = 15; + +Phaser.Gamepad.AXIS_0 = 0; +Phaser.Gamepad.AXIS_1 = 1; +Phaser.Gamepad.AXIS_2 = 2; +Phaser.Gamepad.AXIS_3 = 3; +Phaser.Gamepad.AXIS_4 = 4; +Phaser.Gamepad.AXIS_5 = 5; +Phaser.Gamepad.AXIS_6 = 6; +Phaser.Gamepad.AXIS_7 = 7; +Phaser.Gamepad.AXIS_8 = 8; +Phaser.Gamepad.AXIS_9 = 9; + +// Below mapping applies to XBOX 360 Wired and Wireless controller on Google Chrome (tested on Windows 7). +// - Firefox uses different map! Separate amount of buttons and axes. DPAD = axis and not a button. +// In other words - discrepancies when using gamepads. + +Phaser.Gamepad.XBOX360_A = 0; +Phaser.Gamepad.XBOX360_B = 1; +Phaser.Gamepad.XBOX360_X = 2; +Phaser.Gamepad.XBOX360_Y = 3; +Phaser.Gamepad.XBOX360_LEFT_BUMPER = 4; +Phaser.Gamepad.XBOX360_RIGHT_BUMPER = 5; +Phaser.Gamepad.XBOX360_LEFT_TRIGGER = 6; +Phaser.Gamepad.XBOX360_RIGHT_TRIGGER = 7; +Phaser.Gamepad.XBOX360_BACK = 8; +Phaser.Gamepad.XBOX360_START = 9; +Phaser.Gamepad.XBOX360_STICK_LEFT_BUTTON = 10; +Phaser.Gamepad.XBOX360_STICK_RIGHT_BUTTON = 11; + +Phaser.Gamepad.XBOX360_DPAD_LEFT = 14; +Phaser.Gamepad.XBOX360_DPAD_RIGHT = 15; +Phaser.Gamepad.XBOX360_DPAD_UP = 12; +Phaser.Gamepad.XBOX360_DPAD_DOWN = 13; + +Phaser.Gamepad.XBOX360_STICK_LEFT_X = 0; +Phaser.Gamepad.XBOX360_STICK_LEFT_Y = 1; +Phaser.Gamepad.XBOX360_STICK_RIGHT_X = 2; +Phaser.Gamepad.XBOX360_STICK_RIGHT_Y = 3; + +/** +* @author @karlmacklin +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +*/ + +/** +* @class Phaser.SinglePad +* @classdesc A single Phaser Gamepad +* @constructor +* @param {Phaser.Game} game - Current game instance. +* @param {Object} padParent - The parent Phaser.Gamepad object (all gamepads reside under this) +*/ +Phaser.SinglePad = function (game, padParent) { + + /** + * @property {Phaser.Game} game - Local reference to game. + */ + this.game = game; + + /** + * @property {Phaser.Gamepad} padParent - Main Phaser Gamepad object + */ + this._padParent = padParent; + + /** + * @property {number} index - The gamepad index as per browsers data + * @default + */ + this._index = null; + + /** + * @property {Object} _rawPad - The 'raw' gamepad data. + * @private + */ + this._rawPad = null; + + /** + * @property {boolean} _connected - Is this pad connected or not. + * @private + */ + this._connected = false; + + /** + * @property {number} _prevTimestamp - Used to check for differences between earlier polls and current state of gamepads. + * @private + */ + this._prevTimestamp = null; + + /** + * @property {Array} _rawButtons - The 'raw' button state. + * @private + */ + this._rawButtons = []; + + /** + * @property {Array} _buttons - Current Phaser state of the buttons. + * @private + */ + this._buttons = []; + + /** + * @property {Array} _axes - Current axes state. + * @private + */ + this._axes = []; + + /** + * @property {Array} _hotkeys - Hotkey buttons. + * @private + */ + this._hotkeys = []; + + /** + * @property {Object} callbackContext - The context under which the callbacks are run. + */ + this.callbackContext = this; + + /** + * @property {function} onConnectCallback - This callback is invoked every time this gamepad is connected + */ + this.onConnectCallback = null; + + /** + * @property {function} onDisconnectCallback - This callback is invoked every time this gamepad is disconnected + */ + this.onDisconnectCallback = null; + + /** + * @property {function} onDownCallback - This callback is invoked every time a button is pressed down. + */ + this.onDownCallback = null; + + /** + * @property {function} onUpCallback - This callback is invoked every time a gamepad button is released. + */ + this.onUpCallback = null; + + /** + * @property {function} onAxisCallback - This callback is invoked every time an axis is changed. + */ + this.onAxisCallback = null; + + /** + * @property {function} onFloatCallback - This callback is invoked every time a button is changed to a value where value > 0 and value < 1. + */ + this.onFloatCallback = null; + + /** + * @property {number} deadZone - Dead zone for axis feedback - within this value you won't trigger updates. + */ + this.deadZone = 0.26; + +}; + +Phaser.SinglePad.prototype = { + + /** + * Add callbacks to the this Gamepad to handle connect/disconnect/button down/button up/axis change/float value buttons + * @method Phaser.Gamepad#addCallbacks + * @param {Object} context - The context under which the callbacks are run. + * @param {Object} callbacks - Object that takes six different callbak methods: + * onConnectCallback, onDisconnectCallback, onDownCallback, onUpCallback, onAxisCallback, onFloatCallback + */ + addCallbacks: function (context, callbacks) { + + if (typeof callbacks !== 'undefined') + { + this.onConnectCallback = (typeof callbacks.onConnect === 'function') ? callbacks.onConnect : this.onConnectCallback; + this.onDisconnectCallback = (typeof callbacks.onDisconnect === 'function') ? callbacks.onDisconnect : this.onDisconnectCallback; + this.onDownCallback = (typeof callbacks.onDown === 'function') ? callbacks.onDown : this.onDownCallback; + this.onUpCallback = (typeof callbacks.onUp === 'function') ? callbacks.onUp : this.onUpCallback; + this.onAxisCallback = (typeof callbacks.onAxis === 'function') ? callbacks.onAxis : this.onAxisCallback; + this.onFloatCallback = (typeof callbacks.onFloat === 'function') ? callbacks.onFloat : this.onFloatCallback; + } + + }, + + /** + * If you need more fine-grained control over a Key you can create a new Phaser.Key object via this method. + * The Key object can then be polled, have events attached to it, etc. + * + * @method Phaser.SinglePad#addButton + * @param {number} buttonCode - The buttonCode of the button, i.e. Phaser.Gamepad.BUTTON_0 or Phaser.Gamepad.BUTTON_1 + * @return {Phaser.GamepadButton} The GamepadButton object which you can store locally and reference directly. + */ + addButton: function (buttonCode) { + + this._hotkeys[buttonCode] = new Phaser.GamepadButton(this.game, buttonCode); + return this._hotkeys[buttonCode]; + + }, + + /** + * Main update function, should be called by Phaser.Gamepad + * @method Phaser.SinglePad#pollStatus + */ + pollStatus: function () { + + if (this._rawPad.timestamp && (this._rawPad.timestamp == this._prevTimestamp)) + { + return; + } + + for (var i = 0; i < this._rawPad.buttons.length; i += 1) + { + var buttonValue = this._rawPad.buttons[i]; + + if (this._rawButtons[i] !== buttonValue) + { + if (buttonValue === 1) + { + this.processButtonDown(i, buttonValue); + } + else if (buttonValue === 0) + { + this.processButtonUp(i, buttonValue); + } + else + { + this.processButtonFloat(i, buttonValue); + } + + this._rawButtons[i] = buttonValue; + } + } + + var axes = this._rawPad.axes; + + for (var j = 0; j < axes.length; j += 1) + { + var axis = axes[j]; + + if (axis > 0 && axis > this.deadZone || axis < 0 && axis < -this.deadZone) + { + this.processAxisChange({axis: j, value: axis}); + } + else + { + this.processAxisChange({axis: j, value: 0}); + } + } + + this._prevTimestamp = this._rawPad.timestamp; + + }, + + /** + * Gamepad connect function, should be called by Phaser.Gamepad + * @param {Object} rawPad - The raw gamepad object + * @method Phaser.SinglePad#connect + */ + connect: function (rawPad) { + + var triggerCallback = !this._connected; + + this._index = rawPad.index; + this._connected = true; + this._rawPad = rawPad; + this._rawButtons = rawPad.buttons; + this._axes = rawPad.axes; + + if (triggerCallback && this._padParent.onConnectCallback) + { + this._padParent.onConnectCallback.call(this._padParent.callbackContext, this._index); + } + + if (triggerCallback && this.onConnectCallback) + { + this.onConnectCallback.call(this.callbackContext); + } + + }, + + /** + * Gamepad disconnect function, should be called by Phaser.Gamepad + * @method Phaser.SinglePad#disconnect + */ + disconnect: function () { + + var triggerCallback = this._connected; + this._connected = false; + this._rawPad = undefined; + this._rawButtons = []; + this._buttons = []; + var disconnectingIndex = this._index; + this._index = null; + + if (triggerCallback && this._padParent.onDisconnectCallback) + { + this._padParent.onDisconnectCallback.call(this._padParent.callbackContext, disconnectingIndex); + } + + if (triggerCallback && this.onDisconnectCallback) + { + this.onDisconnectCallback.call(this.callbackContext); + } + + }, + + /** + * Handles changes in axis + * @param {Object} axisState - State of the relevant axis + * @method Phaser.SinglePad#processAxisChange + */ + processAxisChange: function (axisState) { + + if (this.game.input.disabled || this.game.input.gamepad.disabled) + { + return; + } + + if (this._axes[axisState.axis] === axisState.value) + { + return; + } + + this._axes[axisState.axis] = axisState.value; + + if (this._padParent.onAxisCallback) + { + this._padParent.onAxisCallback.call(this._padParent.callbackContext, axisState, this._index); + } + + if (this.onAxisCallback) + { + this.onAxisCallback.call(this.callbackContext, axisState); + } + + }, + + /** + * Handles button down press + * @param {number} buttonCode - Which buttonCode of this button + * @param {Object} value - Button value + * @method Phaser.SinglePad#processButtonDown + */ + processButtonDown: function (buttonCode, value) { + + if (this.game.input.disabled || this.game.input.gamepad.disabled) + { + return; + } + + if (this._padParent.onDownCallback) + { + this._padParent.onDownCallback.call(this._padParent.callbackContext, buttonCode, value, this._index); + } + + if (this.onDownCallback) + { + this.onDownCallback.call(this.callbackContext, buttonCode, value); + } + + if (this._buttons[buttonCode] && this._buttons[buttonCode].isDown) + { + // Key already down and still down, so update + this._buttons[buttonCode].duration = this.game.time.now - this._buttons[buttonCode].timeDown; + } + else + { + if (!this._buttons[buttonCode]) + { + // Not used this button before, so register it + this._buttons[buttonCode] = { + isDown: true, + timeDown: this.game.time.now, + timeUp: 0, + duration: 0, + value: value + }; + } + else + { + // Button used before but freshly down + this._buttons[buttonCode].isDown = true; + this._buttons[buttonCode].timeDown = this.game.time.now; + this._buttons[buttonCode].duration = 0; + this._buttons[buttonCode].value = value; + } + } + + if (this._hotkeys[buttonCode]) + { + this._hotkeys[buttonCode].processButtonDown(value); + } + + }, + + /** + * Handles button release + * @param {number} buttonCode - Which buttonCode of this button + * @param {Object} value - Button value + * @method Phaser.SinglePad#processButtonUp + */ + processButtonUp: function (buttonCode, value) { + + if (this.game.input.disabled || this.game.input.gamepad.disabled) + { + return; + } + + if (this._padParent.onUpCallback) + { + this._padParent.onUpCallback.call(this._padParent.callbackContext, buttonCode, value, this._index); + } + + if (this.onUpCallback) + { + this.onUpCallback.call(this.callbackContext, buttonCode, value); + } + + if (this._hotkeys[buttonCode]) + { + this._hotkeys[buttonCode].processButtonUp(value); + } + + if (this._buttons[buttonCode]) + { + this._buttons[buttonCode].isDown = false; + this._buttons[buttonCode].timeUp = this.game.time.now; + this._buttons[buttonCode].value = value; + } + else + { + // Not used this button before, so register it + this._buttons[buttonCode] = { + isDown: false, + timeDown: this.game.time.now, + timeUp: this.game.time.now, + duration: 0, + value: value + }; + } + + }, + + /** + * Handles buttons with floating values (like analog buttons that acts almost like an axis but still registers like a button) + * @param {number} buttonCode - Which buttonCode of this button + * @param {Object} value - Button value (will range somewhere between 0 and 1, but not specifically 0 or 1. + * @method Phaser.SinglePad#processButtonFloat + */ + processButtonFloat: function (buttonCode, value) { + + if (this.game.input.disabled || this.game.input.gamepad.disabled) + { + return; + } + + if (this._padParent.onFloatCallback) + { + this._padParent.onFloatCallback.call(this._padParent.callbackContext, buttonCode, value, this._index); + } + + if (this.onFloatCallback) + { + this.onFloatCallback.call(this.callbackContext, buttonCode, value); + } + + if (!this._buttons[buttonCode]) + { + // Not used this button before, so register it + this._buttons[buttonCode] = { value: value }; + } + else + { + // Button used before but freshly down + this._buttons[buttonCode].value = value; + } + + if (this._hotkeys[buttonCode]) + { + this._hotkeys[buttonCode].processButtonFloat(value); + } + + }, + + /** + * Returns value of requested axis + * @method Phaser.SinglePad#isDown + * @param {number} axisCode - The index of the axis to check + * @return {number} Axis value if available otherwise false + */ + axis: function (axisCode) { + + if (this._axes[axisCode]) + { + return this._axes[axisCode]; + } + + return false; + + }, + + /** + * Returns true if the button is currently pressed down. + * @method Phaser.SinglePad#isDown + * @param {number} buttonCode - The buttonCode of the key to check. + * @return {boolean} True if the key is currently down. + */ + isDown: function (buttonCode) { + + if (this._buttons[buttonCode]) + { + return this._buttons[buttonCode].isDown; + } + + return false; + + }, + + /** + * Returns the "just released" state of a button from this gamepad. Just released is considered as being true if the button was released within the duration given (default 250ms). + * @method Phaser.SinglePad#justPressed + * @param {number} buttonCode - The buttonCode of the button to check for. + * @param {number} [duration=250] - The duration below which the button is considered as being just released. + * @return {boolean} True if the button is just released otherwise false. + */ + justReleased: function (buttonCode, duration) { + + if (typeof duration === "undefined") { duration = 250; } + + return (this._buttons[buttonCode] && this._buttons[buttonCode].isDown === false && (this.game.time.now - this._buttons[buttonCode].timeUp < duration)); + + }, + + /** + * Returns the "just pressed" state of a button from this gamepad. Just pressed is considered true if the button was pressed down within the duration given (default 250ms). + * @method Phaser.SinglePad#justPressed + * @param {number} buttonCode - The buttonCode of the button to check for. + * @param {number} [duration=250] - The duration below which the button is considered as being just pressed. + * @return {boolean} True if the button is just pressed otherwise false. + */ + justPressed: function (buttonCode, duration) { + + if (typeof duration === "undefined") { duration = 250; } + + return (this._buttons[buttonCode] && this._buttons[buttonCode].isDown && this._buttons[buttonCode].duration < duration); + + }, + + /** + * Returns the value of a gamepad button. Intended mainly for cases when you have floating button values, for example + * analog trigger buttons on the XBOX 360 controller + * @method Phaser.SinglePad#buttonValue + * @param {number} buttonCode - The buttonCode of the button to check. + * @return {boolean} Button value if available otherwise false. + */ + buttonValue: function (buttonCode) { + + if (this._buttons[buttonCode]) + { + return this._buttons[buttonCode].value; + } + + return false; + + }, + + /** + * Reset all buttons/axes of this gamepad + * @method Phaser.SinglePad#reset + */ + reset: function () { + + for (var i = 0; i < this._buttons.length; i++) + { + this._buttons[i] = 0; + } + + for (var j = 0; j < this._axes.length; j++) + { + this._axes[j] = 0; + } + + } + +}; + +Phaser.SinglePad.prototype.constructor = Phaser.SinglePad; + +/** + * Whether or not this particular gamepad is connected or not. + * @name Phaser.SinglePad#connected + * @property {boolean} connected - Whether or not this particular gamepad is connected or not. + * @readonly + */ +Object.defineProperty(Phaser.SinglePad.prototype, "connected", { + + get: function () { + return this._connected; + } + +}); + +/** + * Gamepad index as per browser data + * @name Phaser.SinglePad#index + * @property {number} index - The gamepad index, used to identify specific gamepads in the browser + * @readonly + */ +Object.defineProperty(Phaser.SinglePad.prototype, "index", { + + get: function () { + return this._index; + } + +}); + +/** +* @author @karlmacklin +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +*/ + +/** +* @class Phaser.GamepadButton +* @classdesc If you need more fine-grained control over the handling of specific buttons you can create and use Phaser.GamepadButton objects. +* @constructor +* @param {Phaser.Game} game - Current game instance. +* @param {number} buttoncode - The button code this GamepadButton is responsible for. +*/ +Phaser.GamepadButton = function (game, buttoncode) { + + /** + * @property {Phaser.Game} game - A reference to the currently running game. + */ + this.game = game; + + /** + * @property {boolean} isDown - The "down" state of the button. + * @default + */ + this.isDown = false; + + /** + * @property {boolean} isUp - The "up" state of the button. + * @default + */ + this.isUp = false; + + /** + * @property {number} timeDown - The timestamp when the button was last pressed down. + * @default + */ + this.timeDown = 0; + + /** + * If the button is down this value holds the duration of that button press and is constantly updated. + * If the button is up it holds the duration of the previous down session. + * @property {number} duration - The number of milliseconds this button has been held down for. + * @default + */ + this.duration = 0; + + /** + * @property {number} timeUp - The timestamp when the button was last released. + * @default + */ + this.timeUp = 0; + + /** + * @property {number} repeats - If a button is held down this holds down the number of times the button has 'repeated'. + * @default + */ + this.repeats = 0; + + /** + * @property {number} value - Button value. Mainly useful for checking analog buttons (like shoulder triggers) + * @default + */ + this.value = 0; + + /** + * @property {number} buttonCode - The buttoncode of this button. + */ + this.buttonCode = buttoncode; + + /** + * @property {Phaser.Signal} onDown - This Signal is dispatched every time this GamepadButton is pressed down. It is only dispatched once (until the button is released again). + */ + this.onDown = new Phaser.Signal(); + + /** + * @property {Phaser.Signal} onUp - This Signal is dispatched every time this GamepadButton is pressed down. It is only dispatched once (until the button is released again). + */ + this.onUp = new Phaser.Signal(); + + /** + * @property {Phaser.Signal} onFloat - This Signal is dispatched every time this GamepadButton changes floating value (between (but not exactly) 0 and 1) + */ + this.onFloat = new Phaser.Signal(); + +}; + +Phaser.GamepadButton.prototype = { + + /** + * Called automatically by Phaser.SinglePad. + * @method Phaser.GamepadButton#processButtonDown + * @param {Object} value - Button value + * @protected + */ + processButtonDown: function (value) { + + if (this.isDown) + { + this.duration = this.game.time.now - this.timeDown; + this.repeats++; + } + else + { + this.isDown = true; + this.isUp = false; + this.timeDown = this.game.time.now; + this.duration = 0; + this.repeats = 0; + this.value = value; + + this.onDown.dispatch(this, value); + } + + }, + + /** + * Called automatically by Phaser.SinglePad. + * @method Phaser.GamepadButton#processButtonUp + * @param {Object} value - Button value + * @protected + */ + processButtonUp: function (value) { + + this.isDown = false; + this.isUp = true; + this.timeUp = this.game.time.now; + this.value = value; + + this.onUp.dispatch(this, value); + + }, + + /** + * Called automatically by Phaser.Gamepad. + * @method Phaser.GamepadButton#processButtonFloat + * @param {Object} value - Button value + * @protected + */ + processButtonFloat: function (value) { + + this.value = value; + this.onFloat.dispatch(this, value); + + }, + + /** + * Returns the "just pressed" state of this button. Just pressed is considered true if the button was pressed down within the duration given (default 250ms). + * @method Phaser.GamepadButton#justPressed + * @param {number} [duration=250] - The duration below which the button is considered as being just pressed. + * @return {boolean} True if the button is just pressed otherwise false. + */ + justPressed: function (duration) { + + if (typeof duration === "undefined") { duration = 250; } + + return (this.isDown && this.duration < duration); + + }, + + /** + * Returns the "just released" state of this button. Just released is considered as being true if the button was released within the duration given (default 250ms). + * @method Phaser.GamepadButton#justPressed + * @param {number} [duration=250] - The duration below which the button is considered as being just released. + * @return {boolean} True if the button is just pressed otherwise false. + */ + justReleased: function (duration) { + + if (typeof duration === "undefined") { duration = 250; } + + return (this.isDown === false && (this.game.time.now - this.timeUp < duration)); + } + +}; + +Phaser.GamepadButton.prototype.constructor = Phaser.GamepadButton; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -17396,6 +19247,9 @@ Phaser.Events.prototype = { } }; + +Phaser.Events.prototype.constructor = Phaser.Events; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -17445,15 +19299,19 @@ Phaser.GameObjectFactory.prototype = { * @param {number} y - Y position of the new sprite. * @param {string|Phaser.RenderTexture|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture. * @param {string|number} [frame] - If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name. + * @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group. * @returns {Phaser.Sprite} the newly created sprite object. */ - sprite: function (x, y, key, frame) { + sprite: function (x, y, key, frame, group) { - return this.world.create(x, y, key, frame); + if (typeof group === 'undefined') { group = this.world; } + + return group.create(x, y, key, frame); }, /** + * DEPRECATED - will be removed in Phaser 1.2 * Create a new Sprite with specific position and sprite sheet key that will automatically be added as a child of the given parent. * * @method Phaser.GameObjectFactory#child @@ -17487,8 +19345,8 @@ Phaser.GameObjectFactory.prototype = { * A Group is a container for display objects that allows for fast pooling, recycling and collision checks. * * @method Phaser.GameObjectFactory#group - * @param {*} parent - The parent Group or DisplayObjectContainer that will hold this group, if any. - * @param {string} [name=group] - A name for this Group. Not used internally but useful for debugging. + * @param {any} parent - The parent Group or DisplayObjectContainer that will hold this group, if any. + * @param {string} [name='group'] - A name for this Group. Not used internally but useful for debugging. * @return {Phaser.Group} The newly created group. */ group: function (parent, name) { @@ -17498,7 +19356,7 @@ Phaser.GameObjectFactory.prototype = { }, /** - * Creates a new instance of the Sound class. + * Creates a new Sound object. * * @method Phaser.GameObjectFactory#audio * @param {string} key - The Game.cache key of the sound that this object will use. @@ -17514,7 +19372,23 @@ Phaser.GameObjectFactory.prototype = { }, /** - * Creates a new TileSprite. + * Creates a new Sound object. + * + * @method Phaser.GameObjectFactory#sound + * @param {string} key - The Game.cache key of the sound that this object will use. + * @param {number} [volume=1] - The volume at which the sound will be played. + * @param {boolean} [loop=false] - Whether or not the sound will loop. + * @param {boolean} [connect=true] - Controls if the created Sound object will connect to the master gainNode of the SoundManager when running under WebAudio. + * @return {Phaser.Sound} The newly created text object. + */ + sound: function (key, volume, loop, connect) { + + return this.game.sound.add(key, volume, loop, connect); + + }, + + /** + * Creates a new TileSprite object. * * @method Phaser.GameObjectFactory#tileSprite * @param {number} x - X position of the new tileSprite. @@ -17522,33 +19396,38 @@ Phaser.GameObjectFactory.prototype = { * @param {number} width - the width of the tilesprite. * @param {number} height - the height of the tilesprite. * @param {string|Phaser.RenderTexture|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture. - * @param {string|number} frame - If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index. + * @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group. * @return {Phaser.TileSprite} The newly created tileSprite object. */ - tileSprite: function (x, y, width, height, key, frame) { + tileSprite: function (x, y, width, height, key, group) { - return this.world.add(new Phaser.TileSprite(this.game, x, y, width, height, key, frame)); + if (typeof group === 'undefined') { group = this.world; } + + return group.add(new Phaser.TileSprite(this.game, x, y, width, height, key)); }, /** - * Creates a new Text. + * Creates a new Text object. * * @method Phaser.GameObjectFactory#text * @param {number} x - X position of the new text object. * @param {number} y - Y position of the new text object. * @param {string} text - The actual text that will be written. * @param {object} style - The style object containing style attributes like font, font size , etc. + * @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group. * @return {Phaser.Text} The newly created text object. */ - text: function (x, y, text, style) { + text: function (x, y, text, style, group) { - return this.world.add(new Phaser.Text(this.game, x, y, text, style)); + if (typeof group === 'undefined') { group = this.world; } + + return group.add(new Phaser.Text(this.game, x, y, text, style)); }, /** - * Creates a new Button object. + * Creates a new Button object. * * @method Phaser.GameObjectFactory#button * @param {number} [x] X position of the new button object. @@ -17559,25 +19438,32 @@ Phaser.GameObjectFactory.prototype = { * @param {string|number} [overFrame] This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name. * @param {string|number} [outFrame] This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name. * @param {string|number} [downFrame] This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name. + * @param {string|number} [upFrame] This is the frame or frameName that will be set when this button is in an up state. Give either a number to use a frame ID or a string for a frame name. + * @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group. * @return {Phaser.Button} The newly created button object. */ - button: function (x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) { + button: function (x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame, group) { - return this.world.add(new Phaser.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame)); + if (typeof group === 'undefined') { group = this.world; } + + return group.add(new Phaser.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame)); }, /** - * Creates a new Graphics object. + * Creates a new Graphics object. * * @method Phaser.GameObjectFactory#graphics * @param {number} x - X position of the new graphics object. * @param {number} y - Y position of the new graphics object. + * @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group. * @return {Phaser.Graphics} The newly created graphics object. */ - graphics: function (x, y) { + graphics: function (x, y, group) { - return this.world.add(new Phaser.Graphics(this.game, x, y)); + if (typeof group === 'undefined') { group = this.world; } + + return group.add(new Phaser.Graphics(this.game, x, y)); }, @@ -17599,16 +19485,19 @@ Phaser.GameObjectFactory.prototype = { }, /** - * * Create a new BitmapText. + * * Create a new BitmapText object. * * @method Phaser.GameObjectFactory#bitmapText * @param {number} x - X position of the new bitmapText object. * @param {number} y - Y position of the new bitmapText object. * @param {string} text - The actual text that will be written. * @param {object} style - The style object containing style attributes like font, font size , etc. + * @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group. * @return {Phaser.BitmapText} The newly created bitmapText object. */ - bitmapText: function (x, y, text, style) { + bitmapText: function (x, y, text, style, group) { + + if (typeof group === 'undefined') { group = this.world; } return this.world.add(new Phaser.BitmapText(this.game, x, y, text, style)); @@ -17618,41 +19507,13 @@ Phaser.GameObjectFactory.prototype = { * Creates a new Tilemap object. * * @method Phaser.GameObjectFactory#tilemap - * @param {string} key - Asset key for the JSON file. + * @param {string} key - Asset key for the JSON or CSV map data in the cache. + * @param {object|string} tilesets - An object mapping Cache.tileset keys with the tileset names in the JSON file. If a string is provided that will be used. * @return {Phaser.Tilemap} The newly created tilemap object. */ - tilemap: function (key) { + tilemap: function (key, tilesets) { - return new Phaser.Tilemap(this.game, key); - - }, - - /** - * Creates a new Tileset object. - * - * @method Phaser.GameObjectFactory#tileset - * @param {string} key - The image key as defined in the Game.Cache to use as the tileset. - * @return {Phaser.Tileset} The newly created tileset object. - */ - tileset: function (key) { - - return this.game.cache.getTileset(key); - - }, - - /** - * Creates a new Tilemap Layer object. - * - * @method Phaser.GameObjectFactory#tilemapLayer - * @param {number} x - X position of the new tilemapLayer. - * @param {number} y - Y position of the new tilemapLayer. - * @param {number} width - the width of the tilemapLayer. - * @param {number} height - the height of the tilemapLayer. - * @return {Phaser.TilemapLayer} The newly created tilemaplayer object. - */ - tilemapLayer: function (x, y, width, height, tileset, tilemap, layer) { - - return this.world.add(new Phaser.TilemapLayer(this.game, x, y, width, height, tileset, tilemap, layer)); + return new Phaser.Tilemap(this.game, key, tilesets); }, @@ -17676,7 +19537,7 @@ Phaser.GameObjectFactory.prototype = { }, /** - * A BitmapData object which can be manipulated and drawn to like a traditional Canvas object and used to texture Sprites. + * Experimental: A BitmapData object which can be manipulated and drawn to like a traditional Canvas object and used to texture Sprites. * * @method Phaser.GameObjectFactory#bitmapData * @param {number} [width=256] - The width of the BitmapData in pixels. @@ -17710,6 +19571,9 @@ Phaser.GameObjectFactory.prototype = { } }; + +Phaser.GameObjectFactory.prototype.constructor = Phaser.GameObjectFactory; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -18669,7 +20533,9 @@ Phaser.BitmapData.prototype = { } -} +}; + +Phaser.BitmapData.prototype.constructor = Phaser.BitmapData; // EaselJS Tiny API emulation @@ -19185,7 +21051,7 @@ Phaser.Sprite = function (game, x, y, key, frame) { /** * @property {Phaser.Point} cameraOffset - If this Sprite is fixed to the camera then use this Point to specify how far away from the Camera x/y it's rendered. */ - this.cameraOffset = new Phaser.Point(); + this.cameraOffset = new Phaser.Point(x, y); /** * You can crop the Sprites texture by modifying the crop properties. For example crop.width = 50 would set the Sprite to only render 50px wide. @@ -19204,6 +21070,11 @@ Phaser.Sprite = function (game, x, y, key, frame) { this.updateCache(); this.updateBounds(); + /** + * @property {PIXI.Point} pivot - The pivot point of the displayObject that it rotates around. + */ + + }; // Needed to keep the PIXI.Sprite constructor in the prototype chain (as the core pixi renderer uses an instanceof check sadly) @@ -19603,8 +21474,17 @@ Phaser.Sprite.prototype.loadTexture = function (key, frame) { */ Phaser.Sprite.prototype.centerOn = function(x, y) { - this.x = x + (this.x - this.center.x); - this.y = y + (this.y - this.center.y); + if (this.fixedToCamera) + { + this.cameraOffset.x = x + (this.cameraOffset.x - this.center.x); + this.cameraOffset.y = y + (this.cameraOffset.y - this.center.y); + } + else + { + this.x = x + (this.x - this.center.x); + this.y = y + (this.y - this.center.y); + } + return this; }; @@ -19671,6 +21551,11 @@ Phaser.Sprite.prototype.kill = function() { */ Phaser.Sprite.prototype.destroy = function() { + if (this.filters) + { + this.filters = null; + } + if (this.group) { this.group.remove(this); @@ -19932,8 +21817,6 @@ Object.defineProperty(Phaser.Sprite.prototype, "inputEnabled", { set: function (value) { - console.log('inputEnabled', value, this.input); - if (value) { if (this.input.enabled === false) @@ -19970,18 +21853,16 @@ Object.defineProperty(Phaser.Sprite.prototype, "inputEnabled", { * @param {number} width - the width of the tilesprite. * @param {number} height - the height of the tilesprite. * @param {string|Phaser.RenderTexture|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture. -* @param {string|number} frame - If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index. */ -Phaser.TileSprite = function (game, x, y, width, height, key, frame) { +Phaser.TileSprite = function (game, x, y, width, height, key) { x = x || 0; y = y || 0; width = width || 256; height = height || 256; key = key || null; - frame = frame || null; - Phaser.Sprite.call(this, game, x, y, key, frame); + Phaser.Sprite.call(this, game, x, y, key); /** * @property {PIXI.Texture} texture - The texture that the sprite renders with. @@ -20006,11 +21887,113 @@ Phaser.TileSprite = function (game, x, y, width, height, key, frame) { */ this.tilePosition = new Phaser.Point(0, 0); + this.body.width = width; + this.body.height = height; + }; Phaser.TileSprite.prototype = Phaser.Utils.extend(true, PIXI.TilingSprite.prototype, Phaser.Sprite.prototype); Phaser.TileSprite.prototype.constructor = Phaser.TileSprite; +/** +* Indicates the rotation of the Sprite, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. +* Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement player.angle = 450 is the same as player.angle = 90. +* If you wish to work in radians instead of degrees use the property Sprite.rotation instead. +* @name Phaser.TileSprite#angle +* @property {number} angle - Gets or sets the Sprites angle of rotation in degrees. +*/ +Object.defineProperty(Phaser.TileSprite.prototype, 'angle', { + + get: function() { + return Phaser.Math.wrapAngle(Phaser.Math.radToDeg(this.rotation)); + }, + + set: function(value) { + this.rotation = Phaser.Math.degToRad(Phaser.Math.wrapAngle(value)); + } + +}); + +/** +* @name Phaser.TileSprite#frame +* @property {number} frame - Gets or sets the current frame index and updates the Texture Cache for display. +*/ +Object.defineProperty(Phaser.TileSprite.prototype, "frame", { + + get: function () { + return this.animations.frame; + }, + + set: function (value) { + this.animations.frame = value; + } + +}); + +/** +* @name Phaser.TileSprite#frameName +* @property {string} frameName - Gets or sets the current frame name and updates the Texture Cache for display. +*/ +Object.defineProperty(Phaser.TileSprite.prototype, "frameName", { + + get: function () { + return this.animations.frameName; + }, + + set: function (value) { + this.animations.frameName = value; + } + +}); + +/** +* @name Phaser.TileSprite#inCamera +* @property {boolean} inCamera - Is this sprite visible to the camera or not? +* @readonly +*/ +Object.defineProperty(Phaser.TileSprite.prototype, "inCamera", { + + get: function () { + return this._cache.cameraVisible; + } + +}); + +/** +* By default a Sprite won't process any input events at all. By setting inputEnabled to true the Phaser.InputHandler is +* activated for this Sprite instance and it will then start to process click/touch events and more. +* +* @name Phaser.TileSprite#inputEnabled +* @property {boolean} inputEnabled - Set to true to allow this Sprite to receive input events, otherwise false. +*/ +Object.defineProperty(Phaser.TileSprite.prototype, "inputEnabled", { + + get: function () { + + return (this.input.enabled); + + }, + + set: function (value) { + + if (value) + { + if (this.input.enabled === false) + { + this.input.start(); + } + } + else + { + if (this.input.enabled) + { + this.input.stop(); + } + } + + } + +}); /** * @author Richard Davey @@ -20019,7 +22002,7 @@ Phaser.TileSprite.prototype.constructor = Phaser.TileSprite; */ /** -* Create a new Text. +* Create a new `Text` object. * @class Phaser.Text * @constructor * @param {Phaser.Game} game - Current game instance. @@ -20104,6 +22087,18 @@ Phaser.Text = function (game, x, y, text, style) { */ this.scale = new Phaser.Point(1, 1); + /** + * An object that is fixed to the camera ignores the position of any ancestors in the display list and uses its x/y coordinates as offsets from the top left of the camera. + * @property {boolean} fixedToCamera - Fixes this object to the Camera. + * @default + */ + this.fixedToCamera = false; + + /** + * @property {Phaser.Point} cameraOffset - If this object is fixed to the camera then use this Point to specify how far away from the Camera x/y it's rendered. + */ + this.cameraOffset = new Phaser.Point(); + /** * @property {object} _cache - A mini cache for storing all of the calculated values. * @private @@ -20155,6 +22150,12 @@ Phaser.Text.prototype.update = function() { return; } + if (this.fixedToCamera) + { + this.x = this.game.camera.view.x + this.cameraOffset.x; + this.y = this.game.camera.view.y + this.cameraOffset.y; + } + this._cache.dirty = false; this._cache.x = this.x; @@ -20418,11 +22419,6 @@ Phaser.BitmapText = function (game, x, y, text, style) { this._cache.x = this.x; this._cache.y = this.y; - /** - * @property {boolean} renderable - A renderable object will be rendered to the context each frame. - */ - this.renderable = true; - }; Phaser.BitmapText.prototype = Object.create(PIXI.BitmapText.prototype); @@ -20451,8 +22447,8 @@ Phaser.BitmapText.prototype.update = function() { this._cache.dirty = true; } - this.pivot.x = this.anchor.x*this.width; - this.pivot.y = this.anchor.y*this.height; + this.pivot.x = this.anchor.x * this.width; + this.pivot.y = this.anchor.y * this.height; } @@ -20556,16 +22552,17 @@ Object.defineProperty(Phaser.BitmapText.prototype, 'y', { * @constructor * * @param {Phaser.Game} game Current game instance. -* @param {number} [x] - X position of the Button. -* @param {number} [y] - Y position of the Button. +* @param {number} [x=0] - X position of the Button. +* @param {number} [y=0] - Y position of the Button. * @param {string} [key] - The image key as defined in the Game.Cache to use as the texture for this Button. * @param {function} [callback] - The function to call when this Button is pressed. * @param {object} [callbackContext] - The context in which the callback will be called (usually 'this'). * @param {string|number} [overFrame] - This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name. * @param {string|number} [outFrame] - This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name. * @param {string|number} [downFrame] - This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name. +* @param {string|number} [upFrame] - This is the frame or frameName that will be set when this button is in an up state. Give either a number to use a frame ID or a string for a frame name. */ -Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) { +Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame) { x = x || 0; y = y || 0; @@ -20600,7 +22597,7 @@ Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame, * @default */ this._onDownFrameName = null; - + /** * @property {string} _onUpFrameName - Internal variable. * @private @@ -20628,7 +22625,7 @@ Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame, * @default */ this._onDownFrameID = null; - + /** * @property {number} _onUpFrameID - Internal variable. * @private @@ -20710,13 +22707,13 @@ Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame, this.freezeFrames = false; /** - * When the Button is clicked you can optionally force the state to "out". + * When the Button is touched / clicked and then released you can force it to enter a state of "out" instead of "up". * @property {boolean} forceOut * @default */ - this.forceOut = true; + this.forceOut = false; - this.setFrames(overFrame, outFrame, downFrame); + this.setFrames(overFrame, outFrame, downFrame, upFrame); if (callback !== null) { @@ -20738,15 +22735,38 @@ Phaser.Button.prototype = Phaser.Utils.extend(true, Phaser.Button.prototype, Pha Phaser.Button.prototype.constructor = Phaser.Button; /** -* Used to manually set the frames that will be used for the different states of the button -* exactly like setting them in the constructor. +* Clears all of the frames set on this Button. +* +* @method Phaser.Button.prototype.clearFrames +*/ +Phaser.Button.prototype.clearFrames = function () { + + this._onOverFrameName = null; + this._onOverFrameID = null; + + this._onOutFrameName = null; + this._onOutFrameID = null; + + this._onDownFrameName = null; + this._onDownFrameID = null; + + this._onUpFrameName = null; + this._onUpFrameID = null; + +} + +/** +* Used to manually set the frames that will be used for the different states of the Button. * * @method Phaser.Button.prototype.setFrames * @param {string|number} [overFrame] - This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name. * @param {string|number} [outFrame] - This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name. * @param {string|number} [downFrame] - This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name. +* @param {string|number} [upFrame] - This is the frame or frameName that will be set when this button is in an up state. Give either a number to use a frame ID or a string for a frame name. */ -Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) { +Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame, upFrame) { + + this.clearFrames(); if (overFrame !== null) { @@ -20775,7 +22795,6 @@ Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) { if (typeof outFrame === 'string') { this._onOutFrameName = outFrame; - this._onUpFrameName = outFrame; if (this.input.pointerOver() === false) { @@ -20785,7 +22804,6 @@ Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) { else { this._onOutFrameID = outFrame; - this._onUpFrameID = outFrame; if (this.input.pointerOver() === false) { @@ -20816,6 +22834,28 @@ Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) { } } + if (upFrame !== null) + { + if (typeof upFrame === 'string') + { + this._onUpFrameName = upFrame; + + if (this.input.pointerUp()) + { + this.frameName = upFrame; + } + } + else + { + this._onUpFrameID = upFrame; + + if (this.input.pointerUp()) + { + this.frame = upFrame; + } + } + } + }; /** @@ -20837,8 +22877,8 @@ Phaser.Button.prototype.setSounds = function (overSound, overMarker, downSound, this.setOverSound(overSound, overMarker); this.setOutSound(outSound, outMarker); - this.setUpSound(upSound, upMarker); this.setDownSound(downSound, downMarker); + this.setUpSound(upSound, upMarker); } @@ -20891,31 +22931,7 @@ Phaser.Button.prototype.setOutSound = function (sound, marker) { } /** -* The Sound to be played when a Pointer clicks on this Button. -* -* @method Phaser.Button.prototype.setUpSound -* @param {Phaser.Sound} sound - The Sound that will be played. -* @param {string} [marker] - A Sound Marker that will be used in the playback. -*/ -Phaser.Button.prototype.setUpSound = function (sound, marker) { - - this.onUpSound = null; - this.onUpSoundMarker = ''; - - if (sound instanceof Phaser.Sound) - { - this.onUpSound = sound; - } - - if (typeof marker === 'string') - { - this.onUpSoundMarker = marker; - } - -} - -/** -* The Sound to be played when a Pointer clicks on this Button. +* The Sound to be played when a Pointer presses down on this Button. * * @method Phaser.Button.prototype.setDownSound * @param {Phaser.Sound} sound - The Sound that will be played. @@ -20938,25 +22954,43 @@ Phaser.Button.prototype.setDownSound = function (sound, marker) { } +/** +* The Sound to be played when a Pointer has pressed down and is released from this Button. +* +* @method Phaser.Button.prototype.setUpSound +* @param {Phaser.Sound} sound - The Sound that will be played. +* @param {string} [marker] - A Sound Marker that will be used in the playback. +*/ +Phaser.Button.prototype.setUpSound = function (sound, marker) { + + this.onUpSound = null; + this.onUpSoundMarker = ''; + + if (sound instanceof Phaser.Sound) + { + this.onUpSound = sound; + } + + if (typeof marker === 'string') + { + this.onUpSoundMarker = marker; + } + +} + /** * Internal function that handles input events. * * @protected * @method Phaser.Button.prototype.onInputOverHandler +* @param {Phaser.Button} sprite - The Button that the event occured on. * @param {Phaser.Pointer} pointer - The Pointer that activated the Button. */ -Phaser.Button.prototype.onInputOverHandler = function (pointer) { +Phaser.Button.prototype.onInputOverHandler = function (sprite, pointer) { if (this.freezeFrames === false) { - if (this._onOverFrameName != null) - { - this.frameName = this._onOverFrameName; - } - else if (this._onOverFrameID != null) - { - this.frame = this._onOverFrameID; - } + this.setState(1); } if (this.onOverSound) @@ -20975,20 +23009,14 @@ Phaser.Button.prototype.onInputOverHandler = function (pointer) { * * @protected * @method Phaser.Button.prototype.onInputOverHandler +* @param {Phaser.Button} sprite - The Button that the event occured on. * @param {Phaser.Pointer} pointer - The Pointer that activated the Button. */ -Phaser.Button.prototype.onInputOutHandler = function (pointer) { +Phaser.Button.prototype.onInputOutHandler = function (sprite, pointer) { if (this.freezeFrames === false) { - if (this._onOutFrameName != null) - { - this.frameName = this._onOutFrameName; - } - else if (this._onOutFrameID != null) - { - this.frame = this._onOutFrameID; - } + this.setState(2); } if (this.onOutSound) @@ -21007,20 +23035,14 @@ Phaser.Button.prototype.onInputOutHandler = function (pointer) { * * @protected * @method Phaser.Button.prototype.onInputOverHandler +* @param {Phaser.Button} sprite - The Button that the event occured on. * @param {Phaser.Pointer} pointer - The Pointer that activated the Button. */ -Phaser.Button.prototype.onInputDownHandler = function (pointer) { +Phaser.Button.prototype.onInputDownHandler = function (sprite, pointer) { if (this.freezeFrames === false) { - if (this._onDownFrameName != null) - { - this.frameName = this._onDownFrameName; - } - else if (this._onDownFrameID != null) - { - this.frame = this._onDownFrameID; - } + this.setState(3); } if (this.onDownSound) @@ -21039,29 +23061,76 @@ Phaser.Button.prototype.onInputDownHandler = function (pointer) { * * @protected * @method Phaser.Button.prototype.onInputOverHandler +* @param {Phaser.Button} sprite - The Button that the event occured on. * @param {Phaser.Pointer} pointer - The Pointer that activated the Button. */ -Phaser.Button.prototype.onInputUpHandler = function (pointer) { - - if (this.freezeFrames === false) - { - if (this._onUpFrameName != null) - { - this.frameName = this._onUpFrameName; - } - else if (this._onUpFrameID != null) - { - this.frame = this._onUpFrameID; - } - } +Phaser.Button.prototype.onInputUpHandler = function (sprite, pointer, isOver) { if (this.onUpSound) { this.onUpSound.play(this.onUpSoundMarker); } - if (this.forceOut && this.freezeFrames === false) + if (this.onInputUp) { + this.onInputUp.dispatch(this, pointer, isOver); + } + + if (this.freezeFrames) + { + return; + } + + if (this.forceOut) + { + // Button should be forced to the Out frame when released. + this.setState(2); + } + else + { + if (this._onUpFrameName || this._onUpFrameID) + { + this.setState(4); + } + else + { + if (isOver) + { + this.setState(1); + } + else + { + this.setState(2); + } + } + } + +}; + +/** +* Internal function that handles Button state changes. +* +* @protected +* @method Phaser.Button.prototype.setState +* @param {number} newState - The new State of the Button. +*/ +Phaser.Button.prototype.setState = function (newState) { + + if (newState === 1) + { + // Over + if (this._onOverFrameName != null) + { + this.frameName = this._onOverFrameName; + } + else if (this._onOverFrameID != null) + { + this.frame = this._onOverFrameID; + } + } + else if (newState === 2) + { + // Out if (this._onOutFrameName != null) { this.frameName = this._onOutFrameName; @@ -21071,10 +23140,29 @@ Phaser.Button.prototype.onInputUpHandler = function (pointer) { this.frame = this._onOutFrameID; } } - - if (this.onInputUp) + else if (newState === 3) { - this.onInputUp.dispatch(this, pointer); + // Down + if (this._onDownFrameName != null) + { + this.frameName = this._onDownFrameName; + } + else if (this._onDownFrameID != null) + { + this.frame = this._onDownFrameID; + } + } + else if (newState === 4) + { + // Up + if (this._onUpFrameName != null) + { + this.frameName = this._onUpFrameName; + } + else if (this._onUpFrameID != null) + { + this.frame = this._onUpFrameID; + } } }; @@ -21257,16 +23345,19 @@ Phaser.RenderTexture.prototype.constructor = PIXI.RenderTexture; /** * This function will draw the display object to the texture. If the display object is a Group or has children it will * draw all children as well. -* -* @method render +* +* @method Phaser.RenderTexture#render +* @memberof Phaser.RenderTexture * @param {DisplayObject} displayObject - The display object to render this texture on. * @param {Phaser.Point} [position] - Where to draw the display object. * @param {boolean} [clear=false] - If true the texture will be cleared before the displayObject is drawn. +* @param {boolean} [renderHidden=false] - If true displayObjects that have their visible property set to false will still be rendered. */ -Phaser.RenderTexture.prototype.render = function(displayObject, position, clear) { +Phaser.RenderTexture.prototype.render = function(displayObject, position, clear, renderHidden) { if (typeof position === 'undefined') { position = false; } if (typeof clear === 'undefined') { clear = false; } + if (typeof renderHidden === 'undefined') { renderHidden = false; } if (displayObject instanceof Phaser.Group) { @@ -21275,11 +23366,11 @@ Phaser.RenderTexture.prototype.render = function(displayObject, position, clear) if (PIXI.gl) { - this.renderWebGL(displayObject, position, clear); + this.renderWebGL(displayObject, position, clear, renderHidden); } else { - this.renderCanvas(displayObject, position, clear); + this.renderCanvas(displayObject, position, clear, renderHidden); } } @@ -21288,29 +23379,32 @@ Phaser.RenderTexture.prototype.render = function(displayObject, position, clear) * This function will draw the display object to the texture at the given x/y coordinates. * If the display object is a Group or has children it will draw all children as well. * -* @method renderXY +* @method Phaser.RenderTexture#renderXY +* @memberof Phaser.RenderTexture * @param {DisplayObject} displayObject - The display object to render this texture on. * @param {number} x - The x coordinate to draw the display object at. * @param {number} y - The y coordinate to draw the display object at. * @param {boolean} [clear=false] - If true the texture will be cleared before the displayObject is drawn. +* @param {boolean} [renderHidden=false] - If true displayObjects that have their visible property set to false will still be rendered. */ -Phaser.RenderTexture.prototype.renderXY = function(displayObject, x, y, clear) { +Phaser.RenderTexture.prototype.renderXY = function(displayObject, x, y, clear, renderHidden) { this._tempPoint.x = x; this._tempPoint.y = y; - this.render(displayObject, this._tempPoint, clear); + this.render(displayObject, this._tempPoint, clear, renderHidden); } /** - * Initializes the webgl data for this texture - * - * @method initWebGL - * @private - */ -Phaser.RenderTexture.prototype.initWebGL = function() -{ +* Initializes the webgl data for this texture +* +* @method Phaser.RenderTexture#initWebGL +* @memberof Phaser.RenderTexture +* @private +*/ +Phaser.RenderTexture.prototype.initWebGL = function() { + var gl = PIXI.gl; this.glFramebuffer = gl.createFramebuffer(); @@ -21346,7 +23440,12 @@ Phaser.RenderTexture.prototype.initWebGL = function() // this.render = this.renderWebGL; } - +/** +* Resizes the RenderTexture. +* +* @method Phaser.RenderTexture#resize +* @memberof Phaser.RenderTexture +*/ Phaser.RenderTexture.prototype.resize = function(width, height) { @@ -21372,11 +23471,12 @@ Phaser.RenderTexture.prototype.resize = function(width, height) } /** - * Initializes the canvas data for this texture - * - * @method initCanvas - * @private - */ +* Initializes the canvas data for this texture +* +* @method Phaser.RenderTexture#initCanvas +* @memberof Phaser.RenderTexture +* @private +*/ Phaser.RenderTexture.prototype.initCanvas = function() { this.renderer = new PIXI.CanvasRenderer(this.width, this.height, null, 0); @@ -21388,14 +23488,17 @@ Phaser.RenderTexture.prototype.initCanvas = function() } /** - * This function will draw the display object to the texture. - * - * @method renderWebGL - * @param displayObject {DisplayObject} The display object to render this texture on - * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn - * @private - */ -Phaser.RenderTexture.prototype.renderWebGL = function(displayObject, position, clear) +* This function will draw the display object to the texture. +* +* @method Phaser.RenderTexture#renderWebGL +* @memberof Phaser.RenderTexture +* @private +* @param {DisplayObject} displayObject - The display object to render this texture on. +* @param {Phaser.Point} [position] - Where to draw the display object. +* @param {boolean} [clear=false] - If true the texture will be cleared before the displayObject is drawn. +* @param {boolean} [renderHidden=false] - If true displayObjects that have their visible property set to false will still be rendered. +*/ +Phaser.RenderTexture.prototype.renderWebGL = function(displayObject, position, clear, renderHidden) { var gl = PIXI.gl; @@ -21466,12 +23569,15 @@ Phaser.RenderTexture.prototype.renderWebGL = function(displayObject, position, c /** * This function will draw the display object to the texture. * - * @method renderCanvas - * @param displayObject {DisplayObject} The display object to render this texture on - * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn - * @private - */ -Phaser.RenderTexture.prototype.renderCanvas = function(displayObject, position, clear) +* @method Phaser.RenderTexture#renderCanvas +* @memberof Phaser.RenderTexture +* @private +* @param {DisplayObject} displayObject - The display object to render this texture on. +* @param {Phaser.Point} [position] - Where to draw the display object. +* @param {boolean} [clear=false] - If true the texture will be cleared before the displayObject is drawn. +* @param {boolean} [renderHidden=false] - If true displayObjects that have their visible property set to false will still be rendered. +*/ +Phaser.RenderTexture.prototype.renderCanvas = function(displayObject, position, clear, renderHidden) { var children = displayObject.children; @@ -21492,12 +23598,11 @@ Phaser.RenderTexture.prototype.renderCanvas = function(displayObject, position, { this.renderer.context.clearRect(0, 0, this.width, this.height); } - - this.renderer.renderDisplayObject(displayObject); + + this.renderer.renderDisplayObject(displayObject, renderHidden); this.renderer.context.setTransform(1, 0, 0, 1, 0, 0); - // PIXI.texturesToUpdate.push(this.baseTexture); } /** @@ -21507,7 +23612,7 @@ Phaser.RenderTexture.prototype.renderCanvas = function(displayObject, position, */ /** -* The Canvas class handles everything related to the <canvas> tag as a DOM Element, like styles, offset, aspect ratio +* The Canvas class handles everything related to creating the `canvas` DOM tag that Phaser will use, including styles, offset and aspect ratio. * * @class Phaser.Canvas * @static @@ -21515,21 +23620,29 @@ Phaser.RenderTexture.prototype.renderCanvas = function(displayObject, position, Phaser.Canvas = { /** - * Creates the <canvas> tag + * Creates a `canvas` DOM element. The element is not automatically added to the document. * * @method Phaser.Canvas.create - * @param {number} width - The desired width. - * @param {number} height - The desired height. - * @return {HTMLCanvasElement} The newly created <canvas> tag. + * @param {number} [width=256] - The width of the canvas element. + * @param {number} [height=256] - The height of the canvas element.. + * @param {string} [id=''] - If given this will be set as the ID of the canvas element, otherwise no ID will be set. + * @return {HTMLCanvasElement} The newly created canvas element. */ - create: function (width, height) { + create: function (width, height, id) { width = width || 256; height = height || 256; var canvas = document.createElement('canvas'); + + if (typeof id === 'string') + { + canvas.id = id; + } + canvas.width = width; canvas.height = height; + canvas.style.display = 'block'; return canvas; @@ -21550,8 +23663,22 @@ Phaser.Canvas = { var box = element.getBoundingClientRect(); var clientTop = element.clientTop || document.body.clientTop || 0; var clientLeft = element.clientLeft || document.body.clientLeft || 0; - var scrollTop = window.pageYOffset || element.scrollTop || document.body.scrollTop; - var scrollLeft = window.pageXOffset || element.scrollLeft || document.body.scrollLeft; + + // Without this check Chrome is now throwing console warnings about strict vs. quirks :( + + var scrollTop = 0; + var scrollLeft = 0; + + if (document.compatMode === 'CSS1Compat') + { + scrollTop = window.pageYOffset || document.documentElement.scrollTop || element.scrollTop || 0; + scrollLeft = window.pageXOffset || document.documentElement.scrollLeft || element.scrollLeft || 0; + } + else + { + scrollTop = window.pageYOffset || document.body.scrollTop || element.scrollTop || 0; + scrollLeft = window.pageXOffset || document.body.scrollLeft || element.scrollLeft || 0; + } point.x = box.left + scrollLeft - clientLeft; point.y = box.top + scrollTop - clientTop; @@ -21639,8 +23766,8 @@ Phaser.Canvas = { * * @method Phaser.Canvas.addToDOM * @param {HTMLCanvasElement} canvas - The canvas to set the touch action on. - * @param {string|HTMLElement} parent - The DOM element to add the canvas to. Defaults to ''. - * @param {boolean} overflowHidden - If set to true it will add the overflow='hidden' style to the parent DOM element. + * @param {string|HTMLElement} parent - The DOM element to add the canvas to. + * @param {boolean} [overflowHidden=true] - If set to true it will add the overflow='hidden' style to the parent DOM element. * @return {HTMLCanvasElement} Returns the source canvas. */ addToDOM: function (canvas, parent, overflowHidden) { @@ -21651,29 +23778,29 @@ Phaser.Canvas = { if (parent) { - // hopefully an element ID if (typeof parent === 'string') { + // hopefully an element ID target = document.getElementById(parent); } - // quick test for a HTMLelement else if (typeof parent === 'object' && parent.nodeType === 1) { + // quick test for a HTMLelement target = parent; } - - if (overflowHidden) - { - target.style.overflow = 'hidden'; - } } - // fallback, covers an invalid ID and a none HTMLelement object - if(!target) + // Fallback, covers an invalid ID and a non HTMLelement object + if (!target) { target = document.body; } + if (overflowHidden && target.style) + { + target.style.overflow = 'hidden'; + } + target.appendChild(canvas); return canvas; @@ -21735,9 +23862,11 @@ Phaser.Canvas = { */ setImageRenderingCrisp: function (canvas) { + canvas.style['image-rendering'] = 'optimizeSpeed'; canvas.style['image-rendering'] = 'crisp-edges'; canvas.style['image-rendering'] = '-moz-crisp-edges'; canvas.style['image-rendering'] = '-webkit-optimize-contrast'; + canvas.style['image-rendering'] = 'optimize-contrast'; canvas.style.msInterpolationMode = 'nearest-neighbor'; return canvas; @@ -22025,7 +24154,8 @@ Phaser.StageScaleMode.prototype = { this._width = this.width; this._height = this.height; - console.log('startFullScreen', this._width, this._height); + // This needs updating to match the final spec: + // http://generatedcontent.org/post/70347573294/is-your-fullscreen-api-code-up-to-date-find-out-how-to if (element['requestFullScreen']) { @@ -22033,7 +24163,7 @@ Phaser.StageScaleMode.prototype = { } else if (element['mozRequestFullScreen']) { - element['mozRequestFullScreen'](); + element.parentNode['mozRequestFullScreen'](); } else if (element['webkitRequestFullScreen']) { @@ -22075,16 +24205,24 @@ Phaser.StageScaleMode.prototype = { if (this.isFullScreen) { - this.game.stage.canvas.style['width'] = '100%'; - this.game.stage.canvas.style['height'] = '100%'; + if (this.game.stage.fullScreenScaleMode === Phaser.StageScaleMode.EXACT_FIT) + { + this.game.stage.canvas.style['width'] = '100%'; + this.game.stage.canvas.style['height'] = '100%'; - this.setMaximum(); + this.setMaximum(); - this.game.input.scale.setTo(this.game.width / this.width, this.game.height / this.height); + this.game.input.scale.setTo(this.game.width / this.width, this.game.height / this.height); - this.aspectRatio = this.width / this.height; - this.scaleFactor.x = this.game.width / this.width; - this.scaleFactor.y = this.game.height / this.height; + this.aspectRatio = this.width / this.height; + this.scaleFactor.x = this.game.width / this.width; + this.scaleFactor.y = this.game.height / this.height; + } + else if (this.game.stage.fullScreenScaleMode === Phaser.StageScaleMode.SHOW_ALL) + { + this.game.stage.scale.setShowAll(); + this.game.stage.scale.refresh(); + } } else { @@ -22325,13 +24463,27 @@ Phaser.StageScaleMode.prototype = { { this.setMaximum(); } - else if (this.game.stage.scaleMode == Phaser.StageScaleMode.EXACT_FIT) + else if (!this.isFullScreen) { - this.setExactFit(); + if (this.game.stage.scaleMode == Phaser.StageScaleMode.EXACT_FIT) + { + this.setExactFit(); + } + else if (this.game.stage.scaleMode == Phaser.StageScaleMode.SHOW_ALL) + { + this.setShowAll(); + } } - else if (this.game.stage.scaleMode == Phaser.StageScaleMode.SHOW_ALL) + else { - this.setShowAll(); + if (this.game.stage.fullScreenScaleMode == Phaser.StageScaleMode.EXACT_FIT) + { + this.setExactFit(); + } + else if (this.game.stage.fullScreenScaleMode == Phaser.StageScaleMode.SHOW_ALL) + { + this.setShowAll(); + } } this.setSize(); @@ -22476,6 +24628,8 @@ Phaser.StageScaleMode.prototype = { }; +Phaser.StageScaleMode.prototype.constructor = Phaser.StageScaleMode; + /** * @name Phaser.StageScaleMode#isFullScreen * @property {boolean} isFullScreen - Returns true if the browser is in full screen mode, otherwise false. @@ -22559,6 +24713,12 @@ Phaser.Device = function () { */ this.cocoonJS = false; + /** + * @property {boolean} ejecta - Is the game running under Ejecta? + * @default + */ + this.ejecta = false; + /** * @property {boolean} android - Is running on android? * @default @@ -22657,6 +24817,18 @@ Phaser.Device = function () { */ this.typedArray = false; + /** + * @property {boolean} vibration - Does the device support the Vibration API? + * @default + */ + this.vibration = false; + + /** + * @property {boolean} quirksMode - Is the browser running in strict mode (false) or quirks mode? (true) + * @default + */ + this.quirksMode = false; + // Browser /** @@ -22695,6 +24867,18 @@ Phaser.Device = function () { */ this.ieVersion = 0; + /** + * @property {boolean} trident - Set to true if running a Trident version of Internet Explorer (IE11+) + * @default + */ + this.trident = false; + + /** + * @property {number} tridentVersion - If running in Internet Explorer 11 this will contain the major version number. See http://msdn.microsoft.com/en-us/library/ie/ms537503(v=vs.85).aspx + * @default + */ + this.tridentVersion = 0; + /** * @property {boolean} mobileSafari - Set to true if running in Mobile Safari. * @default @@ -22725,6 +24909,12 @@ Phaser.Device = function () { */ this.webApp = false; + /** + * @property {boolean} silk - Set to true if running in the Silk browser (as used on the Amazon Kindle) + * @default + */ + this.silk = false; + // Audio /** @@ -22829,21 +25019,33 @@ Phaser.Device.prototype = { var ua = navigator.userAgent; - if (/Android/.test(ua)) { + if (/Android/.test(ua)) + { this.android = true; - } else if (/CrOS/.test(ua)) { + } + else if (/CrOS/.test(ua)) + { this.chromeOS = true; - } else if (/iP[ao]d|iPhone/i.test(ua)) { + } + else if (/iP[ao]d|iPhone/i.test(ua)) + { this.iOS = true; - } else if (/Linux/.test(ua)) { + } + else if (/Linux/.test(ua)) + { this.linux = true; - } else if (/Mac OS/.test(ua)) { + } + else if (/Mac OS/.test(ua)) + { this.macOS = true; - } else if (/Windows/.test(ua)) { + } + else if (/Windows/.test(ua)) + { this.windows = true; } - if (this.windows || this.macOS || this.linux) { + if (this.windows || this.macOS || (this.linux && this.silk === false)) + { this.desktop = true; } @@ -22879,16 +25081,20 @@ Phaser.Device.prototype = { this.worker = !!window['Worker']; - if ('ontouchstart' in document.documentElement || (window.navigator.maxTouchPoints && window.navigator.maxTouchPoints > 1)) { + if ('ontouchstart' in document.documentElement || (window.navigator.maxTouchPoints && window.navigator.maxTouchPoints > 1)) + { this.touch = true; } - if (window.navigator.msPointerEnabled || window.navigator.pointerEnabled) { + if (window.navigator.msPointerEnabled || window.navigator.pointerEnabled) + { this.mspointer = true; } this.pointerLock = 'pointerLockElement' in document || 'mozPointerLockElement' in document || 'webkitPointerLockElement' in document; + this.quirksMode = (document.compatMode === 'CSS1Compat') ? false : true; + }, /** @@ -22900,36 +25106,70 @@ Phaser.Device.prototype = { var ua = navigator.userAgent; - if (/Arora/.test(ua)) { + if (/Arora/.test(ua)) + { this.arora = true; - } else if (/Chrome/.test(ua)) { + } + else if (/Chrome/.test(ua)) + { this.chrome = true; - } else if (/Epiphany/.test(ua)) { + } + else if (/Epiphany/.test(ua)) + { this.epiphany = true; - } else if (/Firefox/.test(ua)) { + } + else if (/Firefox/.test(ua)) + { this.firefox = true; - } else if (/Mobile Safari/.test(ua)) { + } + else if (/Mobile Safari/.test(ua)) + { this.mobileSafari = true; - } else if (/MSIE (\d+\.\d+);/.test(ua)) { + } + else if (/MSIE (\d+\.\d+);/.test(ua)) + { this.ie = true; this.ieVersion = parseInt(RegExp.$1, 10); - } else if (/Midori/.test(ua)) { + } + else if (/Midori/.test(ua)) + { this.midori = true; - } else if (/Opera/.test(ua)) { + } + else if (/Opera/.test(ua)) + { this.opera = true; - } else if (/Safari/.test(ua)) { + } + else if (/Safari/.test(ua)) + { this.safari = true; } + else if (/Silk/.test(ua)) + { + this.silk = true; + } + else if (/Trident\/(\d+\.\d+);/.test(ua)) + { + this.ie = true; + this.trident = true; + this.tridentVersion = parseInt(RegExp.$1, 10); + } // WebApp mode in iOS - if (navigator['standalone']) { + if (navigator['standalone']) + { this.webApp = true; } - if (navigator['isCocoonJS']) { + if (navigator['isCocoonJS']) + { this.cocoonJS = true; } + if (typeof window.ejecta !== "undefined") + { + this.ejecta = true; + } + }, /** @@ -23002,6 +25242,13 @@ Phaser.Device.prototype = { this.typedArray = false; } + navigator.vibrate = navigator.vibrate || navigator.webkitVibrate || navigator.mozVibrate || navigator.msVibrate; + + if (navigator.vibrate) + { + this.vibration = true; + } + }, /** @@ -23024,8 +25271,10 @@ Phaser.Device.prototype = { // Add it to the body to get the computed style. document.body.insertBefore(el, null); - for (var t in transforms) { - if (el.style[t] !== undefined) { + for (var t in transforms) + { + if (el.style[t] !== undefined) + { el.style[t] = "translate3d(1px,1px,1px)"; has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]); } @@ -23100,6 +25349,8 @@ Phaser.Device.prototype = { }; +Phaser.Device.prototype.constructor = Phaser.Device; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -23257,6 +25508,9 @@ Phaser.RequestAnimationFrame.prototype = { } }; + +Phaser.RequestAnimationFrame.prototype.constructor = Phaser.RequestAnimationFrame; + /* jshint noempty: false */ /** @@ -23505,6 +25759,8 @@ Phaser.RandomDataGenerator.prototype = { }; +Phaser.RandomDataGenerator.prototype.constructor = Phaser.RandomDataGenerator; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -24195,7 +26451,7 @@ Phaser.Math = { }, /** - * Description. + * A Linear Interpolation Method, mostly used by Phaser.Tween. * @method Phaser.Math#linearInterpolation * @param {number} v * @param {number} k @@ -24222,7 +26478,7 @@ Phaser.Math = { }, /** - * Description. + * A Bezier Interpolation Method, mostly used by Phaser.Tween. * @method Phaser.Math#bezierInterpolation * @param {number} v * @param {number} k @@ -24243,7 +26499,7 @@ Phaser.Math = { }, /** - * Description. + * A Catmull Rom Interpolation Method, mostly used by Phaser.Tween. * @method Phaser.Math#catmullRomInterpolation * @param {number} v * @param {number} k @@ -24940,6 +27196,8 @@ Phaser.QuadTree.prototype = { }; +Phaser.QuadTree.prototype.constructor = Phaser.QuadTree; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -25137,6 +27395,8 @@ Phaser.Circle.prototype = { }; +Phaser.Circle.prototype.constructor = Phaser.Circle; + /** * The largest distance between any two points on the circle. The same as the radius * 2. * @name Phaser.Circle#diameter @@ -25706,6 +27966,8 @@ Phaser.Point.prototype = { }; +Phaser.Point.prototype.constructor = Phaser.Point; + /** * Adds the coordinates of two points together to create a new point. * @method Phaser.Point.add @@ -26115,6 +28377,8 @@ Phaser.Rectangle.prototype = { }; +Phaser.Rectangle.prototype.constructor = Phaser.Rectangle; + /** * @name Phaser.Rectangle#halfWidth * @property {number} halfWidth - Half of the width of the Rectangle. @@ -26493,7 +28757,14 @@ Phaser.Rectangle.intersection = function (a, b, out) { */ Phaser.Rectangle.intersects = function (a, b) { - return (a.x < b.right && b.x < a.right && a.y < b.bottom && b.y < a.bottom); + if (a.width <= 0 || a.height <= 0 || b.width <= 0 || b.height <= 0) + { + return false; + } + + return !(a.right < b.x || a.bottom < b.y || a.x > b.right || a.y > b.bottom); + + // return (a.x < b.right && b.x < a.right && a.y < b.bottom && b.y < a.bottom); // return (a.x <= b.right && b.x <= a.right && a.y <= b.bottom && b.y <= a.bottom); @@ -26696,8 +28967,8 @@ Phaser.Net.prototype = { var output = {}; var keyValues = location.search.substring(1).split('&'); - for (var i in keyValues) { - + for (var i in keyValues) + { var key = keyValues[i].split('='); if (key.length > 1) @@ -26731,6 +29002,8 @@ Phaser.Net.prototype = { }; +Phaser.Net.prototype.constructor = Phaser.Net; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -26814,9 +29087,9 @@ Phaser.TweenManager.prototype = { * @param {Phaser.Tween} tween - The tween object you want to add. * @returns {Phaser.Tween} The tween object you added to the manager. */ - add: function ( tween ) { + add: function (tween) { - this._add.push( tween ); + this._add.push(tween); }, @@ -26839,14 +29112,13 @@ Phaser.TweenManager.prototype = { * @method Phaser.TweenManager#remove * @param {Phaser.Tween} tween - The tween object you want to remove. */ - remove: function ( tween ) { + remove: function (tween) { - var i = this._tweens.indexOf( tween ); - - if ( i !== -1 ) { + var i = this._tweens.indexOf(tween); + if (i !== -1) + { this._tweens[i].pendingDelete = true; - } }, @@ -26859,7 +29131,7 @@ Phaser.TweenManager.prototype = { */ update: function () { - if ( this._tweens.length === 0 && this._add.length === 0 ) + if (this._tweens.length === 0 && this._add.length === 0) { return false; } @@ -26867,20 +29139,18 @@ Phaser.TweenManager.prototype = { var i = 0; var numTweens = this._tweens.length; - while ( i < numTweens ) { - - if ( this._tweens[ i ].update( this.game.time.now ) ) { - + while (i < numTweens) + { + if (this._tweens[i].update(this.game.time.now)) + { i++; - - } else { - - this._tweens.splice( i, 1 ); + } + else + { + this._tweens.splice(i, 1); numTweens--; - } - } // If there are any new tweens to be added, do so now - otherwise they can be spliced out of the array before ever running @@ -26916,7 +29186,8 @@ Phaser.TweenManager.prototype = { */ pauseAll: function () { - for (var i = this._tweens.length - 1; i >= 0; i--) { + for (var i = this._tweens.length - 1; i >= 0; i--) + { this._tweens[i].pause(); } @@ -26929,13 +29200,17 @@ Phaser.TweenManager.prototype = { */ resumeAll: function () { - for (var i = this._tweens.length - 1; i >= 0; i--) { + for (var i = this._tweens.length - 1; i >= 0; i--) + { this._tweens[i].resume(); } } }; + +Phaser.TweenManager.prototype.constructor = Phaser.TweenManager; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -26966,119 +29241,105 @@ Phaser.Tween = function (object, game) { this.game = game; /** - * @property {object} _manager - Description. + * @property {Phaser.TweenManager} _manager - Reference to the TweenManager. * @private */ this._manager = this.game.tweens; /** - * @property {object} _valuesStart - Description. + * @property {object} _valuesStart - Private value object. * @private */ this._valuesStart = {}; /** - * @property {object} _valuesEnd - Description. + * @property {object} _valuesEnd - Private value object. * @private */ this._valuesEnd = {}; /** - * @property {object} _valuesStartRepeat - Description. + * @property {object} _valuesStartRepeat - Private value object. * @private */ this._valuesStartRepeat = {}; /** - * @property {number} _duration - Description. + * @property {number} _duration - Private duration counter. * @private * @default */ this._duration = 1000; /** - * @property {number} _repeat - Description. + * @property {number} _repeat - Private repeat counter. * @private * @default */ this._repeat = 0; /** - * @property {boolean} _yoyo - Description. + * @property {boolean} _yoyo - Private yoyo flag. * @private * @default */ this._yoyo = false; /** - * @property {boolean} _reversed - Description. + * @property {boolean} _reversed - Private reversed flag. * @private * @default */ this._reversed = false; /** - * @property {number} _delayTime - Description. + * @property {number} _delayTime - Private delay counter. * @private * @default */ this._delayTime = 0; /** - * @property {Description} _startTime - Description. + * @property {number} _startTime - Private start time counter. * @private * @default null */ this._startTime = null; /** - * @property {Description} _easingFunction - Description. + * @property {function} _easingFunction - The easing function used for the tween. * @private */ this._easingFunction = Phaser.Easing.Linear.None; /** - * @property {Description} _interpolationFunction - Description. + * @property {function} _interpolationFunction - The interpolation function used for the tween. * @private */ this._interpolationFunction = Phaser.Math.linearInterpolation; /** - * @property {Description} _chainedTweens - Description. + * @property {array} _chainedTweens - A private array of chained tweens. * @private */ this._chainedTweens = []; /** - * @property {Description} _onStartCallback - Description. - * @private - * @default - */ - this._onStartCallback = null; - - /** - * @property {boolean} _onStartCallbackFired - Description. + * @property {boolean} _onStartCallbackFired - Private flag. * @private * @default */ this._onStartCallbackFired = false; /** - * @property {Description} _onUpdateCallback - Description. + * @property {function} _onUpdateCallback - An onUpdate callback. * @private * @default null */ this._onUpdateCallback = null; - + /** - * @property {Description} _onCompleteCallback - Description. - * @private - * @default null - */ - this._onCompleteCallback = null; - - /** - * @property {number} _pausedTime - Description. + * @property {number} _pausedTime - Private pause timer. * @private * @default */ @@ -27091,22 +29352,28 @@ Phaser.Tween = function (object, game) { this.pendingDelete = false; // Set all starting values present on the target object - for ( var field in object ) { - this._valuesStart[ field ] = parseFloat(object[field], 10); + for (var field in object) + { + this._valuesStart[field] = parseFloat(object[field], 10); } /** - * @property {Phaser.Signal} onStart - Description. + * @property {Phaser.Signal} onStart - The onStart event is fired when the Tween begins. */ this.onStart = new Phaser.Signal(); /** - * @property {Phaser.Signal} onComplete - Description. + * @property {Phaser.Signal} onLoop - The onLoop event is fired if the Tween loops. + */ + this.onLoop = new Phaser.Signal(); + + /** + * @property {Phaser.Signal} onComplete - The onComplete event is fired when the Tween completes. Does not fire if the Tween is set to loop. */ this.onComplete = new Phaser.Signal(); /** - * @property {boolean} isRunning - Description. + * @property {boolean} isRunning - If the tween is running this is set to true, otherwise false. Tweens that are in a delayed state, waiting to start, are considered as being running. * @default */ this.isRunning = false; @@ -27120,15 +29387,15 @@ Phaser.Tween.prototype = { * * @method Phaser.Tween#to * @param {object} properties - Properties you want to tween. - * @param {number} duration - Duration of this tween. - * @param {function} ease - Easing function. - * @param {boolean} autoStart - Whether this tween will start automatically or not. - * @param {number} delay - Delay before this tween will start, defaults to 0 (no delay). - * @param {boolean} repeat - Should the tween automatically restart once complete? (ignores any chained tweens). - * @param {Phaser.Tween} yoyo - Description. - * @return {Phaser.Tween} Itself. + * @param {number} [duration=1000] - Duration of this tween in ms. + * @param {function} [ease=null] - Easing function. If not set it will default to Phaser.Easing.Linear.None. + * @param {boolean} [autoStart=false] - Whether this tween will start automatically or not. + * @param {number} [delay=0] - Delay before this tween will start, defaults to 0 (no delay). Value given is in ms. + * @param {boolean} [repeat=0] - Should the tween automatically restart once complete? (ignores any chained tweens). + * @param {boolean} [yoyo=false] - A tween that yoyos will reverse itself when it completes. + * @return {Phaser.Tween} This Tween object. */ - to: function ( properties, duration, ease, autoStart, delay, repeat, yoyo ) { + to: function (properties, duration, ease, autoStart, delay, repeat, yoyo) { duration = duration || 1000; ease = ease || null; @@ -27138,6 +29405,7 @@ Phaser.Tween.prototype = { yoyo = yoyo || false; var self; + if (this._parent) { self = this._manager.create(this._object); @@ -27167,9 +29435,12 @@ Phaser.Tween.prototype = { self._yoyo = yoyo; - if (autoStart) { + if (autoStart) + { return this.start(); - } else { + } + else + { return this; } @@ -27183,43 +29454,41 @@ Phaser.Tween.prototype = { */ start: function () { - if (this.game === null || this._object === null) { + if (this.game === null || this._object === null) + { return; } this._manager.add(this); - this.onStart.dispatch(this._object); - this.isRunning = true; this._onStartCallbackFired = false; this._startTime = this.game.time.now + this._delayTime; - for ( var property in this._valuesEnd ) { - + for (var property in this._valuesEnd) + { // check if an Array was provided as property value - if ( this._valuesEnd[ property ] instanceof Array ) { - - if ( this._valuesEnd[ property ].length === 0 ) { - + if (this._valuesEnd[property] instanceof Array) + { + if (this._valuesEnd[property].length === 0) + { continue; - } // create a local copy of the Array with the start value at the front - this._valuesEnd[ property ] = [ this._object[ property ] ].concat( this._valuesEnd[ property ] ); - + this._valuesEnd[property] = [this._object[property]].concat(this._valuesEnd[property]); } - this._valuesStart[ property ] = this._object[ property ]; + this._valuesStart[property] = this._object[property]; - if ( ( this._valuesStart[ property ] instanceof Array ) === false ) { - this._valuesStart[ property ] *= 1.0; // Ensures we're using numbers, not strings + if ((this._valuesStart[property] instanceof Array) === false) + { + this._valuesStart[property] *= 1.0; // Ensures we're using numbers, not strings } - this._valuesStartRepeat[ property ] = this._valuesStart[ property ] || 0; + this._valuesStartRepeat[property] = this._valuesStart[property] || 0; } @@ -27250,7 +29519,7 @@ Phaser.Tween.prototype = { * @param {number} amount - The amount of the delay in ms. * @return {Phaser.Tween} Itself. */ - delay: function ( amount ) { + delay: function (amount) { this._delayTime = amount; return this; @@ -27264,7 +29533,7 @@ Phaser.Tween.prototype = { * @param {number} times - How many times to repeat. * @return {Phaser.Tween} Itself. */ - repeat: function ( times ) { + repeat: function (times) { this._repeat = times; return this; @@ -27279,7 +29548,7 @@ Phaser.Tween.prototype = { * @param {boolean} yoyo - Set to true to yoyo this tween. * @return {Phaser.Tween} Itself. */ - yoyo: function( yoyo ) { + yoyo: function(yoyo) { this._yoyo = yoyo; return this; @@ -27293,7 +29562,7 @@ Phaser.Tween.prototype = { * @param {function} easing - The easing function this tween will use, i.e. Phaser.Easing.Linear.None. * @return {Phaser.Tween} Itself. */ - easing: function ( easing ) { + easing: function (easing) { this._easingFunction = easing; return this; @@ -27302,12 +29571,13 @@ Phaser.Tween.prototype = { /** * Set interpolation function the tween will use, by default it uses Phaser.Math.linearInterpolation. + * Also available: Phaser.Math.bezierInterpolation and Phaser.Math.catmullRomInterpolation. * * @method Phaser.Tween#interpolation * @param {function} interpolation - The interpolation function to use (Phaser.Math.linearInterpolation by default) * @return {Phaser.Tween} Itself. */ - interpolation: function ( interpolation ) { + interpolation: function (interpolation) { this._interpolationFunction = interpolation; return this; @@ -27347,20 +29617,6 @@ Phaser.Tween.prototype = { }, - /** - * Sets a callback to be fired when the tween starts. Note: callback will be called in the context of the global scope. - * - * @method Phaser.Tween#onStartCallback - * @param {function} callback - The callback to invoke on start. - * @return {Phaser.Tween} Itself. - */ - onStartCallback: function ( callback ) { - - this._onStartCallback = callback; - return this; - - }, - /** * Sets a callback to be fired each time this tween updates. Note: callback will be called in the context of the global scope. * @@ -27368,35 +29624,23 @@ Phaser.Tween.prototype = { * @param {function} callback - The callback to invoke each time this tween is updated. * @return {Phaser.Tween} Itself. */ - onUpdateCallback: function ( callback ) { + onUpdateCallback: function (callback) { this._onUpdateCallback = callback; return this; }, - /** - * Sets a callback to be fired when the tween completes. Note: callback will be called in the context of the global scope. - * - * @method Phaser.Tween#onCompleteCallback - * @param {function} callback - The callback to invoke on completion. - * @return {Phaser.Tween} Itself. - */ - onCompleteCallback: function ( callback ) { - - this._onCompleteCallback = callback; - return this; - - }, - /** * Pauses the tween. * * @method Phaser.Tween#pause */ pause: function () { + this._paused = true; this._pausedTime = this.game.time.now; + }, /** @@ -27405,8 +29649,10 @@ Phaser.Tween.prototype = { * @method Phaser.Tween#resume */ resume: function () { + this._paused = false; this._startTime += (this.game.time.now - this._pausedTime); + }, /** @@ -27416,127 +29662,112 @@ Phaser.Tween.prototype = { * @param {number} time - A timestamp passed in by the TweenManager. * @return {boolean} false if the tween has completed and should be deleted from the manager, otherwise true (still active). */ - update: function ( time ) { + update: function (time) { if (this.pendingDelete) { return false; } - if (this._paused || time < this._startTime) { - + if (this._paused || time < this._startTime) + { return true; - } var property; - if ( time < this._startTime ) { - + if (time < this._startTime) + { return true; - } - if ( this._onStartCallbackFired === false ) { - - if ( this._onStartCallback !== null ) { - - this._onStartCallback.call( this._object ); - - } - + if (this._onStartCallbackFired === false) + { + this.onStart.dispatch(this._object); this._onStartCallbackFired = true; - } - var elapsed = ( time - this._startTime ) / this._duration; + var elapsed = (time - this._startTime) / this._duration; elapsed = elapsed > 1 ? 1 : elapsed; - var value = this._easingFunction( elapsed ); + var value = this._easingFunction(elapsed); - for ( property in this._valuesEnd ) { - - var start = this._valuesStart[ property ] || 0; - var end = this._valuesEnd[ property ]; - - if ( end instanceof Array ) { - - this._object[ property ] = this._interpolationFunction( end, value ); - - } else { + for (property in this._valuesEnd) + { + var start = this._valuesStart[property] || 0; + var end = this._valuesEnd[property]; + if (end instanceof Array) + { + this._object[property] = this._interpolationFunction(end, value); + } + else + { // Parses relative end values with start as base (e.g.: +10, -3) - if ( typeof(end) === "string" ) { + if (typeof(end) === 'string') + { end = start + parseFloat(end, 10); } // protect against non numeric properties. - if ( typeof(end) === "number" ) { - this._object[ property ] = start + ( end - start ) * value; + if (typeof(end) === 'number') + { + this._object[property] = start + ( end - start ) * value; } - } - } - if ( this._onUpdateCallback !== null ) { - - this._onUpdateCallback.call( this._object, value ); - + if (this._onUpdateCallback !== null) + { + this._onUpdateCallback.call(this._object, value); } - if ( elapsed == 1 ) { - - if ( this._repeat > 0 ) { - - if ( isFinite( this._repeat ) ) { + if (elapsed == 1) + { + if (this._repeat > 0) + { + if (isFinite(this._repeat)) + { this._repeat--; } // reassign starting values, restart by making startTime = now - for ( property in this._valuesStartRepeat ) { - - if ( typeof( this._valuesEnd[ property ] ) === "string" ) { - this._valuesStartRepeat[ property ] = this._valuesStartRepeat[ property ] + parseFloat(this._valuesEnd[ property ], 10); + for (property in this._valuesStartRepeat) + { + if (typeof(this._valuesEnd[property]) === 'string') + { + this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property], 10); } - if (this._yoyo) { - var tmp = this._valuesStartRepeat[ property ]; - this._valuesStartRepeat[ property ] = this._valuesEnd[ property ]; - this._valuesEnd[ property ] = tmp; + if (this._yoyo) + { + var tmp = this._valuesStartRepeat[property]; + this._valuesStartRepeat[property] = this._valuesEnd[property]; + this._valuesEnd[property] = tmp; this._reversed = !this._reversed; } - this._valuesStart[ property ] = this._valuesStartRepeat[ property ]; + this._valuesStart[property] = this._valuesStartRepeat[property]; } this._startTime = time + this._delayTime; - this.onComplete.dispatch(this._object); - - if ( this._onCompleteCallback !== null ) { - this._onCompleteCallback.call( this._object ); - } + this.onLoop.dispatch(this._object); return true; - } else { - + } + else + { this.isRunning = false; this.onComplete.dispatch(this._object); - if ( this._onCompleteCallback !== null ) { - this._onCompleteCallback.call( this._object ); - } - - for ( var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i ++ ) { - - this._chainedTweens[ i ].start( time ); - + for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i ++) + { + this._chainedTweens[i].start(time); } return false; - } } @@ -27547,6 +29778,8 @@ Phaser.Tween.prototype = { }; +Phaser.Tween.prototype.constructor = Phaser.Tween; + /* jshint curly: false */ /** @@ -28127,228 +30360,333 @@ Phaser.Easing = { */ Phaser.Time = function (game) { - /** - * @property {Phaser.Game} game - Local reference to game. - */ - this.game = game; + /** + * @property {Phaser.Game} game - Local reference to game. + */ + this.game = game; - /** - * @property {number} _started - The time at which the Game instance started. - * @private - */ - this._started = 0; + /** + * @property {number} physicsElapsed - The elapsed time calculated for the physics motion updates. + */ + this.physicsElapsed = 0; - /** - * @property {number} _timeLastSecond - The time (in ms) that the last second counter ticked over. - * @private - */ - this._timeLastSecond = 0; + /** + * @property {number} time - Game time counter. + */ + this.time = 0; - /** - * @property {number} _pauseStarted - The time the game started being paused. - * @private - */ - this._pauseStarted = 0; + /** + * @property {number} pausedTime - Records how long the game has been paused for. Is reset each time the game pauses. + */ + this.pausedTime = 0; - /** - * @property {number} physicsElapsed - The elapsed time calculated for the physics motion updates. - */ - this.physicsElapsed = 0; + /** + * @property {number} now - The time right now. + */ + this.now = 0; - /** - * @property {number} time - Game time counter. - */ - this.time = 0; + /** + * @property {number} elapsed - Elapsed time since the last frame (in ms). + */ + this.elapsed = 0; - /** - * @property {number} pausedTime - Records how long the game has been paused for. Is reset each time the game pauses. - */ - this.pausedTime = 0; + /** + * @property {number} fps - Frames per second. + */ + this.fps = 0; - /** - * @property {number} now - The time right now. - */ - this.now = 0; + /** + * @property {number} fpsMin - The lowest rate the fps has dropped to. + */ + this.fpsMin = 1000; - /** - * @property {number} elapsed - Elapsed time since the last frame. - */ - this.elapsed = 0; + /** + * @property {number} fpsMax - The highest rate the fps has reached (usually no higher than 60fps). + */ + this.fpsMax = 0; - /** - * @property {number} fps - Frames per second. - */ - this.fps = 0; + /** + * @property {number} msMin - The minimum amount of time the game has taken between two frames. + * @default + */ + this.msMin = 1000; - /** - * @property {number} fpsMin - The lowest rate the fps has dropped to. - */ - this.fpsMin = 1000; + /** + * @property {number} msMax - The maximum amount of time the game has taken between two frames. + */ + this.msMax = 0; - /** - * @property {number} fpsMax - The highest rate the fps has reached (usually no higher than 60fps). - */ - this.fpsMax = 0; + /** + * @property {number} frames - The number of frames record in the last second. + */ + this.frames = 0; - /** - * @property {number} msMin - The minimum amount of time the game has taken between two frames. - * @default - */ - this.msMin = 1000; + /** + * @property {number} pauseDuration - Records how long the game was paused for in miliseconds. + */ + this.pauseDuration = 0; - /** - * @property {number} msMax - The maximum amount of time the game has taken between two frames. - */ - this.msMax = 0; + /** + * @property {number} timeToCall - The value that setTimeout needs to work out when to next update + */ + this.timeToCall = 0; - /** - * @property {number} frames - The number of frames record in the last second. - */ - this.frames = 0; + /** + * @property {number} lastTime - Internal value used by timeToCall as part of the setTimeout loop + */ + this.lastTime = 0; - /** - * @property {number} pauseDuration - Records how long the game was paused for in miliseconds. - */ - this.pauseDuration = 0; + /** + * @property {Phaser.Timer} events - This is a Phaser.Timer object bound to the master clock to which you can add timed events. + */ + this.events = new Phaser.Timer(this.game, false); - /** - * @property {number} timeToCall - The value that setTimeout needs to work out when to next update - */ - this.timeToCall = 0; - - /** - * @property {number} lastTime - Internal value used by timeToCall as part of the setTimeout loop - */ - this.lastTime = 0; - - // Listen for game pause/resume events - this.game.onPause.add(this.gamePaused, this); - this.game.onResume.add(this.gameResumed, this); - - /** - * @property {boolean} _justResumed - Internal value used to recover from the game pause state. + /** + * @property {number} _started - The time at which the Game instance started. * @private - */ - this._justResumed = false; + */ + this._started = 0; + + /** + * @property {number} _timeLastSecond - The time (in ms) that the last second counter ticked over. + * @private + */ + this._timeLastSecond = 0; + + /** + * @property {number} _pauseStarted - The time the game started being paused. + * @private + */ + this._pauseStarted = 0; + + /** + * @property {boolean} _justResumed - Internal value used to recover from the game pause state. + * @private + */ + this._justResumed = false; + + /** + * @property {array} _timers - Internal store of Phaser.Timer objects. + * @private + */ + this._timers = []; + + /** + * @property {number} _len - Temp. array length variable. + * @private + */ + this._len = 0; + + /** + * @property {number} _i - Temp. array counter variable. + * @private + */ + this._i = 0; + + // Listen for game pause/resume events + this.game.onPause.add(this.gamePaused, this); + this.game.onResume.add(this.gameResumed, this); }; Phaser.Time.prototype = { - /** - * Updates the game clock and calculate the fps. This is called automatically by Phaser.Game. - * @method Phaser.Time#update - * @param {number} time - The current timestamp, either performance.now or Date.now depending on the browser. - */ - update: function (time) { + /** + * @method Phaser.Time#boot + */ + boot: function () { - this.now = time; + this.events.start(); - if (this._justResumed) - { - this.time = this.now; - this._justResumed = false; - } + }, - this.timeToCall = this.game.math.max(0, 16 - (time - this.lastTime)); + /** + * Creates a new stand-alone Phaser.Timer object. + * @method Phaser.Time#create + * @param {boolean} [autoDestroy=true] - A Timer that is set to automatically destroy itself will do so after all of its events have been dispatched (assuming no looping events). + * @return {Phaser.Timer} The Timer object that was created. + */ + create: function (autoDestroy) { - this.elapsed = this.now - this.time; + if (typeof autoDestroy === 'undefined') { autoDestroy = true; } - this.msMin = this.game.math.min(this.msMin, this.elapsed); - this.msMax = this.game.math.max(this.msMax, this.elapsed); + var timer = new Phaser.Timer(this.game, autoDestroy); - this.frames++; + this._timers.push(timer); - if (this.now > this._timeLastSecond + 1000) - { - this.fps = Math.round((this.frames * 1000) / (this.now - this._timeLastSecond)); - this.fpsMin = this.game.math.min(this.fpsMin, this.fps); - this.fpsMax = this.game.math.max(this.fpsMax, this.fps); - this._timeLastSecond = this.now; - this.frames = 0; - } + return timer; - this.time = this.now; + }, + + /** + * Remove all Timer objects, regardless of their state. + * @method Phaser.Time#removeAll + */ + removeAll: function () { + + for (var i = 0; i < this._timers.length; i++) + { + this._timers[i].destroy(); + } + + this._timers = []; + + }, + + /** + * Updates the game clock and calculate the fps. This is called automatically by Phaser.Game. + * @method Phaser.Time#update + * @param {number} time - The current timestamp, either performance.now or Date.now depending on the browser. + */ + update: function (time) { + + this.now = time; + + if (this._justResumed) + { + this.time = this.now; + this._justResumed = false; + + this.events.resume(); + + for (var i = 0; i < this._timers.length; i++) + { + this._timers[i].resume(); + } + } + + this.timeToCall = this.game.math.max(0, 16 - (time - this.lastTime)); + + this.elapsed = this.now - this.time; + + this.msMin = this.game.math.min(this.msMin, this.elapsed); + this.msMax = this.game.math.max(this.msMax, this.elapsed); + + this.frames++; + + if (this.now > this._timeLastSecond + 1000) + { + this.fps = Math.round((this.frames * 1000) / (this.now - this._timeLastSecond)); + this.fpsMin = this.game.math.min(this.fpsMin, this.fps); + this.fpsMax = this.game.math.max(this.fpsMax, this.fps); + this._timeLastSecond = this.now; + this.frames = 0; + } + + this.time = this.now; this.lastTime = time + this.timeToCall; - this.physicsElapsed = 1.0 * (this.elapsed / 1000); + this.physicsElapsed = 1.0 * (this.elapsed / 1000); - // Clamp the delta - if (this.physicsElapsed > 1) - { - this.physicsElapsed = 1; - } + // Clamp the delta + if (this.physicsElapsed > 1) + { + this.physicsElapsed = 1; + } - // Paused? - if (this.game.paused) - { - this.pausedTime = this.now - this._pauseStarted; - } + // Paused? + if (this.game.paused) + { + this.pausedTime = this.now - this._pauseStarted; + } + else + { + // Our internal Phaser.Timer + this.events.update(this.now); - }, + // Any game level timers + this._i = 0; + this._len = this._timers.length; - /** - * Called when the game enters a paused state. - * @method Phaser.Time#gamePaused - * @private - */ - gamePaused: function () { - - this._pauseStarted = this.now; + while (this._i < this._len) + { + if (this._timers[this._i].update(this.now)) + { + this._i++; + } + else + { + this._timers.splice(this._i, 1); - }, + this._len--; + } + } + } - /** - * Called when the game resumes from a paused state. - * @method Phaser.Time#gameResumed - * @private - */ - gameResumed: function () { + }, - // Level out the elapsed timer to avoid spikes - this.time = Date.now(); - this.pauseDuration = this.pausedTime; - this._justResumed = true; + /** + * Called when the game enters a paused state. + * @method Phaser.Time#gamePaused + * @private + */ + gamePaused: function () { + + this._pauseStarted = this.now; - }, + this.events.pause(); - /** - * The number of seconds that have elapsed since the game was started. - * @method Phaser.Time#totalElapsedSeconds - * @return {number} - */ - totalElapsedSeconds: function() { - return (this.now - this._started) * 0.001; - }, + for (var i = 0; i < this._timers.length; i++) + { + this._timers[i].pause(); + } - /** - * How long has passed since the given time. - * @method Phaser.Time#elapsedSince - * @param {number} since - The time you want to measure against. - * @return {number} The difference between the given time and now. - */ - elapsedSince: function (since) { - return this.now - since; - }, + }, - /** - * How long has passed since the given time (in seconds). - * @method Phaser.Time#elapsedSecondsSince - * @param {number} since - The time you want to measure (in seconds). - * @return {number} Duration between given time and now (in seconds). - */ - elapsedSecondsSince: function (since) { - return (this.now - since) * 0.001; - }, + /** + * Called when the game resumes from a paused state. + * @method Phaser.Time#gameResumed + * @private + */ + gameResumed: function () { - /** - * Resets the private _started value to now. - * @method Phaser.Time#reset - */ - reset: function () { - this._started = this.now; - } + // Level out the elapsed timer to avoid spikes + this.time = Date.now(); + this.pauseDuration = this.pausedTime; + this._justResumed = true; + + }, + + /** + * The number of seconds that have elapsed since the game was started. + * @method Phaser.Time#totalElapsedSeconds + * @return {number} + */ + totalElapsedSeconds: function() { + return (this.now - this._started) * 0.001; + }, + + /** + * How long has passed since the given time. + * @method Phaser.Time#elapsedSince + * @param {number} since - The time you want to measure against. + * @return {number} The difference between the given time and now. + */ + elapsedSince: function (since) { + return this.now - since; + }, + + /** + * How long has passed since the given time (in seconds). + * @method Phaser.Time#elapsedSecondsSince + * @param {number} since - The time you want to measure (in seconds). + * @return {number} Duration between given time and now (in seconds). + */ + elapsedSecondsSince: function (since) { + return (this.now - since) * 0.001; + }, + + /** + * Resets the private _started value to now. + * @method Phaser.Time#reset + */ + reset: function () { + this._started = this.now; + } }; + +Phaser.Time.prototype.constructor = Phaser.Time; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -28356,14 +30694,19 @@ Phaser.Time.prototype = { */ /** -* Timer constructor. +* A Timer is a way to create small re-usable or disposable objects that do nothing but wait for a specific moment in time, and then dispatch an event. +* You can add as many events to a Timer as you like, each with their own delays. A Timer uses milliseconds as its unit of time. There are 1000 ms in 1 second. +* So if you want to fire an event every quarter of a second you'd need to set the delay to 250. * * @class Phaser.Timer -* @classdesc A Timer +* @classdesc A Timer is a way to create small re-usable or disposable objects that do nothing but wait for a specific moment in time, and then dispatch an event. * @constructor * @param {Phaser.Game} game A reference to the currently running game. +* @param {boolean} [autoDestroy=true] - A Timer that is set to automatically destroy itself will do so after all of its events have been dispatched (assuming no looping events). */ -Phaser.Timer = function (game) { +Phaser.Timer = function (game, autoDestroy) { + + if (typeof autoDestroy === 'undefined') { autoDestroy = true; } /** * @property {Phaser.Game} game - Local reference to game. @@ -28371,67 +30714,208 @@ Phaser.Timer = function (game) { this.game = game; /** - * The time at which this Timer instance started. - * @property {number} _started + * @property {boolean} running - True if the Timer is actively running. Do not switch this boolean, if you wish to pause the timer then use Timer.pause() instead. + * @default + */ + this.running = false; + + /** + * @property {boolean} autoDestroy - A Timer that is set to automatically destroy itself will do so after all of its events have been dispatched (assuming no looping events). + */ + this.autoDestroy = autoDestroy; + + /** + * @property {boolean} expired - An expired Timer is one in which all of its events have been dispatched and none are pending. + * @readonly + * @default + */ + this.expired = false; + + /** + * @property {array} events - An array holding all of this timers Phaser.TimerEvent objects. Use the methods add, repeat and loop to populate it. + */ + this.events = []; + + /** + * @property {Phaser.Signal} onComplete - This signal will be dispatched when this Timer has completed, meaning there are no more events in the queue. + */ + this.onComplete = new Phaser.Signal(); + + /** + * @property {number} nextTick - The time the next tick will occur. + * @readonly + * @protected + */ + this.nextTick = 0; + + /** + * @property {boolean} paused - The paused state of the Timer. You can pause the timer by calling Timer.pause() and Timer.resume() or by the game pausing. + * @readonly + * @default + */ + this.paused = false; + + /** + * @property {number} _started - The time at which this Timer instance started running. * @private * @default */ this._started = 0; /** - * The time (in ms) that the last second counter ticked over. - * @property {number} _timeLastSecond + * @property {number} _pauseStarted - The time the game started being paused. * @private - * @default */ - this._timeLastSecond = 0; + this._pauseStarted = 0; - this.running = false; + /** + * @property {number} _now - The current start-time adjusted time. + * @private + */ + this._now = 0; - this.events = []; + /** + * @property {number} _len - Temp. array length variable. + * @private + */ + this._len = 0; - this.onEvent = new Phaser.Signal(); + /** + * @property {number} _i - Temp. array counter variable. + * @private + */ + this._i = 0; - // Need to add custom FPS rate, for now we'll just use seconds +}; -} +/** +* @constant +* @type {number} +*/ +Phaser.Timer.MINUTE = 60000; + +/** +* @constant +* @type {number} +*/ +Phaser.Timer.SECOND = 1000; + +/** +* @constant +* @type {number} +*/ +Phaser.Timer.HALF = 500; + +/** +* @constant +* @type {number} +*/ +Phaser.Timer.QUARTER = 250; Phaser.Timer.prototype = { - // delay could be from now, when the timer is created, or relative to an already running timer + /** + * Creates a new TimerEvent on this Timer. Use the methods add, repeat or loop instead of this. + * @method Phaser.Timer#create + * @private + * @param {number} delay - The number of milliseconds that should elapse before the Timer will call the given callback. + * @param {boolean} loop - Should the event loop or not? + * @param {number} repeatCount - The number of times the event will repeat. + * @param {function} callback - The callback that will be called when the Timer event occurs. + * @param {object} callbackContext - The context in which the callback will be called. + * @param {array} arguments - The values to be sent to your callback function when it is called. + * @return {Phaser.TimerEvent} The Phaser.TimerEvent object that was created. + */ + create: function (delay, loop, repeatCount, callback, callbackContext, args) { - // add: function (delay, callback, callbackContext) { - add: function (delay) { + var tick = delay; - this.events.push({ - delay: delay, - dispatched: false, - args: Array.prototype.splice.call(arguments, 1) - }); + if (this.running) + { + tick += this._now; + } - // this.events.push({ - // delay: delay, - // dispatched: false, - // callback: callback, - // callbackContext: callbackContext, - // args: Array.prototype.splice.call(arguments, 3) - // }); + var event = new Phaser.TimerEvent(this, delay, tick, repeatCount, loop, callback, callbackContext, args); + + this.events.push(event); + + this.order(); + + this.expired = false; + + return event; }, + /** + * Adds a new Event to this Timer. The event will fire after the given amount of 'delay' in milliseconds has passed, once the Timer has started running. + * Call Timer.start() once you have added all of the Events you require for this Timer. The delay is in relation to when the Timer starts, not the time it was added. + * If the Timer is already running the delay will be calculated based on the timers current time. + * @method Phaser.Timer#add + * @param {number} delay - The number of milliseconds that should elapse before the Timer will call the given callback. + * @param {function} callback - The callback that will be called when the Timer event occurs. + * @param {object} callbackContext - The context in which the callback will be called. + * @param {...} arguments - The values to be sent to your callback function when it is called. + * @return {Phaser.TimerEvent} The Phaser.TimerEvent object that was created. + */ + add: function (delay, callback, callbackContext) { + + return this.create(delay, false, 0, callback, callbackContext, Array.prototype.splice.call(arguments, 3)); + + }, + + /** + * Adds a new Event to this Timer that will repeat for the given number of iterations. + * The event will fire after the given amount of 'delay' milliseconds has passed once the Timer has started running. + * Call Timer.start() once you have added all of the Events you require for this Timer. The delay is in relation to when the Timer starts, not the time it was added. + * If the Timer is already running the delay will be calculated based on the timers current time. + * @method Phaser.Timer#repeat + * @param {number} delay - The number of milliseconds that should elapse before the Timer will call the given callback. + * @param {number} repeatCount - The number of times the event will repeat. + * @param {function} callback - The callback that will be called when the Timer event occurs. + * @param {object} callbackContext - The context in which the callback will be called. + * @param {...} arguments - The values to be sent to your callback function when it is called. + * @return {Phaser.TimerEvent} The Phaser.TimerEvent object that was created. + */ + repeat: function (delay, repeatCount, callback, callbackContext) { + + return this.create(delay, false, repeatCount, callback, callbackContext, Array.prototype.splice.call(arguments, 4)); + + }, + + /** + * Adds a new looped Event to this Timer that will repeat forever or until the Timer is stopped. + * The event will fire after the given amount of 'delay' milliseconds has passed once the Timer has started running. + * Call Timer.start() once you have added all of the Events you require for this Timer. The delay is in relation to when the Timer starts, not the time it was added. + * If the Timer is already running the delay will be calculated based on the timers current time. + * @method Phaser.Timer#loop + * @param {number} delay - The number of milliseconds that should elapse before the Timer will call the given callback. + * @param {function} callback - The callback that will be called when the Timer event occurs. + * @param {object} callbackContext - The context in which the callback will be called. + * @param {...} arguments - The values to be sent to your callback function when it is called. + * @return {Phaser.TimerEvent} The Phaser.TimerEvent object that was created. + */ + loop: function (delay, callback, callbackContext) { + + return this.create(delay, true, 0, callback, callbackContext, Array.prototype.splice.call(arguments, 3)); + + }, + + /** + * Starts this Timer running. + * @method Phaser.Timer#start + */ start: function() { this._started = this.game.time.now; this.running = true; - // sort the events based on delay here, also don't run unless events is populated - // add ability to auto-stop once all events are done - // add support for maximum duration - // add support for delay before starting - // add signals? - }, + /** + * Stops this Timer from running. Does not cause it to be destroyed if autoDestroy is set to true. + * @method Phaser.Timer#stop + */ stop: function() { this.running = false; @@ -28439,33 +30923,326 @@ Phaser.Timer.prototype = { }, - update: function() { + /** + * Removes a pending TimerEvent from the queue. + * @param {Phaser.TimerEvent} event - The event to remove from the queue. + * @method Phaser.Timer#remove + */ + remove: function(event) { - // TODO: Game Paused support - - if (this.running) + for (var i = 0; i < this.events.length; i++) { - var seconds = this.seconds(); - - for (var i = 0, len = this.events.length; i < len; i++) + if (this.events[i] === event) { - if (this.events[i].dispatched === false && seconds >= this.events[i].delay) - { - this.events[i].dispatched = true; - // this.events[i].callback.apply(this.events[i].callbackContext, this.events[i].args); - this.onEvent.dispatch.apply(this, this.events[i].args); - // ought to slice it now - } + this.events.splice(i, 1); + return true; } } + return false; + + }, + + /** + * Orders the events on this Timer so they are in tick order. This is called automatically when new events are created. + * @method Phaser.Timer#order + */ + order: function () { + + if (this.events.length > 0) + { + // Sort the events so the one with the lowest tick is first + this.events.sort(this.sortHandler); + + this.nextTick = this.events[0].tick; + } + }, - seconds: function() { - return (this.game.time.now - this._started) * 0.001; + /** + * Sort handler used by Phaser.Timer.order. + * @method Phaser.Timer#sortHandler + * @protected + */ + sortHandler: function (a, b) { + + if (a.tick < b.tick) + { + return -1; + } + else if (a.tick > b.tick) + { + return 1; + } + + return 0; + + }, + + /** + * The main Timer update event, called automatically by the Game clock. + * @method Phaser.Timer#update + * @protected + * @param {number} time - The time from the core game clock. + * @return {boolean} True if there are still events waiting to be dispatched, otherwise false if this Timer can be destroyed. + */ + update: function(time) { + + if (this.paused) + { + return true; + } + + this._now = time - this._started; + + this._len = this.events.length; + + if (this.running && this._now >= this.nextTick && this._len > 0) + { + this._i = 0; + + while (this._i < this._len) + { + if (this._now >= this.events[this._i].tick) + { + if (this.events[this._i].loop === true) + { + this.events[this._i].tick += this.events[this._i].delay - (this._now - this.events[this._i].tick); + this.events[this._i].callback.apply(this.events[this._i].callbackContext, this.events[this._i].args); + } + else if (this.events[this._i].repeatCount > 0) + { + this.events[this._i].repeatCount--; + this.events[this._i].tick += this.events[this._i].delay - (this._now - this.events[this._i].tick); + this.events[this._i].callback.apply(this.events[this._i].callbackContext, this.events[this._i].args); + } + else + { + this.events[this._i].callback.apply(this.events[this._i].callbackContext, this.events[this._i].args); + this.events.splice(this._i, 1); + this._len--; + } + + this._i++; + } + else + { + break; + } + } + + // Are there any events left? + if (this.events.length > 0) + { + this.order(); + } + else + { + this.expired = true; + this.onComplete.dispatch(this); + } + } + + if (this.expired && this.autoDestroy) + { + return false; + } + else + { + return true; + } + + }, + + /** + * Pauses the Timer and all events in the queue. + * @method Phaser.Timer#pause + */ + pause: function () { + + this._pauseStarted = this.game.time.now; + + this.paused = true; + + }, + + /** + * Resumes the Timer and updates all pending events. + * @method Phaser.Timer#resume + */ + resume: function () { + + var pauseDuration = this.game.time.now - this._pauseStarted; + + for (var i = 0; i < this.events.length; i++) + { + this.events[i].tick += pauseDuration; + } + + this.nextTick += pauseDuration; + + this.paused = false; + + }, + + /** + * Destroys this Timer. Events are not dispatched. + * @method Phaser.Timer#destroy + */ + destroy: function() { + + this.onComplete.removeAll(); + this.running = false; + this.events = []; + } -} +}; + +/** +* @name Phaser.Timer#next +* @property {number} next - The time at which the next event will occur. +* @readonly +*/ +Object.defineProperty(Phaser.Timer.prototype, "next", { + + get: function () { + return this.nextTick; + } + +}); + +/** +* @name Phaser.Timer#duration +* @property {number} duration - The duration in ms remaining until the next event will occur. +* @readonly +*/ +Object.defineProperty(Phaser.Timer.prototype, "duration", { + + get: function () { + + if (this.running && this.nextTick > this._now) + { + return this.nextTick - this._now; + } + else + { + return 0; + } + + } + +}); + +/** +* @name Phaser.Timer#length +* @property {number} length - The number of pending events in the queue. +* @readonly +*/ +Object.defineProperty(Phaser.Timer.prototype, "length", { + + get: function () { + return this.events.length; + } + +}); + +/** +* @name Phaser.Timer#ms +* @property {number} ms - The duration in milliseconds that this Timer has been running for. +* @readonly +*/ +Object.defineProperty(Phaser.Timer.prototype, "ms", { + + get: function () { + return this._now; + } + +}); + +/** +* @name Phaser.Timer#seconds +* @property {number} seconds - The duration in seconds that this Timer has been running for. +* @readonly +*/ +Object.defineProperty(Phaser.Timer.prototype, "seconds", { + + get: function () { + return this._now * 0.001; + } + +}); + +Phaser.Timer.prototype.constructor = Phaser.Timer; + +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +*/ + +/** +* A TimerEvent is a single event that is processed by a Phaser.Timer. It consists of a delay, which is a value in milliseconds after which the event will fire. +* It can call a specific callback, passing in optional parameters. +* +* @class Phaser.TimerEvent +* @classdesc A TimerEvent is a single event that is processed by a Phaser.Timer. It consists of a delay, which is a value in milliseconds after which the event will fire. +* @constructor +* @param {Phaser.Timer} timer - The Timer object that this TimerEvent belongs to. +* @param {number} delay - The delay in ms at which this TimerEvent fires. +* @param {number} tick - The tick is the next game clock time that this event will fire at. +* @param {number} repeatCount - If this TimerEvent repeats it will do so this many times. +* @param {boolean} loop - True if this TimerEvent loops, otherwise false. +* @param {function} callback - The callback that will be called when the TimerEvent occurs. +* @param {object} callbackContext - The context in which the callback will be called. +* @param {array} arguments - The values to be passed to the callback. +*/ +Phaser.TimerEvent = function (timer, delay, tick, repeatCount, loop, callback, callbackContext, args) { + + /** + * @property {Phaser.Timer} timer - The Timer object that this TimerEvent belongs to. + */ + this.timer = timer; + + /** + * @property {number} delay - The delay in ms at which this TimerEvent fires. + */ + this.delay = delay; + + /** + * @property {number} tick - The tick is the next game clock time that this event will fire at. + */ + this.tick = tick; + + /** + * @property {number} repeatCount - If this TimerEvent repeats it will do so this many times. + */ + this.repeatCount = repeatCount - 1; + + /** + * @property {boolean} loop - True if this TimerEvent loops, otherwise false. + */ + this.loop = loop; + + /** + * @property {function} callback - The callback that will be called when the TimerEvent occurs. + */ + this.callback = callback; + + /** + * @property {object} callbackContext - The context in which the callback will be called. + */ + this.callbackContext = callbackContext; + + /** + * @property {array} arguments - The values to be passed to the callback. + */ + this.args = args; + +}; + +Phaser.TimerEvent.prototype.constructor = Phaser.TimerEvent; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -28779,6 +31556,8 @@ Phaser.AnimationManager.prototype = { }; +Phaser.AnimationManager.prototype.constructor = Phaser.AnimationManager; + /** * @name Phaser.AnimationManager#frameData * @property {Phaser.FrameData} frameData - The current animations FrameData. @@ -28939,7 +31718,7 @@ Phaser.Animation = function (game, parent, name, frameData, frames, delay, loope this.name = name; /** - * @property {object} _frames + * @property {array} _frames * @private */ this._frames = []; @@ -28956,7 +31735,8 @@ Phaser.Animation = function (game, parent, name, frameData, frames, delay, loope this.looped = looped; /** - * @property {boolean} looped - The loop state of the Animation. + * @property {boolean} killOnComplete - Should the parent of this Animation be killed when the animation completes? + * @default */ this.killOnComplete = false; @@ -29223,6 +32003,8 @@ Phaser.Animation.prototype = { }; +Phaser.Animation.prototype.constructor = Phaser.Animation; + /** * @name Phaser.Animation#paused * @property {boolean} paused - Gets and sets the paused state of this Animation. @@ -29526,6 +32308,8 @@ Phaser.Frame.prototype = { }; +Phaser.Frame.prototype.constructor = Phaser.Frame; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -29751,6 +32535,8 @@ Phaser.FrameData.prototype = { }; +Phaser.FrameData.prototype.constructor = Phaser.FrameData; + /** * @name Phaser.FrameData#total * @property {number} total - The total number of frames in this FrameData set. @@ -29786,9 +32572,11 @@ Phaser.AnimationParser = { * @param {number} frameWidth - The fixed width of each frame of the animation. * @param {number} frameHeight - The fixed height of each frame of the animation. * @param {number} [frameMax=-1] - The total number of animation frames to extact from the Sprite Sheet. The default value of -1 means "extract all frames". + * @param {number} [margin=0] - If the frames have been drawn with a margin, specify the amount here. + * @param {number} [spacing=0] - If the frames have been drawn with spacing between them, specify the amount here. * @return {Phaser.FrameData} A FrameData object containing the parsed frames. */ - spriteSheet: function (game, key, frameWidth, frameHeight, frameMax) { + spriteSheet: function (game, key, frameWidth, frameHeight, frameMax, margin, spacing) { // How big is our image? var img = game.cache.getImage(key); @@ -29829,8 +32617,8 @@ Phaser.AnimationParser = { // Let's create some frames then var data = new Phaser.FrameData(); - var x = 0; - var y = 0; + var x = margin; + var y = margin; for (var i = 0; i < total; i++) { @@ -29845,12 +32633,12 @@ Phaser.AnimationParser = { height: frameHeight }); - x += frameWidth; + x += frameWidth + spacing; if (x === width) { - x = 0; - y += frameHeight; + x = margin; + y += frameHeight + spacing; } } @@ -30099,9 +32887,8 @@ Phaser.AnimationParser = { /** * Phaser.Cache constructor. * -* @class Phaser.Cache -* @classdesc A game only has one instance of a Cache and it is used to store all externally loaded assets such -* as images, sounds and data files as a result of Loader calls. Cache items use string based keys for look-up. +* @class Phaser.Cache +* @classdesc A game only has one instance of a Cache and it is used to store all externally loaded assets such as images, sounds and data files as a result of Loader calls. Cached items use string based keys for look-up. * @constructor * @param {Phaser.Game} game - A reference to the currently running game. */ @@ -30149,10 +32936,10 @@ Phaser.Cache = function (game) { this._tilemaps = {}; /** - * @property {object} _tilesets - Tileset key-value container. + * @property {object} _binary - Binary file key-value container. * @private */ - this._tilesets = {}; + this._binary = {}; /** * @property {object} _bitmapDatas - BitmapData key-value container. @@ -30185,6 +32972,18 @@ Phaser.Cache.prototype = { }, + /** + * Add a binary object in to the cache. + * @method Phaser.Cache#addBinary + * @param {string} key - Asset key for this binary data. + * @param {object} binaryData - The binary object to be addded to the cache. + */ + addBinary: function (key, binaryData) { + + this._binary[key] = binaryData; + + }, + /** * Add a BitmapData object in to the cache. * @method Phaser.Cache#addBitmapData @@ -30224,40 +33023,18 @@ Phaser.Cache.prototype = { * @param {object} data - Extra sprite sheet data. * @param {number} frameWidth - Width of the sprite sheet. * @param {number} frameHeight - Height of the sprite sheet. - * @param {number} frameMax - How many frames stored in the sprite sheet. + * @param {number} [frameMax=-1] - How many frames stored in the sprite sheet. If -1 then it divides the whole sheet evenly. + * @param {number} [margin=0] - If the frames have been drawn with a margin, specify the amount here. + * @param {number} [spacing=0] - If the frames have been drawn with spacing between them, specify the amount here. */ - addSpriteSheet: function (key, url, data, frameWidth, frameHeight, frameMax) { + addSpriteSheet: function (key, url, data, frameWidth, frameHeight, frameMax, margin, spacing) { - this._images[key] = { url: url, data: data, spriteSheet: true, frameWidth: frameWidth, frameHeight: frameHeight }; + this._images[key] = { url: url, data: data, spriteSheet: true, frameWidth: frameWidth, frameHeight: frameHeight, margin: margin, spacing: spacing }; PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data); PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]); - this._images[key].frameData = Phaser.AnimationParser.spriteSheet(this.game, key, frameWidth, frameHeight, frameMax); - - }, - - /** - * Add a new tile set in to the cache. - * - * @method Phaser.Cache#addTileset - * @param {string} key - The unique key by which you will reference this object. - * @param {string} url - URL of this tile set file. - * @param {object} data - Extra tile set data. - * @param {number} tileWidth - Width of the sprite sheet. - * @param {number} tileHeight - Height of the sprite sheet. - * @param {number} tileMax - How many tiles stored in the sprite sheet. - * @param {number} [tileMargin=0] - If the tiles have been drawn with a margin, specify the amount here. - * @param {number} [tileSpacing=0] - If the tiles have been drawn with spacing between them, specify the amount here. - */ - addTileset: function (key, url, data, tileWidth, tileHeight, tileMax, tileMargin, tileSpacing) { - - this._tilesets[key] = { url: url, data: data, tileWidth: tileWidth, tileHeight: tileHeight, tileMargin: tileMargin, tileSpacing: tileSpacing }; - - PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data); - PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]); - - this._tilesets[key].tileData = Phaser.TilemapParser.tileset(this.game, key, tileWidth, tileHeight, tileMax, tileMargin, tileSpacing); + this._images[key].frameData = Phaser.AnimationParser.spriteSheet(this.game, key, frameWidth, frameHeight, frameMax, margin, spacing); }, @@ -30267,15 +33044,13 @@ Phaser.Cache.prototype = { * @method Phaser.Cache#addTilemap * @param {string} key - The unique key by which you will reference this object. * @param {string} url - URL of the tilemap image. - * @param {object} mapData - The tilemap data object. + * @param {object} mapData - The tilemap data object (either a CSV or JSON file). * @param {number} format - The format of the tilemap data. */ addTilemap: function (key, url, mapData, format) { this._tilemaps[key] = { url: url, data: mapData, format: format }; - this._tilemaps[key].layers = Phaser.TilemapParser.parse(this.game, mapData, format); - }, /** @@ -30425,12 +33200,13 @@ Phaser.Cache.prototype = { decoded = true; } - this._sounds[key] = { url: url, data: data, isDecoding: false, decoded: decoded, webAudio: webAudio, audioTag: audioTag }; + this._sounds[key] = { url: url, data: data, isDecoding: false, decoded: decoded, webAudio: webAudio, audioTag: audioTag, locked: this.game.sound.touchLocked }; }, /** * Reload a sound. + * * @method Phaser.Cache#reloadSound * @param {string} key - Asset key for the sound. */ @@ -30451,7 +33227,8 @@ Phaser.Cache.prototype = { }, /** - * Description. + * Fires the onSoundUnlock event when the sound has completed reloading. + * * @method Phaser.Cache#reloadSoundComplete * @param {string} key - Asset key for the sound. */ @@ -30466,7 +33243,8 @@ Phaser.Cache.prototype = { }, /** - * Description. + * Updates the sound object in the cache. + * * @method Phaser.Cache#updateSound * @param {string} key - Asset key for the sound. */ @@ -30498,8 +33276,8 @@ Phaser.Cache.prototype = { * Get a canvas object from the cache by its key. * * @method Phaser.Cache#getCanvas - * @param {string} key - Asset key of the canvas you want. - * @return {object} The canvas you want. + * @param {string} key - Asset key of the canvas to retrieve from the Cache. + * @return {object} The canvas object. */ getCanvas: function (key) { @@ -30507,8 +33285,10 @@ Phaser.Cache.prototype = { { return this._canvases[key].canvas; } - - return null; + else + { + console.warn('Phaser.Cache.getCanvas: Invalid key: "' + key + '"'); + } }, @@ -30516,7 +33296,7 @@ Phaser.Cache.prototype = { * Get a BitmapData object from the cache by its key. * * @method Phaser.Cache#getBitmapData - * @param {string} key - Asset key of the BitmapData object you want. + * @param {string} key - Asset key of the BitmapData object to retrieve from the Cache. * @return {Phaser.BitmapData} The requested BitmapData object if found, or null if not. */ getBitmapData: function (key) { @@ -30525,8 +33305,10 @@ Phaser.Cache.prototype = { { return this._bitmapDatas[key]; } - - return null; + else + { + console.warn('Phaser.Cache.getBitmapData: Invalid key: "' + key + '"'); + } }, @@ -30534,7 +33316,7 @@ Phaser.Cache.prototype = { * Checks if an image key exists. * * @method Phaser.Cache#checkImageKey - * @param {string} key - Asset key of the image you want. + * @param {string} key - Asset key of the image to check is in the Cache. * @return {boolean} True if the key exists, otherwise false. */ checkImageKey: function (key) { @@ -30552,8 +33334,8 @@ Phaser.Cache.prototype = { * Get image data by key. * * @method Phaser.Cache#getImage - * @param {string} key - Asset key of the image you want. - * @return {object} The image data you want. + * @param {string} key - Asset key of the image to retrieve from the Cache. + * @return {object} The image data. */ getImage: function (key) { @@ -30561,53 +33343,19 @@ Phaser.Cache.prototype = { { return this._images[key].data; } - - return null; - - }, - - /** - * Get tile set image data by key. - * - * @method Phaser.Cache#getTileSetImage - * @param {string} key - Asset key of the image you want. - * @return {object} The image data you want. - */ - getTilesetImage: function (key) { - - if (this._tilesets[key]) + else { - return this._tilesets[key].data; + console.warn('Phaser.Cache.getImage: Invalid key: "' + key + '"'); } - return null; - - }, - - /** - * Get tile set image data by key. - * - * @method Phaser.Cache#getTileset - * @param {string} key - Asset key of the image you want. - * @return {Phaser.Tileset} The tileset data. The tileset image is in the data property, the tile data in tileData. - */ - getTileset: function (key) { - - if (this._tilesets[key]) - { - return this._tilesets[key].tileData; - } - - return null; - }, /** * Get tilemap data by key. * * @method Phaser.Cache#getTilemap - * @param {string} key - Asset key of the tilemap you want. - * @return {Object} The tilemap data. The tileset image is in the data property, the map data in mapData. + * @param {string} key - Asset key of the tilemap data to retrieve from the Cache. + * @return {Object} The raw tilemap data in CSV or JSON format. */ getTilemapData: function (key) { @@ -30615,16 +33363,19 @@ Phaser.Cache.prototype = { { return this._tilemaps[key]; } + else + { + console.warn('Phaser.Cache.getTilemapData: Invalid key: "' + key + '"'); + } - return null; }, /** * Get frame data by key. * * @method Phaser.Cache#getFrameData - * @param {string} key - Asset key of the frame data you want. - * @return {Phaser.FrameData} The frame data you want. + * @param {string} key - Asset key of the frame data to retrieve from the Cache. + * @return {Phaser.FrameData} The frame data. */ getFrameData: function (key) { @@ -30640,8 +33391,8 @@ Phaser.Cache.prototype = { * Get a single frame out of a frameData set by key. * * @method Phaser.Cache#getFrameByIndex - * @param {string} key - Asset key of the frame data you want. - * @return {Phaser.Frame} The frame data you want. + * @param {string} key - Asset key of the frame data to retrieve from the Cache. + * @return {Phaser.Frame} The frame object. */ getFrameByIndex: function (key, frame) { @@ -30657,8 +33408,8 @@ Phaser.Cache.prototype = { * Get a single frame out of a frameData set by key. * * @method Phaser.Cache#getFrameByName - * @param {string} key - Asset key of the frame data you want. - * @return {Phaser.Frame} The frame data you want. + * @param {string} key - Asset key of the frame data to retrieve from the Cache. + * @return {Phaser.Frame} The frame object. */ getFrameByName: function (key, frame) { @@ -30674,8 +33425,8 @@ Phaser.Cache.prototype = { * Get a single frame by key. You'd only do this to get the default Frame created for a non-atlas/spritesheet image. * * @method Phaser.Cache#getFrame - * @param {string} key - Asset key of the frame data you want. - * @return {Phaser.Frame} The frame data you want. + * @param {string} key - Asset key of the frame data to retrieve from the Cache. + * @return {Phaser.Frame} The frame data. */ getFrame: function (key) { @@ -30688,11 +33439,11 @@ Phaser.Cache.prototype = { }, /** - * Get a single frame by key. You'd only do this to get the default Frame created for a non-atlas/spritesheet image. + * Get a single texture frame by key. You'd only do this to get the default Frame created for a non-atlas/spritesheet image. * * @method Phaser.Cache#getTextureFrame - * @param {string} key - Asset key of the frame data you want. - * @return {Phaser.Frame} The frame data you want. + * @param {string} key - Asset key of the frame to retrieve from the Cache. + * @return {Phaser.Frame} The frame data. */ getTextureFrame: function (key) { @@ -30708,8 +33459,8 @@ Phaser.Cache.prototype = { * Get a RenderTexture by key. * * @method Phaser.Cache#getTexture - * @param {string} key - Asset key of the RenderTexture you want. - * @return {Phaser.RenderTexture} The RenderTexture you want. + * @param {string} key - Asset key of the RenderTexture to retrieve from the Cache. + * @return {Phaser.RenderTexture} The RenderTexture object. */ getTexture: function (key) { @@ -30717,8 +33468,10 @@ Phaser.Cache.prototype = { { return this._textures[key]; } - - return null; + else + { + console.warn('Phaser.Cache.getTexture: Invalid key: "' + key + '"'); + } }, @@ -30726,8 +33479,8 @@ Phaser.Cache.prototype = { * Get sound by key. * * @method Phaser.Cache#getSound - * @param {string} key - Asset key of the sound you want. - * @return {Phaser.Sound} The sound you want. + * @param {string} key - Asset key of the sound to retrieve from the Cache. + * @return {Phaser.Sound} The sound object. */ getSound: function (key) { @@ -30735,8 +33488,10 @@ Phaser.Cache.prototype = { { return this._sounds[key]; } - - return null; + else + { + console.warn('Phaser.Cache.getSound: Invalid key: "' + key + '"'); + } }, @@ -30744,8 +33499,8 @@ Phaser.Cache.prototype = { * Get sound data by key. * * @method Phaser.Cache#getSoundData - * @param {string} key - Asset key of the sound you want. - * @return {object} The sound data you want. + * @param {string} key - Asset key of the sound to retrieve from the Cache. + * @return {object} The sound data. */ getSoundData: function (key) { @@ -30753,8 +33508,10 @@ Phaser.Cache.prototype = { { return this._sounds[key].data; } - - return null; + else + { + console.warn('Phaser.Cache.getSoundData: Invalid key: "' + key + '"'); + } }, @@ -30762,7 +33519,7 @@ Phaser.Cache.prototype = { * Check if the given sound has finished decoding. * * @method Phaser.Cache#isSoundDecoded - * @param {string} key - Asset key of the sound you want. + * @param {string} key - Asset key of the sound in the Cache. * @return {boolean} The decoded state of the Sound object. */ isSoundDecoded: function (key) { @@ -30778,7 +33535,7 @@ Phaser.Cache.prototype = { * Check if the given sound is ready for playback. A sound is considered ready when it has finished decoding and the device is no longer touch locked. * * @method Phaser.Cache#isSoundReady - * @param {string} key - Asset key of the sound you want. + * @param {string} key - Asset key of the sound in the Cache. * @return {boolean} True if the sound is decoded and the device is not touch locked. */ isSoundReady: function (key) { @@ -30809,8 +33566,8 @@ Phaser.Cache.prototype = { * Get text data by key. * * @method Phaser.Cache#getText - * @param {string} key - Asset key of the text data you want. - * @return {object} The text data you want. + * @param {string} key - Asset key of the text data to retrieve from the Cache. + * @return {object} The text data. */ getText: function (key) { @@ -30818,8 +33575,30 @@ Phaser.Cache.prototype = { { return this._text[key].data; } + else + { + console.warn('Phaser.Cache.getText: Invalid key: "' + key + '"'); + } + + }, - return null; + /** + * Get binary data by key. + * + * @method Phaser.Cache#getBinary + * @param {string} key - Asset key of the binary data object to retrieve from the Cache. + * @return {object} The binary data object. + */ + getBinary: function (key) { + + if (this._binary[key]) + { + return this._binary[key]; + } + else + { + console.warn('Phaser.Cache.getBinary: Invalid key: "' + key + '"'); + } }, @@ -30837,7 +33616,7 @@ Phaser.Cache.prototype = { for (var item in array) { - if (item !== '__default') + if (item !== '__default' && item !== '__missing') { output.push(item); } @@ -30947,6 +33726,8 @@ Phaser.Cache.prototype = { }; +Phaser.Cache.prototype.constructor = Phaser.Cache; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -30983,7 +33764,7 @@ Phaser.Loader = function (game) { this._fileIndex = 0; /** - * @property {number} _progressChunk - Indicates assets loading progress. (from 0 to 100) + * @property {number} _progressChunk - Indicates the size of 1 file in terms of a percentage out of 100. * @private * @default */ @@ -31008,11 +33789,17 @@ Phaser.Loader = function (game) { this.hasLoaded = false; /** - * @property {number} progress - The Load progress percentage value (from 0 to 100) + * @property {number} progress - The rounded load progress percentage value (from 0 to 100) * @default */ this.progress = 0; + /** + * @property {number} progressFloat - The non-rounded load progress value (from 0.0 to 100.0) + * @default + */ + this.progressFloat = 0; + /** * You can optionally link a sprite to the preloader. * If you do so the Sprite's width or height will be cropped based on the percentage loaded. @@ -31312,6 +34099,29 @@ Phaser.Loader.prototype = { }, + /** + * Add a binary file to the Loader. It will be loaded via xhr with a responseType of "arraybuffer". You can specify an optional callback to process the file after load. + * When the callback is called it will be passed 2 parameters: the key of the file and the file data. + * WARNING: If you specify a callback, the file data will be set to whatever your callback returns. So always return the data object, even if you didn't modify it. + * + * @method Phaser.Loader#binary + * @param {string} key - Unique asset key of the binary file. + * @param {string} url - URL of the binary file. + * @param {function} [callback] - Optional callback that will be passed the file after loading, so you can perform additional processing on it. + * @param {function} [callbackContext] - The context under which the callback will be applied. If not specified it will use the callback itself as the context. + * @return {Phaser.Loader} This Loader instance. + */ + binary: function (key, url, callback, callbackContext) { + + if (typeof callback === 'undefined') { callback = false; } + if (callback !== false && typeof callbackContext === 'undefined') { callbackContext = callback; } + + this.addToFileList('binary', key, url, { callback: callback, callbackContext: callbackContext }); + + return this; + + }, + /** * Add a new sprite sheet to the loader. * @@ -31321,38 +34131,17 @@ Phaser.Loader.prototype = { * @param {number} frameWidth - Width of each single frame. * @param {number} frameHeight - Height of each single frame. * @param {number} [frameMax=-1] - How many frames in this sprite sheet. If not specified it will divide the whole image into frames. + * @param {number} [margin=0] - If the frames have been drawn with a margin, specify the amount here. + * @param {number} [spacing=0] - If the frames have been drawn with spacing between them, specify the amount here. * @return {Phaser.Loader} This Loader instance. */ - spritesheet: function (key, url, frameWidth, frameHeight, frameMax) { + spritesheet: function (key, url, frameWidth, frameHeight, frameMax, margin, spacing) { if (typeof frameMax === "undefined") { frameMax = -1; } + if (typeof margin === "undefined") { margin = 0; } + if (typeof spacing === "undefined") { spacing = 0; } - this.addToFileList('spritesheet', key, url, { frameWidth: frameWidth, frameHeight: frameHeight, frameMax: frameMax }); - - return this; - - }, - - /** - * Add a new tile set to the loader. These are used in the rendering of tile maps. - * - * @method Phaser.Loader#tileset - * @param {string} key - Unique asset key of the tileset file. - * @param {string} url - URL of the tileset. - * @param {number} tileWidth - Width of each single tile in pixels. - * @param {number} tileHeight - Height of each single tile in pixels. - * @param {number} [tileMax=-1] - How many tiles in this tileset. If not specified it will divide the whole image into tiles. - * @param {number} [tileMargin=0] - If the tiles have been drawn with a margin, specify the amount here. - * @param {number} [tileSpacing=0] - If the tiles have been drawn with spacing between them, specify the amount here. - * @return {Phaser.Loader} This Loader instance. - */ - tileset: function (key, url, tileWidth, tileHeight, tileMax, tileMargin, tileSpacing) { - - if (typeof tileMax === "undefined") { tileMax = -1; } - if (typeof tileMargin === "undefined") { tileMargin = 0; } - if (typeof tileSpacing === "undefined") { tileSpacing = 0; } - - this.addToFileList('tileset', key, url, { tileWidth: tileWidth, tileHeight: tileHeight, tileMax: tileMax, tileMargin: tileMargin, tileSpacing: tileSpacing }); + this.addToFileList('spritesheet', key, url, { frameWidth: frameWidth, frameHeight: frameHeight, frameMax: frameMax, margin: margin, spacing: spacing }); return this; @@ -31660,6 +34449,7 @@ Phaser.Loader.prototype = { } this.progress = 0; + this.progressFloat = 0; this.hasLoaded = false; this.isLoading = true; @@ -31674,6 +34464,7 @@ Phaser.Loader.prototype = { else { this.progress = 100; + this.progressFloat = 100; this.hasLoaded = true; this.onLoadComplete.dispatch(); } @@ -31704,7 +34495,6 @@ Phaser.Loader.prototype = { case 'spritesheet': case 'textureatlas': case 'bitmapfont': - case 'tileset': file.data = new Image(); file.data.name = file.key; file.data.onload = function () { @@ -31795,6 +34585,7 @@ Phaser.Loader.prototype = { break; case 'text': + case 'script': this._xhr.open("GET", this.baseURL + file.url, true); this._xhr.responseType = "text"; this._xhr.onload = function () { @@ -31806,10 +34597,9 @@ Phaser.Loader.prototype = { this._xhr.send(); break; - case 'script': - + case 'binary': this._xhr.open("GET", this.baseURL + file.url, true); - this._xhr.responseType = "text"; + this._xhr.responseType = "arraybuffer"; this._xhr.onload = function () { return _this.fileComplete(_this._fileIndex); }; @@ -31882,7 +34672,6 @@ Phaser.Loader.prototype = { console.warn('Phaser.Loader fileComplete invalid index ' + index); return; } - var file = this._fileList[index]; file.loaded = true; @@ -31899,12 +34688,7 @@ Phaser.Loader.prototype = { case 'spritesheet': - this.game.cache.addSpriteSheet(file.key, file.url, file.data, file.frameWidth, file.frameHeight, file.frameMax); - break; - - case 'tileset': - - this.game.cache.addTileset(file.key, file.url, file.data, file.tileWidth, file.tileHeight, file.tileMax, file.tileMargin, file.tileSpacing); + this.game.cache.addSpriteSheet(file.key, file.url, file.data, file.frameWidth, file.frameHeight, file.frameMax, file.margin, file.spacing); break; case 'textureatlas': @@ -31987,6 +34771,7 @@ Phaser.Loader.prototype = { if (buffer) { that.game.cache.decodedSound(key, buffer); + that.game.sound.onSoundDecode.dispatch(key, that.game.cache.getSound(key)); } }); } @@ -32011,6 +34796,20 @@ Phaser.Loader.prototype = { file.data.text = this._xhr.responseText; document.head.appendChild(file.data); break; + + case 'binary': + if (file.callback) + { + file.data = file.callback.call(file.callbackContext, file.key, this._xhr.response); + } + else + { + file.data = this._xhr.response; + } + + this.game.cache.addBinary(file.key, file.data); + + break; } if (loadNext) @@ -32156,7 +34955,8 @@ Phaser.Loader.prototype = { */ nextFile: function (previousIndex, success) { - this.progress = Math.round(this.progress + this._progressChunk); + this.progressFloat += this._progressChunk; + this.progress = Math.round(this.progressFloat); if (this.progress > 100) { @@ -32240,6 +35040,8 @@ Phaser.Loader.prototype = { }; +Phaser.Loader.prototype.constructor = Phaser.Loader; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -32671,25 +35473,25 @@ Phaser.Sound.prototype = { { if (this.loop) { - //console.log('loop1'); + // console.log('loop1'); // won't work with markers, needs to reset the position this.onLoop.dispatch(this); if (this.currentMarker === '') { - //console.log('loop2'); + // console.log('loop2'); this.currentTime = 0; this.startTime = this.game.time.now; } else { - //console.log('loop3'); + // console.log('loop3'); this.play(this.currentMarker, 0, this.volume, true, true); } } else { - //console.log('stopping, no loop for marker'); + // console.log('stopping, no loop for marker'); this.stop(); } } @@ -32877,7 +35679,7 @@ Phaser.Sound.prototype = { else { // console.log('sound not locked, state?', this._sound.readyState); - if (this._sound && this._sound.readyState == 4) + if (this._sound && (this.game.device.cocoonJS || this._sound.readyState === 4)) { this._sound.play(); // This doesn't become available until you call play(), wonderful ... @@ -32967,7 +35769,20 @@ Phaser.Sound.prototype = { this._sound = this.context.createBufferSource(); this._sound.buffer = this._buffer; - this._sound.connect(this.gainNode); + + if (this.externalNode) + { + this._sound.connect(this.externalNode.input); + } + else + { + this._sound.connect(this.gainNode); + } + + if (this.loop) + { + this._sound.loop = true; + } if (typeof this._sound.start === 'undefined') { @@ -33028,6 +35843,8 @@ Phaser.Sound.prototype = { }; +Phaser.Sound.prototype.constructor = Phaser.Sound; + /** * @name Phaser.Sound#isDecoding * @property {boolean} isDecoding - Returns true if the sound file is still decoding. @@ -33424,7 +36241,7 @@ Phaser.SoundManager.prototype = { that.game.cache.decodedSound(key, buffer); if (sound) { - that.onSoundDecode.dispatch(sound); + that.onSoundDecode.dispatch(key, sound); } }); } @@ -33505,6 +36322,8 @@ Phaser.SoundManager.prototype = { }; +Phaser.SoundManager.prototype.constructor = Phaser.SoundManager; + /** * @name Phaser.SoundManager#mute * @property {boolean} mute - Gets or sets the muted state of the SoundManager. This effects all sounds in the game. @@ -33647,6 +36466,11 @@ Phaser.Utils.Debug = function (game) { */ this.font = '14px Courier'; + /** + * @property {number} columnWidth - The spacing between columns. + */ + this.columnWidth = 100; + /** * @property {number} lineHeight - The line height between the debug text. */ @@ -33682,11 +36506,12 @@ Phaser.Utils.Debug.prototype = { /** * Internal method that resets and starts the debug output values. * @method Phaser.Utils.Debug#start - * @param {number} x - The X value the debug info will start from. - * @param {number} y - The Y value the debug info will start from. - * @param {string} color - The color the debug info will drawn in. + * @param {number} [x=0] - The X value the debug info will start from. + * @param {number} [y=0] - The Y value the debug info will start from. + * @param {string} [color='rgb(255,255,255)'] - The color the debug text will drawn in. + * @param {number} [columnWidth=0] - The spacing between columns. */ - start: function (x, y, color) { + start: function (x, y, color, columnWidth) { if (this.context == null) { @@ -33695,13 +36520,14 @@ Phaser.Utils.Debug.prototype = { if (typeof x !== 'number') { x = 0; } if (typeof y !== 'number') { y = 0; } - color = color || 'rgb(255,255,255)'; + if (typeof columnWidth === 'undefined') { columnWidth = 0; } this.currentX = x; this.currentY = y; this.currentColor = color; this.currentAlpha = this.context.globalAlpha; + this.columnWidth = columnWidth; this.context.save(); this.context.setTransform(1, 0, 0, 1, 0, 0); @@ -33717,7 +36543,6 @@ Phaser.Utils.Debug.prototype = { */ stop: function () { - this.context.restore(); this.context.globalAlpha = this.currentAlpha; @@ -33727,8 +36552,8 @@ Phaser.Utils.Debug.prototype = { * Internal method that outputs a single line of text. * @method Phaser.Utils.Debug#line * @param {string} text - The line of text to draw. - * @param {number} x - The X value the debug info will start from. - * @param {number} y - The Y value the debug info will start from. + * @param {number} [x] - The X value the debug info will start from. + * @param {number} [y] - The Y value the debug info will start from. */ line: function (text, x, y) { @@ -33737,16 +36562,8 @@ Phaser.Utils.Debug.prototype = { return; } - x = x || null; - y = y || null; - - if (x !== null) { - this.currentX = x; - } - - if (y !== null) { - this.currentY = y; - } + if (typeof x !== 'undefined') { this.currentX = x; } + if (typeof y !== 'undefined') { this.currentY = y; } if (this.renderShadow) { @@ -33760,6 +36577,38 @@ Phaser.Utils.Debug.prototype = { }, + /** + * Internal method that outputs a single line of text split over as many columns as needed, one per parameter. + * @method Phaser.Utils.Debug#splitline + * @param {string} text - The text to render. You can have as many columns of text as you want, just pass them as additional parameters. + */ + splitline: function (text) { + + if (this.context == null) + { + return; + } + + var x = this.currentX; + + for (var i = 0; i < arguments.length; i++) + { + if (this.renderShadow) + { + this.context.fillStyle = 'rgb(0,0,0)'; + this.context.fillText(arguments[i], x + 1, this.currentY + 1); + this.context.fillStyle = this.currentColor; + } + + this.context.fillText(arguments[i], x, this.currentY); + + x += this.columnWidth; + } + + this.currentY += this.lineHeight; + + }, + /** * Visually renders a QuadTree to the display. * @method Phaser.Utils.Debug#renderQuadTree @@ -34016,14 +36865,44 @@ Phaser.Utils.Debug.prototype = { color = color || 'rgb(255,255,255)'; - this.start(x, y, color); - this.line('Sprite Collision: (' + sprite.width + ' x ' + sprite.height + ')'); + this.start(x, y, color, 100); + + this.line('Body: (width: ' + sprite.width + ' height: ' + sprite.height + ')'); this.line('left: ' + sprite.body.touching.left); this.line('right: ' + sprite.body.touching.right); this.line('up: ' + sprite.body.touching.up); this.line('down: ' + sprite.body.touching.down); - this.line('velocity.x: ' + sprite.body.velocity.x); - this.line('velocity.y: ' + sprite.body.velocity.y); + this.stop(); + + }, + + /** + * Render Sprite Body Physics Data as text. + * @method Phaser.Utils.Debug#renderBodyInfo + * @param {Phaser.Sprite} sprite - The sprite to be rendered. + * @param {number} x - X position of the debug info to be rendered. + * @param {number} y - Y position of the debug info to be rendered. + * @param {string} [color='rgb(255,255,255)'] - color of the debug info to be rendered. (format is css color string). + */ + renderBodyInfo: function (sprite, x, y, color) { + + color = color || 'rgb(255,255,255)'; + + this.start(x, y, color, 220); + + this.splitline('x: ' + sprite.body.x.toFixed(2), 'y: ' + sprite.body.y.toFixed(2), 'width: ' + sprite.width, 'height: ' + sprite.height); + this.splitline('speed: ' + sprite.body.speed.toFixed(2), 'angle: ' + sprite.body.angle.toFixed(2)); + //this.splitline('old x: ' + sprite.body.preX.toFixed(2), 'y: ' + sprite.body.preY.toFixed(2)); + this.splitline('drag x: ' + sprite.body.drag.x, 'y: ' + sprite.body.drag.y); + this.splitline('gravity x: ' + sprite.body.gravity.x, 'y: ' + sprite.body.gravity.y); + this.splitline('world gravity x: ' + this.game.physics.gravity.x, 'y: ' + this.game.physics.gravity.y); + this.splitline('acceleration x: ' + sprite.body.acceleration.x.toFixed(2), 'y: ' + sprite.body.acceleration.y.toFixed(2)); + this.splitline('velocity x: ' + sprite.body.velocity.x.toFixed(2), 'y: ' + sprite.body.velocity.y.toFixed(2)); + this.splitline('motion x: ' + sprite.body.motionVelocity.x.toFixed(2), 'y: ' + sprite.body.motionVelocity.y.toFixed(2)); + this.splitline('bounce x: ' + sprite.body.bounce.x.toFixed(2), 'y: ' + sprite.body.bounce.y.toFixed(2)); + this.splitline('sleeping: ' + sprite.body.sleeping, 'sleepTimer: ' + sprite.body._sleepTimer.toFixed(2)); + this.splitline('sleepMin x: ' + sprite.body.sleepMin.x, 'y: ' + sprite.body.sleepMin.y); + this.splitline('sleepMax x: ' + sprite.body.sleepMax.x, 'y: ' + sprite.body.sleepMax.y); this.stop(); }, @@ -34244,7 +37123,7 @@ Phaser.Utils.Debug.prototype = { */ renderSpriteBody: function (sprite, color) { - if (this.context == null) + if (this.context == null || sprite.body.touching.none === true) { return; } @@ -34257,6 +37136,38 @@ Phaser.Utils.Debug.prototype = { this.context.fillRect(sprite.body.screenX, sprite.body.screenY, sprite.body.width, sprite.body.height); this.stop(); + this.start(0, 0, color); + + this.context.beginPath(); + this.context.strokeStyle = '#000000'; + + if (sprite.body.touching.up) + { + this.context.moveTo(sprite.body.x, sprite.body.y); + this.context.lineTo(sprite.body.x + sprite.body.width, sprite.body.y); + } + + if (sprite.body.touching.down) + { + this.context.moveTo(sprite.body.x, sprite.body.y + sprite.body.height); + this.context.lineTo(sprite.body.x + sprite.body.width, sprite.body.y + sprite.body.height); + } + + if (sprite.body.touching.left) + { + this.context.moveTo(sprite.body.x, sprite.body.y); + this.context.lineTo(sprite.body.x, sprite.body.y + sprite.body.height); + } + + if (sprite.body.touching.right) + { + this.context.moveTo(sprite.body.x + sprite.body.width, sprite.body.y); + this.context.lineTo(sprite.body.x + sprite.body.width, sprite.body.y + sprite.body.height); + } + + this.context.stroke(); + + this.stop(); }, @@ -34289,7 +37200,16 @@ Phaser.Utils.Debug.prototype = { { this.context.strokeStyle = color; this.context.strokeRect(sprite.bounds.x, sprite.bounds.y, sprite.bounds.width, sprite.bounds.height); + this.context.strokeRect(sprite.body.x, sprite.body.y, sprite.body.width, sprite.body.height); + // this.context.strokeRect(sprite.body.hull.x, sprite.body.hull.y, sprite.body.hull.width, sprite.body.hull.height); this.context.stroke(); + + // this.context.strokeStyle = '#ff0000'; + // this.context.strokeRect(sprite.body.hullX.x, sprite.body.hullX.y, sprite.body.hullX.width, sprite.body.hullX.height); + // this.context.stroke(); + // this.context.strokeStyle = '#00ff00'; + // this.context.strokeRect(sprite.body.hullY.x, sprite.body.hullY.y, sprite.body.hullY.width, sprite.body.hullY.height); + // this.context.stroke(); } this.stop(); @@ -34494,9 +37414,10 @@ Phaser.Utils.Debug.prototype = { } - }; +Phaser.Utils.Debug.prototype.constructor = Phaser.Utils.Debug; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -35017,28 +37938,111 @@ Phaser.Physics.Arcade.prototype = { * * @method Phaser.Physics.Arcade#updateMotion * @param {Phaser.Physics.Arcade.Body} The Body object to be updated. - */ updateMotion: function (body) { // If you're wondering why the velocity is halved and applied twice, read this: http://www.niksula.hut.fi/~hkankaan/Homepages/gravity.html // Rotation - this._velocityDelta = (this.computeVelocity(0, body, body.angularVelocity, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) * this.game.time.physicsElapsed * 0.5 * 60; + this._velocityDelta = (this.computeVelocity(body, body.angularVelocity, body.angularAcceleration, body.angularDrag, body.maxAngular, 0) - body.angularVelocity) * 0.5; body.angularVelocity += this._velocityDelta; body.rotation += (body.angularVelocity * this.game.time.physicsElapsed); body.angularVelocity += this._velocityDelta; + if (body.allowGravity) + { + // Gravity was previously applied without taking physicsElapsed into account + // so it needs to be multiplied by 60 (fps) for compatibility with existing games + this._gravityX = (this.gravity.x + body.gravity.x) * 60; + this._gravityY = (this.gravity.y + body.gravity.y) * 60; + } + else + { + this._gravityX = 0; + this._gravityY = 0; + } + + body.motionVelocity.x = (this.computeVelocity(body, body.velocity.x, body.acceleration.x, body.drag.x, body.maxVelocity.x, this._gravityX) - body.velocity.x) * 0.5; + body.motionVelocity.y = (this.computeVelocity(body, body.velocity.y, body.acceleration.y, body.drag.y, body.maxVelocity.y, this._gravityY) - body.velocity.y) * 0.5; + // Horizontal - this._velocityDelta = (this.computeVelocity(1, body, body.velocity.x, body.acceleration.x, body.drag.x, body.maxVelocity.x) - body.velocity.x) * this.game.time.physicsElapsed * 0.5 * 60; - body.velocity.x += this._velocityDelta; - body.x += (body.velocity.x * this.game.time.physicsElapsed); - body.velocity.x += this._velocityDelta; + // this._velocityDelta = (this.computeVelocity(body, body.velocity.x, body.acceleration.x, body.drag.x, body.maxVelocity.x, this._gravityX) - body.velocity.x) * 0.5; + // body.velocity.x += this._velocityDelta; + // body.x += (body.velocity.x * this.game.time.physicsElapsed); + // body.velocity.x += this._velocityDelta; // Vertical - this._velocityDelta = (this.computeVelocity(2, body, body.velocity.y, body.acceleration.y, body.drag.y, body.maxVelocity.y) - body.velocity.y) * this.game.time.physicsElapsed * 0.5 * 60; - body.velocity.y += this._velocityDelta; - body.y += (body.velocity.y * this.game.time.physicsElapsed); - body.velocity.y += this._velocityDelta; + // this._velocityDelta = (this.computeVelocity(body, body.velocity.y, body.acceleration.y, body.drag.y, body.maxVelocity.y, this._gravityY) - body.velocity.y) * 0.5; + // body.motionVelocity.y = this._velocityDelta; + + // body.velocity.y += this._velocityDelta; + // body.y += (body.velocity.y * this.game.time.physicsElapsed); + // body.velocity.y += this._velocityDelta; + + }, + */ + + /** + * Called automatically by a Physics body, it updates all motion related values on the Body. + * + * @method Phaser.Physics.Arcade#updateMotion + * @param {Phaser.Physics.Arcade.Body} The Body object to be updated. + */ + updateMotion: function (body) { + + // If you're wondering why the velocity is halved and applied twice, read this: http://www.niksula.hut.fi/~hkankaan/Homepages/gravity.html + + if (body.allowGravity) + { + this._gravityX = (this.gravity.x + body.gravity.x); + this._gravityY = (this.gravity.y + body.gravity.y); + } + else + { + this._gravityX = 0; + this._gravityY = 0; + } + + // Rotation + if (body.allowRotation) + { + this._velocityDelta = body.angularAcceleration * this.game.time.physicsElapsed; + + if (body.angularDrag !== 0 && body.angularAcceleration === 0) + { + this._drag = body.angularDrag * this.game.time.physicsElapsed; + + if (body.angularVelocity > 0) + { + body.angularVelocity -= this._drag; + } + else if (body.angularVelocity < 0) + { + body.angularVelocity += this._drag; + } + } + + body.rotation += this.game.time.physicsElapsed * (body.angularVelocity + this._velocityDelta / 2); + body.angularVelocity += this._velocityDelta; + + if (body.angularVelocity > body.maxAngular) + { + body.angularVelocity = body.maxAngular; + } + else if (body.angularVelocity < -body.maxAngular) + { + body.angularVelocity = -body.maxAngular; + } + } + + // velocity = velocity + gravity*delta_time/2 + // position = position + velocity*delta_time + // velocity = velocity + gravity*delta_time/2 + // temp = acc*dt + // pos = pos + dt*(vel + temp/2) + // vel = vel + temp + + body.motionVelocity.x = (body.acceleration.x + this._gravityX) * this.game.time.physicsElapsed; + body.motionVelocity.y = (body.acceleration.y + this._gravityY) * this.game.time.physicsElapsed; }, @@ -35046,42 +38050,37 @@ Phaser.Physics.Arcade.prototype = { * A tween-like function that takes a starting velocity and some other factors and returns an altered velocity. * * @method Phaser.Physics.Arcade#computeVelocity - * @param {number} axis - 1 for horizontal, 2 for vertical. * @param {Phaser.Physics.Arcade.Body} body - The Body object to be updated. * @param {number} velocity - Any component of velocity (e.g. 20). * @param {number} acceleration - Rate at which the velocity is changing. * @param {number} drag - Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set. - * @param {number} mMax - An absolute value cap for the velocity. + * @param {number} [max=10000] - An absolute value cap for the velocity. + * @param {number} gravity - The acceleration due to gravity. Gravity will not induce drag. * @return {number} The altered Velocity value. - */ - computeVelocity: function (axis, body, velocity, acceleration, drag, max) { + computeVelocity: function (body, velocity, acceleration, drag, max, gravity) { max = max || 10000; - if (axis == 1 && body.allowGravity) - { - velocity += this.gravity.x + body.gravity.x; - } - else if (axis == 2 && body.allowGravity) - { - velocity += this.gravity.y + body.gravity.y; - } - - if (acceleration !== 0) - { - velocity += acceleration * this.game.time.physicsElapsed; - } - else if (drag !== 0) + // velocity = (acceleration + gravity) * this.game.time.physicsElapsed; + // velocity += (acceleration + gravity) * this.game.time.physicsElapsed; + velocity = (acceleration + gravity); + + if (acceleration === 0 && drag !== 0) { this._drag = drag * this.game.time.physicsElapsed; + // this._drag = drag; + // if (velocity - drag > 0) if (velocity - this._drag > 0) { - velocity -= this._drag; + // velocity += this._drag; + velocity -= drag; } - else if (velocity + this._drag < 0) + // else if (velocity - drag < 0) + else if (velocity - this._drag < 0) { - velocity += this._drag; + // velocity -= this._drag; + velocity -= drag; } else { @@ -35101,6 +38100,7 @@ Phaser.Physics.Arcade.prototype = { return velocity; }, + */ /** * Called automatically by the core game loop. @@ -35158,9 +38158,9 @@ Phaser.Physics.Arcade.prototype = { if (object1 && object2 && object1.exists && object2.exists) { // SPRITES - if (object1.type == Phaser.SPRITE) + if (object1.type == Phaser.SPRITE || object1.type == Phaser.TILESPRITE) { - if (object2.type == Phaser.SPRITE) + if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE) { this.overlapSpriteVsSprite(object1, object2, overlapCallback, processCallback, callbackContext); } @@ -35172,7 +38172,7 @@ Phaser.Physics.Arcade.prototype = { // GROUPS else if (object1.type == Phaser.GROUP) { - if (object2.type == Phaser.SPRITE) + if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE) { this.overlapSpriteVsGroup(object2, object1, overlapCallback, processCallback, callbackContext); } @@ -35184,7 +38184,7 @@ Phaser.Physics.Arcade.prototype = { // EMITTER else if (object1.type == Phaser.EMITTER) { - if (object2.type == Phaser.SPRITE) + if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE) { this.overlapSpriteVsGroup(object2, object1, overlapCallback, processCallback, callbackContext); } @@ -35334,12 +38334,10 @@ Phaser.Physics.Arcade.prototype = { // Only collide valid objects if (object1 && object2 && object1.exists && object2.exists) { - // Can expand to support Buttons, Text, etc at a later date. For now these are the essentials. - // SPRITES - if (object1.type == Phaser.SPRITE) + if (object1.type == Phaser.SPRITE || object1.type == Phaser.TILESPRITE) { - if (object2.type == Phaser.SPRITE) + if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE) { this.collideSpriteVsSprite(object1, object2, collideCallback, processCallback, callbackContext); } @@ -35355,7 +38353,7 @@ Phaser.Physics.Arcade.prototype = { // GROUPS else if (object1.type == Phaser.GROUP) { - if (object2.type == Phaser.SPRITE) + if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE) { this.collideSpriteVsGroup(object2, object1, collideCallback, processCallback, callbackContext); } @@ -35371,7 +38369,7 @@ Phaser.Physics.Arcade.prototype = { // TILEMAP LAYERS else if (object1.type == Phaser.TILEMAPLAYER) { - if (object2.type == Phaser.SPRITE) + if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE) { this.collideSpriteVsTilemapLayer(object2, object1, collideCallback, processCallback, callbackContext); } @@ -35383,7 +38381,7 @@ Phaser.Physics.Arcade.prototype = { // EMITTER else if (object1.type == Phaser.EMITTER) { - if (object2.type == Phaser.SPRITE) + if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE) { this.collideSpriteVsGroup(object2, object1, collideCallback, processCallback, callbackContext); } @@ -35417,8 +38415,14 @@ Phaser.Physics.Arcade.prototype = { return; } - for (var i = 0; i < this._mapData.length; i++) + if (this._mapData.length > 1) { + // console.log(' multi sep ---------------------------------------------------------------------------------------------'); + this.separateTiles(sprite.body, this._mapData); + } + else + { + var i = 0; if (this.separateTile(sprite.body, this._mapData[i])) { // They collided, is there a custom process callback? @@ -35461,11 +38465,6 @@ Phaser.Physics.Arcade.prototype = { return; } - if (group.length === 0) - { - return; - } - if (group._container.first._iNext) { var currentNode = group._container.first._iNext; @@ -35602,7 +38601,14 @@ Phaser.Physics.Arcade.prototype = { */ separate: function (body1, body2) { - this._result = (this.separateX(body1, body2) || this.separateY(body1, body2)); + if (body1 !== body2) + { + this._result = (this.separateX(body1, body2) || this.separateY(body1, body2)); + } + else + { + this._result = false; + } }, @@ -35705,8 +38711,8 @@ Phaser.Physics.Arcade.prototype = { body2.x += this._overlap; body2.velocity.x = this._velocity1 - this._velocity2 * body2.bounce.x; } - body1.updateHulls(); - body2.updateHulls(); + // body1.updateHulls(); + // body2.updateHulls(); return true; } @@ -35807,13 +38813,13 @@ Phaser.Physics.Arcade.prototype = { } else if (!body1.immovable) { - body1.y = body1.y - this._overlap; + body1.y -= this._overlap; body1.velocity.y = this._velocity2 - this._velocity1 * body1.bounce.y; // This is special case code that handles things like horizontal moving platforms you can ride - if (body2.active && body2.moves && (body1.deltaY() > body2.deltaY())) + if (body2.moves) { - body1.x += body2.x - body2.lastX; + body1.x += body2.x - body2.preX; } } else if (!body2.immovable) @@ -35822,13 +38828,13 @@ Phaser.Physics.Arcade.prototype = { body2.velocity.y = this._velocity1 - this._velocity2 * body2.bounce.y; // This is special case code that handles things like horizontal moving platforms you can ride - if (body1.sprite.active && body1.moves && (body1.deltaY() < body2.deltaY())) + if (body1.moves) { - body2.x += body1.x - body1.lastX; + body2.x += body1.x - body1.preX; } } - body1.updateHulls(); - body2.updateHulls(); + // body1.updateHulls(); + // body2.updateHulls(); return true; } @@ -35839,6 +38845,144 @@ Phaser.Physics.Arcade.prototype = { }, + /** + * The core separation function to separate a physics body and an array of tiles. + * @method Phaser.Physics.Arcade#separateTiles + * @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate. + * @param {Phaser.Tile} tile - The tile to collide against. + * @returns {boolean} Returns true if the bodies were separated, otherwise false. + */ + separateTiles: function (body, tiles) { + + // Can't separate two immovable objects (tiles are always immovable) + if (body.immovable) + { + return false; + } + + body.overlapX = 0; + body.overlapY = 0; + + var tile; + var localOverlapX = 0; + var localOverlapY = 0; + + for (var i = 0; i < tiles.length; i++) + { + tile = tiles[i]; + + if (Phaser.Rectangle.intersects(body, tile)) + { + if (body.deltaX() < 0 && body.allowCollision.left && tile.tile.faceRight) + { + // LEFT + localOverlapX = body.x - tile.right; + + if (localOverlapX >= body.deltaX()) + { + // console.log('m left overlapX', localOverlapX, body.deltaX()); + // use touching instead of blocked? + body.blocked.left = true; + body.touching.left = true; + body.touching.none = false; + } + } + else if (body.deltaX() > 0 && body.allowCollision.right && tile.tile.faceLeft) + { + // RIGHT + localOverlapX = body.right - tile.x; + + // Distance check + if (localOverlapX <= body.deltaX()) + { + // console.log('m right overlapX', localOverlapX, body.deltaX()); + body.blocked.right = true; + body.touching.right = true; + body.touching.none = false; + } + } + + if (body.deltaY() < 0 && body.allowCollision.up && tile.tile.faceBottom) + { + // UP + localOverlapY = body.y - tile.bottom; + + // Distance check + if (localOverlapY >= body.deltaY()) + { + // console.log('m up overlapY', localOverlapY, body.deltaY()); + body.blocked.up = true; + body.touching.up = true; + body.touching.none = false; + } + } + else if (body.deltaY() > 0 && body.allowCollision.down && tile.tile.faceTop) + { + // DOWN + localOverlapY = body.bottom - tile.y; + + if (localOverlapY <= body.deltaY()) + { + // console.log('m down overlapY', localOverlapY, body.deltaY()); + body.blocked.down = true; + body.touching.down = true; + body.touching.none = false; + } + } + } + } + + if (localOverlapX !== 0) + { + body.overlapX = localOverlapX; + } + + if (localOverlapY !== 0) + { + body.overlapY = localOverlapY; + } + + if (body.touching.none) + { + return false; + } + + // if (body.overlapX !== 0) + if (body.touching.left || body.touching.right) + { + body.x -= body.overlapX; + body.preX -= body.overlapX; + + if (body.bounce.x === 0) + { + body.velocity.x = 0; + } + else + { + body.velocity.x = -body.velocity.x * body.bounce.x; + } + } + + // if (body.overlapY !== 0) + if (body.touching.up || body.touching.down) + { + body.y -= body.overlapY; + body.preY -= body.overlapY; + + if (body.bounce.y === 0) + { + body.velocity.y = 0; + } + else + { + body.velocity.y = -body.velocity.y * body.bounce.y; + } + } + + return true; + + }, + /** * The core separation function to separate a physics body and a tile. * @method Phaser.Physics.Arcade#separateTile @@ -35848,182 +38992,124 @@ Phaser.Physics.Arcade.prototype = { */ separateTile: function (body, tile) { - this._result = (this.separateTileX(body, tile, true) || this.separateTileY(body, tile, true)); - - return this._result; - - }, - - /** - * The core separation function to separate a physics body and a tile on the x axis. - * @method Phaser.Physics.Arcade#separateTileX - * @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate. - * @param {Phaser.Tile} tile - The tile to collide against. - * @returns {boolean} Returns true if the bodies were separated, otherwise false. - */ - separateTileX: function (body, tile, separate) { - // Can't separate two immovable objects (tiles are always immovable) - if (body.immovable || body.deltaX() === 0 || Phaser.Rectangle.intersects(body.hullX, tile) === false) + if (body.immovable || Phaser.Rectangle.intersects(body, tile) === false) { + // console.log('no intersects'); + // console.log('tx', tile.x, 'ty', tile.y, 'tw', tile.width, 'th', tile.height, 'tr', tile.right, 'tb', tile.bottom); + // console.log('bx', body.x, 'by', body.y, 'bw', body.width, 'bh', body.height, 'br', body.right, 'bb', body.bottom); return false; } - this._overlap = 0; + // use body var instead + body.overlapX = 0; + body.overlapY = 0; - // The hulls overlap, let's process it - // this._maxOverlap = body.deltaAbsX() + this.OVERLAP_BIAS; + // Remember - this happens AFTER the body has been moved by the motion update, so it needs moving back again + // console.log('---------------------------------------------------------------------------------------------'); + // console.log('tx', tile.x, 'ty', tile.y, 'tw', tile.width, 'th', tile.height, 'tr', tile.right, 'tb', tile.bottom); + // console.log('bx', body.x, 'by', body.y, 'bw', body.width, 'bh', body.height, 'br', body.right, 'bb', body.bottom); + // console.log(Phaser.Rectangle.intersects(body, tile)); + // console.log('dx', body.deltaX(), 'dy', body.deltaY(), 'dax', body.deltaAbsX(), 'day', body.deltaAbsY(), 'cax', Math.ceil(body.deltaAbsX()), 'cay', Math.ceil(body.deltaAbsY())); - if (body.deltaX() < 0) + if (body.deltaX() < 0 && body.allowCollision.left && tile.tile.faceRight) { - // Moving left - this._overlap = tile.right - body.hullX.x; + // LEFT + body.overlapX = body.x - tile.right; - // if ((this._overlap > this._maxOverlap) || body.allowCollision.left === false || tile.tile.collideRight === false) - if (body.allowCollision.left === false || tile.tile.collideRight === false) - { - this._overlap = 0; - } - else + if (body.overlapX >= body.deltaX()) { + // console.log('left overlapX', body.overlapX, body.deltaX()); + // use touching instead of blocked? + body.blocked.left = true; body.touching.left = true; + body.touching.none = false; } } - else + else if (body.deltaX() > 0 && body.allowCollision.right && tile.tile.faceLeft) { - // Moving right - this._overlap = body.hullX.right - tile.x; + // RIGHT + body.overlapX = body.right - tile.x; - // if ((this._overlap > this._maxOverlap) || body.allowCollision.right === false || tile.tile.collideLeft === false) - if (body.allowCollision.right === false || tile.tile.collideLeft === false) - { - this._overlap = 0; - } - else + // Distance check + if (body.overlapX <= body.deltaX()) { + // console.log('right overlapX', body.overlapX, body.deltaX()); + body.blocked.right = true; body.touching.right = true; + body.touching.none = false; } } - // Then adjust their positions and velocities accordingly (if there was any overlap) - if (this._overlap !== 0) + if (body.deltaY() < 0 && body.allowCollision.up && tile.tile.faceBottom) { - if (separate) - { - if (body.deltaX() < 0) - { - body.x = body.x + this._overlap; - } - else - { - body.x = body.x - this._overlap; - } - - if (body.bounce.x === 0) - { - body.velocity.x = 0; - } - else - { - body.velocity.x = -body.velocity.x * body.bounce.x; - } - - body.updateHulls(); - } - - return true; - } - else - { - return false; - } - - }, - - /** - * The core separation function to separate a physics body and a tile on the x axis. - * @method Phaser.Physics.Arcade#separateTileY - * @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate. - * @param {Phaser.Tile} tile - The tile to collide against. - * @returns {boolean} Returns true if the bodies were separated, otherwise false. - */ - separateTileY: function (body, tile, separate) { - - // Can't separate two immovable objects (tiles are always immovable) - if (body.immovable || body.deltaY() === 0 || Phaser.Rectangle.intersects(body.hullY, tile) === false) - { - return false; - } - - this._overlap = 0; - - // The hulls overlap, let's process it - // this._maxOverlap = body.deltaAbsY() + this.OVERLAP_BIAS; - - if (body.deltaY() < 0) - { - // Moving up - this._overlap = tile.bottom - body.hullY.y; - - // if ((this._overlap > this._maxOverlap) || body.allowCollision.up === false || tile.tile.collideDown === false) - if (body.allowCollision.up === false || tile.tile.collideDown === false) - { - this._overlap = 0; - } - else + // UP + body.overlapY = body.y - tile.bottom; + + // Distance check + if (body.overlapY >= body.deltaY()) { + // console.log('up overlapY', body.overlapY, body.deltaY()); + body.blocked.up = true; body.touching.up = true; + body.touching.none = false; } } - else + else if (body.deltaY() > 0 && body.allowCollision.down && tile.tile.faceTop) { - // Moving down - this._overlap = body.hullY.bottom - tile.y; + // DOWN + body.overlapY = body.bottom - tile.y; - // if ((this._overlap > this._maxOverlap) || body.allowCollision.down === false || tile.tile.collideUp === false) - if (body.allowCollision.down === false || tile.tile.collideUp === false) - { - this._overlap = 0; - } - else + if (body.overlapY <= body.deltaY()) { + // console.log('down overlapY', body.overlapY, body.deltaY()); + body.blocked.down = true; body.touching.down = true; + body.touching.none = false; } } - // Then adjust their positions and velocities accordingly (if there was any overlap) - if (this._overlap !== 0) - { - if (separate) - { - if (body.deltaY() < 0) - { - body.y = body.y + this._overlap; - } - else - { - body.y = body.y - this._overlap; - } + // Separate in a single sweep - if (body.bounce.y === 0) - { - body.velocity.y = 0; - } - else - { - body.velocity.y = -body.velocity.y * body.bounce.y; - } - - body.updateHulls(); - } - - return true; - } - else + if (body.touching.none) { return false; } + // if (body.overlapX !== 0) + if (body.touching.left || body.touching.right) + { + body.x -= body.overlapX; + body.preX -= body.overlapX; + + if (body.bounce.x === 0) + { + body.velocity.x = 0; + } + else + { + body.velocity.x = -body.velocity.x * body.bounce.x; + } + } + + // if (body.overlapY !== 0) + if (body.touching.up || body.touching.down) + { + body.y -= body.overlapY; + body.preY -= body.overlapY; + + if (body.bounce.y === 0) + { + body.velocity.y = 0; + } + else + { + body.velocity.y = -body.velocity.y * body.bounce.y; + } + } + + return true; + }, /** @@ -36172,7 +39258,7 @@ Phaser.Physics.Arcade.prototype = { /** * Given the rotation (in radians) and speed calculate the acceleration and return it as a Point object, or set it to the given point object. - * One way to use this is: velocityFromRotation(rotation, 200, sprite.velocity) which will set the values directly to the sprites velocity and not create a new Point object. + * One way to use this is: accelerationFromRotation(rotation, 200, sprite.acceleration) which will set the values directly to the sprites acceleration and not create a new Point object. * * @method Phaser.Physics.Arcade#accelerationFromRotation * @param {number} rotation - The angle in radians. @@ -36392,6 +39478,8 @@ Phaser.Physics.Arcade.prototype = { }; +Phaser.Physics.Arcade.prototype.constructor = Phaser.Physics.Arcade; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -36515,23 +39603,37 @@ Phaser.Physics.Arcade.Body = function (sprite) { */ this._sy = sprite.scale.y; + /** + * @property {Phaser.Point} motionVelocity - The data from the updateMotion function. + */ + this.motionVelocity = new Phaser.Point(); + /** * @property {Phaser.Point} velocity - The velocity in pixels per second sq. of the Body. */ this.velocity = new Phaser.Point(); + /** + * @property {Phaser.Point} prevVelocity - The velocity in pixels per second sq. of the Body. + */ + this.prevVelocity = new Phaser.Point(); + /** * @property {Phaser.Point} acceleration - The velocity in pixels per second sq. of the Body. */ this.acceleration = new Phaser.Point(); + this.speed = 0; + this.angle = 0; + + /** * @property {Phaser.Point} drag - The drag applied to the motion of the Body. */ this.drag = new Phaser.Point(); /** - * @property {Phaser.Point} gravity - A private Gravity setting for the Body. + * @property {Phaser.Point} gravity - The gravity applied to the motion of the Body. */ this.gravity = new Phaser.Point(); @@ -36601,6 +39703,7 @@ Phaser.Physics.Arcade.Body = function (sprite) { * For example allowCollision.up = false means it won't collide when the collision happened while moving up. * @property {object} allowCollision - An object containing allowed collision. */ + // This would be faster as an array this.allowCollision = { none: false, any: true, up: true, down: true, left: true, right: true }; /** @@ -36608,12 +39711,14 @@ Phaser.Physics.Arcade.Body = function (sprite) { * touching.up = true means the collision happened to the top of this Body for example. * @property {object} touching - An object containing touching results. */ + // This would be faster as an array this.touching = { none: true, up: false, down: false, left: false, right: false }; /** * This object is populated with previous touching values from the bodies previous collision. * @property {object} wasTouching - An object containing previous touching results. */ + // This would be faster as an array this.wasTouching = { none: true, up: false, down: false, left: false, right: false }; /** @@ -36623,7 +39728,7 @@ Phaser.Physics.Arcade.Body = function (sprite) { this.facing = Phaser.NONE; /** - * @property {boolean} immovable - An immovable Body will not receive any impacts from other bodies. + * @property {boolean} immovable - An immovable Body will not receive any impacts or exchanges of velocity from other bodies. * @default */ this.immovable = false; @@ -36681,14 +39786,18 @@ Phaser.Physics.Arcade.Body = function (sprite) { this.overlapY = 0; /** - * @property {Phaser.Rectangle} hullX - The dynamically calculated hull used during collision. + * @property {boolean} canSleep - A Body that canSleep will have its velocity set to zero if it falls below sleepThreshold for longer than sleepDuration. + * @default */ - this.hullX = new Phaser.Rectangle(); - - /** - * @property {Phaser.Rectangle} hullY - The dynamically calculated hull used during collision. - */ - this.hullY = new Phaser.Rectangle(); + this.sleeping = false; + this.canSleep = true; + this.sleepMin = new Phaser.Point(-20, -20); + this.sleepMax = new Phaser.Point(20, 20); + this.sleepDuration = 2000; // ms + this._sleepTimer = 0; // ms + this._drag = 0; + this._debug = 0; + this.friction = 0; /** * If a body is overlapping with another body, but neither of them are moving (maybe they spawned on-top of each other?) this is set to true. @@ -36702,6 +39811,8 @@ Phaser.Physics.Arcade.Body = function (sprite) { */ this.collideWorldBounds = false; + this.blocked = { up: false, down: false, left: false, right: false }; + }; Phaser.Physics.Arcade.Body.prototype = { @@ -36755,23 +39866,56 @@ Phaser.Physics.Arcade.Body.prototype = { this.preX = (this.sprite.world.x - (this.sprite.anchor.x * this.width)) + this.offset.x; this.preY = (this.sprite.world.y - (this.sprite.anchor.y * this.height)) + this.offset.y; - this.preRotation = this.sprite.angle; + if (this.canSleep && this.sleeping && (this.velocity.equals(this.prevVelocity) === false || this.acceleration.isZero() === false)) + { + this.sleeping = false; + this._sleepTimer = 0; + } + this.x = this.preX; this.y = this.preY; this.rotation = this.preRotation; + this.speed = Math.sqrt(this.velocity.x * this.velocity.x + this.velocity.y * this.velocity.y); + this.angle = Math.atan2(this.velocity.y, this.velocity.x); + + this.blocked.up = false; + this.blocked.down = false; + this.blocked.left = false; + this.blocked.right = false; + if (this.moves) { this.game.physics.updateMotion(this); - if (this.collideWorldBounds) + if (this.canSleep) { - this.checkWorldBounds(); + if (!this.sleeping) + { + if (this.velocity.x >= this.sleepMin.x && this.velocity.x <= this.sleepMax.x && this.velocity.y >= this.sleepMin.y && this.velocity.y <= this.sleepMax.y) + { + if (this._sleepTimer >= this.sleepDuration) + { + this.sleeping = true; + } + else + { + this._sleepTimer += this.game.time.elapsed; + this.applyMotion(); + } + } + else + { + this.applyMotion(); + } + } + } + else + { + this.applyMotion(); } - - this.updateHulls(); } if (this.skipQuadTree === false && this.allowCollision.none === false && this.sprite.visible && this.sprite.alive) @@ -36781,89 +39925,154 @@ Phaser.Physics.Arcade.Body.prototype = { this.game.physics.quadTree.insert(this); } + this.prevVelocity.copyFrom(this.velocity); + + }, + + applyMotion: function () { + + if (this.friction > 0 && this.acceleration.isZero()) + { + if (this.speed > this.friction) + { + this.speed -= this.friction; + } + else + { + this.speed = 0; + } + + this.velocity.x = Math.cos(this.angle) * this.speed; + this.velocity.y = Math.sin(this.angle) * this.speed; + } + + this.x += this.game.time.physicsElapsed * (this.velocity.x + this.motionVelocity.x / 2); + this.velocity.x += this.motionVelocity.x; + + this.y += this.game.time.physicsElapsed * (this.velocity.y + this.motionVelocity.y / 2); + this.velocity.y += this.motionVelocity.y; + + if (this.velocity.x > this.maxVelocity.x) + { + this.velocity.x = this.maxVelocity.x; + } + else if (this.velocity.x < -this.maxVelocity.x) + { + this.velocity.x = -this.maxVelocity.x; + } + + if (this.velocity.y > this.maxVelocity.y) + { + this.velocity.y = this.maxVelocity.y; + } + else if (this.velocity.y < -this.maxVelocity.y) + { + this.velocity.y = -this.maxVelocity.y; + } + + if (this.collideWorldBounds) + { + this.checkWorldBounds(); + + if (this.blocked.left || this.blocked.right) + { + // this.preX = this.x; + } + + if (this.blocked.up || this.blocked.down) + { + // this.preX = this.x; + } + } + }, /** - * Internal method. + * Internal method. This is called directly before the sprites are sent to the renderer. * * @method Phaser.Physics.Arcade#postUpdate * @protected */ postUpdate: function () { - if (this.deltaX() < 0) + if (this.moves) { - this.facing = Phaser.LEFT; - } - else if (this.deltaX() > 0) - { - this.facing = Phaser.RIGHT; - } + if (this.deltaX() < 0 && this.blocked.left === false) + { + this.facing = Phaser.LEFT; + this.sprite.x += this.deltaX(); + } + else if (this.deltaX() > 0 && this.blocked.right === false) + { + this.facing = Phaser.RIGHT; + this.sprite.x += this.deltaX(); + } - if (this.deltaY() < 0) - { - this.facing = Phaser.UP; - } - else if (this.deltaY() > 0) - { - this.facing = Phaser.DOWN; - } + if (this.deltaY() < 0 && this.blocked.up === false) + { + this.facing = Phaser.UP; + this.sprite.y += this.deltaY(); + } + else if (this.deltaY() > 0 && this.blocked.down === false) + { + this.facing = Phaser.DOWN; + this.sprite.y += this.deltaY(); + } + + if (this.collideWorldBounds) + { + this.checkWorldBounds(); + } - if (this.deltaX() !== 0 || this.deltaY() !== 0) - { - this.sprite.x += this.deltaX(); - this.sprite.y += this.deltaY(); this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight); - } - if (this.allowRotation) - { - this.sprite.angle += this.deltaZ(); + if (this.allowRotation) + { + this.sprite.angle += this.deltaZ(); + } } }, /** - * Internal method. - * - * @method Phaser.Physics.Arcade#updateHulls - * @protected - */ - updateHulls: function () { - - this.hullX.setTo(this.x, this.preY, this.width, this.height); - this.hullY.setTo(this.preX, this.y, this.width, this.height); - - }, - - /** - * Internal method. + * Internal method used to check the Body against the World Bounds. * * @method Phaser.Physics.Arcade#checkWorldBounds * @protected */ checkWorldBounds: function () { + var vx = this.velocity.x; + var vy = this.velocity.y; + if (this.x < this.game.world.bounds.x) { + this.blocked.left = true; this.x = this.game.world.bounds.x; this.velocity.x *= -this.bounce.x; + // console.log(this._debug, 'hit left', vx,'to',this.velocity.x); } else if (this.right > this.game.world.bounds.right) { + this.blocked.right = true; this.x = this.game.world.bounds.right - this.width; this.velocity.x *= -this.bounce.x; + // console.log(this._debug, 'hit right', vx,'to',this.velocity.x); } if (this.y < this.game.world.bounds.y) { + this.blocked.up = true; this.y = this.game.world.bounds.y; this.velocity.y *= -this.bounce.y; + // console.log(this._debug, 'hit top', vy,'to',this.velocity.y); } else if (this.bottom > this.game.world.bounds.bottom) { + this.blocked.down = true; this.y = this.game.world.bounds.bottom - this.height; this.velocity.y *= -this.bounce.y; + // console.log(this._debug, 'hit bottom', vy,'to',this.velocity.y); } }, @@ -36944,7 +40153,7 @@ Phaser.Physics.Arcade.Body.prototype = { * Returns the delta x value. The difference between Body.x now and in the previous step. * * @method Phaser.Physics.Arcade.Body#deltaX - * @return {number} The delta value. + * @return {number} The delta value. Positive if the motion was to the right, negative if to the left. */ deltaX: function () { return this.x - this.preX; @@ -36954,7 +40163,7 @@ Phaser.Physics.Arcade.Body.prototype = { * Returns the delta y value. The difference between Body.y now and in the previous step. * * @method Phaser.Physics.Arcade.Body#deltaY - * @return {number} The delta value. + * @return {number} The delta value. Positive if the motion was downwards, negative if upwards. */ deltaY: function () { return this.y - this.preY; @@ -36966,6 +40175,8 @@ Phaser.Physics.Arcade.Body.prototype = { }; +Phaser.Physics.Arcade.Body.prototype.constructor = Phaser.Physics.Arcade.Body; + /** * @name Phaser.Physics.Arcade.Body#bottom * @property {number} bottom - The bottom value of this Body (same as Body.y + Body.height) @@ -36978,7 +40189,7 @@ Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "bottom", { * @return {number} */ get: function () { - return this.y + this.height; + return Math.floor(this.y + this.height); }, /** @@ -37014,7 +40225,7 @@ Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "right", { * @return {number} */ get: function () { - return this.x + this.width; + return Math.floor(this.x + this.width); }, /** @@ -37117,6 +40328,9 @@ Phaser.Particles.prototype = { } }; + +Phaser.Particles.prototype.constructor = Phaser.Particles; + Phaser.Particles.Arcade = {} /** * @author Richard Davey @@ -37801,30 +41015,34 @@ Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "bottom", { */ /** -* Create a new `Tile` object. Tiles live inside of Tilesets and are rendered via TilemapLayers. +* Create a new `Tile` object. * * @class Phaser.Tile -* @classdesc A Tile is a single representation of a tile within a Tilemap. +* @classdesc A Tile is a representation of a single tile within the Tilemap. * @constructor -* @param {Phaser.Tileset} tileset - The tileset this tile belongs to. * @param {number} index - The index of this tile type in the core map data. * @param {number} x - The x coordinate of this tile. * @param {number} y - The y coordinate of this tile. * @param {number} width - Width of the tile. * @param {number} height - Height of the tile. */ -Phaser.Tile = function (tileset, index, x, y, width, height) { +Phaser.Tile = function (index, x, y, width, height) { /** - * @property {Phaser.Tileset} tileset - The tileset this tile belongs to. - */ - this.tileset = tileset; - - /** - * @property {number} index - The index of this tile within the tileset. + * @property {number} index - The index of this tile within the map. */ this.index = index; + /** + * @property {number} x - The x map coordinate of this tile. + */ + this.x = x; + + /** + * @property {number} y - The y map coordinate of this tile. + */ + this.y = y; + /** * @property {number} width - The width of the tile in pixels. */ @@ -37836,22 +41054,39 @@ Phaser.Tile = function (tileset, index, x, y, width, height) { this.height = height; /** - * @property {number} x - The top-left corner of the tile within the tileset. + * @property {number} alpha - The alpha value at which this tile is drawn to the canvas. */ - this.x = x; - - /** - * @property {number} y - The top-left corner of the tile within the tileset. - */ - this.y = y; - - // Any extra meta data info we need here + this.alpha = 1; /** - * @property {number} mass - The virtual mass of the tile. - * @default + * @property {object} properties - Tile specific properties. */ - this.mass = 1.0; + this.properties = {}; + + /** + * @property {boolean} faceTop - Is the top of this tile an interesting edge? + */ + this.faceTop = false; + + /** + * @property {boolean} faceBottom - Is the bottom of this tile an interesting edge? + */ + this.faceBottom = false; + + /** + * @property {boolean} faceLeft - Is the left of this tile an interesting edge? + */ + this.faceLeft = false; + + /** + * @property {boolean} faceRight - Is the right of this tile an interesting edge? + */ + this.faceRight = false; + + /** + * @property {boolean} collides - Does this tile collide at all? + */ + this.collides = false; /** * @property {boolean} collideNone - Indicating this Tile doesn't collide at all. @@ -37887,13 +41122,13 @@ Phaser.Tile = function (tileset, index, x, y, width, height) { * @property {boolean} separateX - Enable separation at x-axis. * @default */ - this.separateX = true; + // this.separateX = true; /** * @property {boolean} separateY - Enable separation at y-axis. * @default */ - this.separateY = true; + // this.separateY = true; /** * @property {boolean} collisionCallback - Tilemap collision callback. @@ -37931,7 +41166,9 @@ Phaser.Tile.prototype = { */ destroy: function () { - this.tileset = null; + this.collisionCallback = null; + this.collisionCallbackContext = null; + this.properties = null; }, @@ -37977,6 +41214,8 @@ Phaser.Tile.prototype = { }; +Phaser.Tile.prototype.constructor = Phaser.Tile; + /** * @name Phaser.Tile#bottom * @property {number} bottom - The sum of the y and height properties. @@ -38026,22 +41265,52 @@ Phaser.Tilemap = function (game, key) { this.game = game; /** - * @property {array} layers - An array of Tilemap layers. + * @property {string} key - The key of this map data in the Phaser.Cache. */ - this.layers = null; + this.key = key; - if (typeof key === 'string') - { - this.key = key; + var data = Phaser.TilemapParser.parse(this.game, key); - this.layers = game.cache.getTilemapData(key).layers; - this.calculateIndexes(); - } - else + if (data === null) { - this.layers = []; + return; } + this.width = data.width; + this.height = data.height; + this.tileWidth = data.tileWidth; + this.tileHeight = data.tileHeight; + this.orientation = data.orientation; + this.version = data.version; + this.properties = data.properties; + this.widthInPixels = data.widthInPixels; + this.heightInPixels = data.heightInPixels; + + /** + * @property {array} layers - An array of Tilemap layer data. + */ + this.layers = data.layers; + + /** + * @property {array} tilesets - An array of Tilesets. + */ + this.tilesets = data.tilesets; + + /** + * @property {array} tiles - The super array of Tiles. + */ + this.tiles = data.tiles; + + /** + * @property {array} objects - An array of Tiled Object Layers. + */ + this.objects = data.objects; + + /** + * @property {array} images - An array of Tiled Image Layers. + */ + this.images = data.images; + /** * @property {number} currentLayer - The current layer. */ @@ -38050,14 +41319,8 @@ Phaser.Tilemap = function (game, key) { /** * @property {array} debugMap - Map data used for debug values only. */ - this.debugMap = []; - /** - * @property {boolean} dirty - Internal rendering related flag. - */ - this.dirty = false; - /** * @property {array} _results - Internal var. * @private @@ -38125,36 +41388,397 @@ Phaser.Tilemap.prototype = { tileSpacing: 0, format: Phaser.Tilemap.CSV, data: data, - indexes: [] + indexes: [], + dirty: true }); this.currentLayer = this.layers.length - 1; - this.dirty = true; + }, + + addTilesetImage: function (tileset, key) { + + if (typeof key === 'undefined') + { + if (typeof tileset === 'string') + { + key = tileset; + } + else + { + return false; + } + } + + if (typeof tileset === 'string') + { + tileset = this.getTilesetIndex(tileset); + } + + if (this.tilesets[tileset]) + { + this.tilesets[tileset].image = this.game.cache.getImage(key); + + return true; + } + + return false; + + }, + + // Region? Remove tile from map data? + createFromTiles: function (layer, tileIndex, key, frame, group) { + + if (typeof group === 'undefined') { group = this.game.world; } }, /** - * Internal function that calculates the tile indexes for the map data. + * Creates a Sprite for every object matching the given gid in the map data. You can optionally specify the group that the Sprite will be created in. If none is + * given it will be created in the World. All properties from the map data objectgroup are copied across to the Sprite, so you can use this as an easy way to + * configure Sprite properties from within the map editor. For example giving an object a property if alpha: 0.5 in the map editor will duplicate that when the + * Sprite is created. You could also give it a value like: body.velocity.x: 100 to set it moving automatically. * - * @method Phaser.Tilemap#calculateIndexes + * @method Phaser.Tileset#createFromObjects + * @param {string} name - The name of the Object Group to create Sprites from. + * @param {number} gid - The layer array index value, or if a string is given the layer name, within the map data that this TilemapLayer represents. + * @param {string} key - The Game.cache key of the image that this Sprite will use. + * @param {number|string} [frame] - If the Sprite image contains multiple frames you can specify which one to use here. + * @param {boolean} [exists=true] - The default exists state of the Sprite. + * @param {boolean} [autoCull=true] - The default autoCull state of the Sprite. Sprites that are autoCulled are culled from the camera if out of its range. + * @param {Phaser.Group} [group] - Optional Group to add the Sprite to. If not specified it will be added to the World group. */ - calculateIndexes: function () { + createFromObjects: function (name, gid, key, frame, exists, autoCull, group) { - for (var layer = 0; layer < this.layers.length; layer++) + if (typeof exists === 'undefined') { exists = true; } + if (typeof autoCull === 'undefined') { autoCull = true; } + if (typeof group === 'undefined') { group = this.game.world; } + + if (!this.objects[name]) { - this.layers[layer].indexes = []; + console.warn('Tilemap.createFromObjects: Invalid objectgroup name given: ' + name); + return; + } - for (var y = 0; y < this.layers[layer].height ; y++) + var sprite; + + for (var i = 0, len = this.objects[name].length; i < len; i++) + { + if (this.objects[name][i].gid === gid) { - for (var x = 0; x < this.layers[layer].width; x++) - { - var idx = this.layers[layer].data[y][x]; + sprite = group.create(this.objects[name][i].x, this.objects[name][i].y, key, frame, exists); - if (this.layers[layer].indexes.indexOf(idx) === -1) + sprite.anchor.setTo(0, 1); + sprite.name = this.objects[name][i].name; + sprite.visible = this.objects[name][i].visible; + sprite.autoCull = autoCull; + + for (property in this.objects[name][i].properties) + { + group.set(sprite, property, this.objects[name][i].properties[property], false, false, 0); + } + } + } + + }, + + /** + * Creates a new TilemapLayer object. By default TilemapLayers are fixed to the camera. + * + * @method Phaser.Tileset#createLayer + * @param {number|string} layer - The layer array index value, or if a string is given the layer name, within the map data that this TilemapLayer represents. + * @param {number} [width] - The rendered width of the layer, should never be wider than Game.width. If not given it will be set to Game.width. + * @param {number} [height] - The rendered height of the layer, should never be wider than Game.height. If not given it will be set to Game.height. + * @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group. + * @return {Phaser.TilemapLayer} The TilemapLayer object. This is an extension of Phaser.Sprite and can be moved around the display list accordingly. + */ + createLayer: function (layer, width, height, group) { + + // Add Buffer support for the left of the canvas + + if (typeof width === 'undefined') { width = this.game.width; } + if (typeof height === 'undefined') { height = this.game.height; } + if (typeof group === 'undefined') { group = this.game.world; } + + var index = layer; + + if (typeof layer === 'string') + { + index = this.getLayerIndex(layer); + } + + if (index === null || index > this.layers.length) + { + console.warn('Tilemap.createLayer: Invalid layer ID given: ' + index); + return; + } + + return group.add(new Phaser.TilemapLayer(this.game, this, index, width, height)); + + }, + + /** + * Gets the layer index based on a layer name. + * + * @method Phaser.Tileset#getIndex + * @param {array} location - The local array to search. + * @param {string} name - The name of the array element to get. + * @return {number} The index of the element in the array, or null if not found. + */ + getIndex: function (location, name) { + + for (var i = 0; i < location.length; i++) + { + if (location[i].name === name) + { + return i; + } + } + + return null; + + }, + + /** + * Gets the layer index based on its name. + * + * @method Phaser.Tileset#getLayerIndex + * @param {string} name - The name of the layer to get. + * @return {number} The index of the layer in this tilemap, or null if not found. + */ + getLayerIndex: function (name) { + + return this.getIndex(this.layers, name); + + }, + + /** + * Gets the tileset index based on its name. + * + * @method Phaser.Tileset#getTilesetIndex + * @param {string} name - The name of the tileset to get. + * @return {number} The index of the tileset in this tilemap, or null if not found. + */ + getTilesetIndex: function (name) { + + return this.getIndex(this.tilesets, name); + + }, + + /** + * Gets the image index based on its name. + * + * @method Phaser.Tileset#getImageIndex + * @param {string} name - The name of the image to get. + * @return {number} The index of the image in this tilemap, or null if not found. + */ + getImageIndex: function (name) { + + return this.getIndex(this.images, name); + + }, + + /** + * Gets the object index based on its name. + * + * @method Phaser.Tileset#getObjectIndex + * @param {string} name - The name of the object to get. + * @return {number} The index of the object in this tilemap, or null if not found. + */ + getObjectIndex: function (name) { + + return this.getIndex(this.objects, name); + + }, + + // TODO - set collision in an area, REMOVE collision + + /** + * Sets collision on all tiles in the given layer, except for the IDs of those in the given array. + * + * @method Phaser.Tileset#setCollisionByExclusion + * @param {array} indexes - An array of the tile IDs to not be counted for collision. + * @param {number|string|Phaser.TilemapLayer} layer - The layer to operate on. If not given will default to this.currentLayer. + */ + setCollisionByExclusion: function (indexes, layer) { + + if (typeof layer === 'undefined') + { + layer = this.currentLayer; + } + + // Collide everything, except the IDs given in the indexes array + for (var i = 0, len = this.tiles.length; i < len; i++) + { + if (indexes.indexOf(i) === -1) + { + this.setCollisionByIndex(i, layer, false); + } + } + + // Now re-calculate interesting faces + this.calculateFaces(layer); + + }, + + /** + * Sets collision the given tile index, or array of tiles indexes. + * + * @method Phaser.Tileset#setCollision + * @param {number|array} indexes - Either a single tile index, or an array of tile IDs to be checked for collision. + * @param {number|string|Phaser.TilemapLayer} layer - The layer to operate on. If not given will default to this.currentLayer. + */ + setCollision: function (indexes, layer) { + + if (typeof layer === 'undefined') + { + layer = this.currentLayer; + } + + if (typeof indexes === 'number') + { + return this.setCollisionByIndex(indexes, layer); + } + + // Collide all of the IDs given in the indexes array + for (var i = 0, len = indexes.length; i < len; i++) + { + this.setCollisionByIndex(i, layer, false); + } + + // Now re-calculate interesting faces + this.calculateFaces(layer); + + }, + + /** + * Sets collision on a range of tiles. + * + * @method Phaser.Tileset#setCollisionBetween + * @param {number} start - The first index of the tile to be set for collision. + * @param {number} stop - The last index of the tile to be set for collision. + * @param {number|string|Phaser.TilemapLayer} layer - The layer to operate on. If not given will default to this.currentLayer. + */ + setCollisionBetween: function (start, stop, layer) { + + if (start > stop) + { + return; + } + + for (var i = start; i <= stop; i++) + { + var index = this.setCollisionByIndex(i, layer, false); + } + + // Now re-calculate interesting faces + this.calculateFaces(index); + + }, + + /** + * Sets collision values on a tile in the set. + * + * @method Phaser.Tileset#setCollisionByIndex + * @param {number} index - The index of the tile on the layer. + * @param {number|string|Phaser.TilemapLayer} layer - The layer to operate on. If not given will default to this.currentLayer. + * @param {boolean} [recalculate=true] - Recalculates the tile faces after the update. + */ + setCollisionByIndex: function (index, layer, recalculate) { + + if (typeof layer === 'undefined') + { + layer = this.currentLayer; + } + else if (typeof layer === 'string') + { + layer = this.getLayerIndex(layer); + } + else if (layer instanceof Phaser.TilemapLayer) + { + layer = layer.index; + } + + if (typeof recalculate === "undefined") { recalculate = true; } + + for (var y = 0; y < this.layers[layer].height ; y++) + { + for (var x = 0; x < this.layers[layer].width; x++) + { + var tile = this.layers[layer].data[y][x]; + + if (tile && tile.index === index) + { + tile.collides = true; + tile.faceTop = true; + tile.faceBottom = true; + tile.faceLeft = true; + tile.faceRight = true; + } + } + } + + if (recalculate) + { + // Now re-calculate interesting faces + this.calculateFaces(layer); + } + + return layer; + + }, + + /** + * Internal function. + * + * @method Phaser.Tileset#calculateFaces + * @param {number} layer - The layer to operate on. + */ + calculateFaces: function (layer) { + + var above = null; + var below = null; + var left = null; + var right = null; + + // console.log(this.layers[layer].width, 'x', this.layers[layer].height); + + for (var y = 0, h = this.layers[layer].height; y < h; y++) + { + for (var x = 0, w = this.layers[layer].width; x < w; x++) + { + var tile = this.layers[layer].data[y][x]; + + if (tile) + { + above = this.getTileAbove(layer, x, y); + below = this.getTileBelow(layer, x, y); + left = this.getTileLeft(layer, x, y); + right = this.getTileRight(layer, x, y); + + if (above && above.collides) { - this.layers[layer].indexes.push(idx); + // There is a tile above this one that also collides, so the top of this tile is no longer interesting + tile.faceTop = false; + } + + if (below && below.collides) + { + // There is a tile below this one that also collides, so the bottom of this tile is no longer interesting + tile.faceBottom = false; + } + + if (left && left.collides) + { + // There is a tile left this one that also collides, so the left of this tile is no longer interesting + tile.faceLeft = false; + } + + if (right && right.collides) + { + // There is a tile right this one that also collides, so the right of this tile is no longer interesting + tile.faceRight = false; } } } @@ -38162,6 +41786,82 @@ Phaser.Tilemap.prototype = { }, + /** + * Internal function. + * + * @method Phaser.Tileset#getTileAbove + * @param {number} layer - The layer to operate on. + * @param {number} x - X. + * @param {number} y - Y. + */ + getTileAbove: function (layer, x, y) { + + if (y > 0) + { + return this.layers[layer].data[y - 1][x]; + } + + return null; + + }, + + /** + * Internal function. + * + * @method Phaser.Tileset#getTileBelow + * @param {number} layer - The layer to operate on. + * @param {number} x - X. + * @param {number} y - Y. + */ + getTileBelow: function (layer, x, y) { + + if (y < this.layers[layer].height - 1) + { + return this.layers[layer].data[y + 1][x]; + } + + return null; + + }, + + /** + * Internal function. + * + * @method Phaser.Tileset#getTileLeft + * @param {number} layer - The layer to operate on. + * @param {number} x - X. + * @param {number} y - Y. + */ + getTileLeft: function (layer, x, y) { + + if (x > 0) + { + return this.layers[layer].data[y][x - 1]; + } + + return null; + + }, + + /** + * Internal function. + * + * @method Phaser.Tileset#getTileRight + * @param {number} layer - The layer to operate on. + * @param {number} x - X. + * @param {number} y - Y. + */ + getTileRight: function (layer, x, y) { + + if (x < this.layers[layer].width - 1) + { + return this.layers[layer].data[y][x + 1]; + } + + return null; + + }, + /** * Sets the current layer to the given index. * @@ -38192,10 +41892,10 @@ Phaser.Tilemap.prototype = { if (x >= 0 && x < this.layers[layer].width && y >= 0 && y < this.layers[layer].height) { this.layers[layer].data[y][x] = index; + this.layers[layer].dirty = true; + this.calculateFaces(layer); } - this.dirty = true; - }, /** @@ -38259,10 +41959,10 @@ Phaser.Tilemap.prototype = { if (x >= 0 && x < this.layers[layer].width && y >= 0 && y < this.layers[layer].height) { this.layers[layer].data[y][x] = index; + this.layers[layer].dirty = true; + this.calculateFaces(layer); } - this.dirty = true; - }, /** @@ -38354,7 +42054,8 @@ Phaser.Tilemap.prototype = { this.layers[layer].data[ diffY + tileblock[i].y ][ diffX + tileblock[i].x ] = tileblock[i].index; } - this.dirty = true; + this.layers[layer].dirty = true; + this.calculateFaces(layer); }, @@ -38630,6 +42331,8 @@ Phaser.Tilemap.prototype = { }; +Phaser.Tilemap.prototype.constructor = Phaser.Tilemap; + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -38642,25 +42345,37 @@ Phaser.Tilemap.prototype = { * @class Phaser.TilemapLayer * @constructor * @param {Phaser.Game} game - Game reference to the currently running game. -* @param {number} x - The x coordinate of this layer. -* @param {number} y - The y coordinate of this layer. -* @param {number} renderWidth - Width of the layer. -* @param {number} renderHeight - Height of the layer. -* @param {Phaser.Tileset|string} tileset - The tile set used for rendering. * @param {Phaser.Tilemap} tilemap - The tilemap to which this layer belongs. -* @param {number} layer - The layer index within the map. +* @param {number} index - The layer index within the map that this TilemapLayer represents. +* @param {number} width - Width of the renderable area of the layer. +* @param {number} height - Height of the renderable area of the layer. */ -Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset, tilemap, layer) { +Phaser.TilemapLayer = function (game, tilemap, index, width, height) { /** * @property {Phaser.Game} game - A reference to the currently running Game. */ this.game = game; - + /** - * @property {HTMLCanvasElement} canvas - The canvas to which this BitmapData draws. + * @property {Phaser.Tilemap} map - The Tilemap to which this layer is bound. */ - this.canvas = Phaser.Canvas.create(renderWidth, renderHeight); + this.map = tilemap; + + /** + * @property {number} index - The index of this layer within the Tilemap. + */ + this.index = index; + + /** + * @property {object} layer - The layer object within the Tilemap that this layer represents. + */ + this.layer = tilemap.layers[index]; + + /** + * @property {HTMLCanvasElement} canvas - The canvas to which this TilemapLayer draws. + */ + this.canvas = Phaser.Canvas.create(width, height); /** * @property {CanvasRenderingContext2D} context - The 2d context of the canvas. @@ -38680,9 +42395,14 @@ Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset, /** * @property {Phaser.Frame} textureFrame - Dimensions of the renderable area. */ - this.textureFrame = new Phaser.Frame(0, 0, 0, renderWidth, renderHeight, 'tilemaplayer', game.rnd.uuid()); + this.textureFrame = new Phaser.Frame(0, 0, 0, width, height, 'tilemapLayer', game.rnd.uuid()); - Phaser.Sprite.call(this, this.game, x, y, this.texture, this.textureFrame); + Phaser.Sprite.call(this, this.game, 0, 0, this.texture, this.textureFrame); + + /** + * @property {string} name - The name of the layer. + */ + this.name = ''; /** * @property {number} type - The const type of this object. @@ -38691,58 +42411,85 @@ Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset, this.type = Phaser.TILEMAPLAYER; /** - * A layer that is fixed to the camera ignores the position of any ancestors in the display list and uses its x/y coordinates as offsets from the top left of the camera. - * @property {boolean} fixedToCamera - Fixes this layer to the Camera. + * An object that is fixed to the camera ignores the position of any ancestors in the display list and uses its x/y coordinates as offsets from the top left of the camera. + * @property {boolean} fixedToCamera - Fixes this object to the Camera. * @default */ this.fixedToCamera = true; /** - * @property {Phaser.Tileset} tileset - The tile set used for rendering. + * @property {Phaser.Point} cameraOffset - If this object is fixed to the camera then use this Point to specify how far away from the Camera x/y it's rendered. */ - this.tileset = null; + this.cameraOffset = new Phaser.Point(0, 0); /** - * @property {number} tileWidth - The width of a single tile in pixels. + * @property {string} tileColor - If no tile set is given the tiles will be rendered as rectangles in this color. Provide in hex or rgb/rgba string format. + * @default */ - this.tileWidth = 0; + this.tileColor = 'rgb(255, 255, 255)'; /** - * @property {number} tileHeight - The height of a single tile in pixels. + * @property {boolean} debug - If set to true the collideable tile edges path will be rendered. + * @default */ - this.tileHeight = 0; + this.debug = false; /** - * @property {number} tileMargin - The margin around the tiles. + * @property {number} debugAlpha - If debug is true then the tileset is rendered with this alpha level, to make the tile edges clearer. + * @default */ - this.tileMargin = 0; + this.debugAlpha = 0.5; /** - * @property {number} tileSpacing - The spacing around the tiles. + * @property {string} debugColor - If debug is true this is the color used to outline the edges of collidable tiles. Provide in hex or rgb/rgba string format. + * @default */ - this.tileSpacing = 0; + this.debugColor = 'rgba(0, 255, 0, 1)'; /** - * @property {number} widthInPixels - Do NOT recommend changing after the map is loaded! - * @readonly + * @property {boolean} debugFill - If true the debug tiles are filled with debugFillColor AND stroked around. + * @default */ - this.widthInPixels = 0; + this.debugFill = false; /** - * @property {number} heightInPixels - Do NOT recommend changing after the map is loaded! - * @readonly + * @property {string} debugFillColor - If debugFill is true this is the color used to fill the tiles. Provide in hex or rgb/rgba string format. + * @default */ - this.heightInPixels = 0; + this.debugFillColor = 'rgba(0, 255, 0, 0.2)'; /** - * @property {number} renderWidth - The width of the area being rendered. + * @property {number} scrollFactorX - speed at which this layer scrolls + * horizontally, relative to the camera (e.g. scrollFactorX of 0.5 scrolls + * half as quickly as the 'normal' camera-locked layers do) + * @default 1 */ - this.renderWidth = renderWidth; + this.scrollFactorX = 1; /** - * @property {number} renderHeight - The height of the area being rendered. + * @property {number} scrollFactorY - speed at which this layer scrolls + * vertically, relative to the camera (e.g. scrollFactorY of 0.5 scrolls + * half as quickly as the 'normal' camera-locked layers do) + * @default 1 */ - this.renderHeight = renderHeight; + this.scrollFactorY = 1; + + /** + * @property {boolean} dirty - Flag controlling when to re-render the layer. + */ + this.dirty = true; + + /** + * @property {number} _cw - Local collision var. + * @private + */ + this._cw = tilemap.tileWidth; + + /** + * @property {number} _ch - Local collision var. + * @private + */ + this._ch = tilemap.tileHeight; /** * @property {number} _ga - Local render loop var to help avoid gc spikes. @@ -38858,51 +42605,7 @@ Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset, */ this._prevY = 0; - /** - * @property {number} scrollFactorX - speed at which this layer scrolls - * horizontally, relative to the camera (e.g. scrollFactorX of 0.5 scrolls - * half as quickly as the 'normal' camera-locked layers do) - * @default 1 - */ - this.scrollFactorX = 1; - - /** - * @property {number} scrollFactorY - speed at which this layer scrolls - * vertically, relative to the camera (e.g. scrollFactorY of 0.5 scrolls - * half as quickly as the 'normal' camera-locked layers do) - * @default 1 - */ - this.scrollFactorY = 1; - - /** - * @property {Phaser.Tilemap} tilemap - The Tilemap to which this layer is bound. - */ - this.tilemap = null; - - /** - * @property {number} layer - Tilemap layer index. - */ - this.layer = null; - - /** - * @property {number} index - */ - this.index = 0; - - /** - * @property {boolean} dirty - Flag controlling when to re-render the layer. - */ - this.dirty = true; - - if (tileset instanceof Phaser.Tileset || typeof tileset === 'string') - { - this.updateTileset(tileset); - } - - if (tilemap instanceof Phaser.Tilemap) - { - this.updateMapData(tilemap, layer); - } + this.updateMax(); }; @@ -38911,13 +42614,16 @@ Phaser.TilemapLayer.prototype = Phaser.Utils.extend(true, Phaser.TilemapLayer.pr Phaser.TilemapLayer.prototype.constructor = Phaser.TilemapLayer; /** -* Automatically called by World.preUpdate. Handles cache updates. +* Automatically called by World.postUpdate. Handles cache updates. * -* @method Phaser.TilemapLayer#update +* @method Phaser.TilemapLayer#postUpdate * @memberof Phaser.TilemapLayer */ -Phaser.TilemapLayer.prototype.update = function () { +Phaser.TilemapLayer.prototype.postUpdate = function () { + Phaser.Sprite.prototype.postUpdate.call(this); + + // Stops you being able to auto-scroll the camera if it's not following a sprite this.scrollX = this.game.camera.x * this.scrollFactorX; this.scrollY = this.game.camera.y * this.scrollFactorY; @@ -38933,69 +42639,12 @@ Phaser.TilemapLayer.prototype.update = function () { */ Phaser.TilemapLayer.prototype.resizeWorld = function () { - this.game.world.setBounds(0, 0, this.widthInPixels, this.heightInPixels); + this.game.world.setBounds(0, 0, this.layer.widthInPixels, this.layer.heightInPixels); } /** -* Updates the Tileset data. -* -* @method Phaser.TilemapLayer#updateTileset -* @memberof Phaser.TilemapLayer -* @param {Phaser.Tileset|string} tileset - The tileset to use for this layer. -*/ -Phaser.TilemapLayer.prototype.updateTileset = function (tileset) { - - if (tileset instanceof Phaser.Tileset) - { - this.tileset = tileset; - } - else if (typeof tileset === 'string') - { - this.tileset = this.game.cache.getTileset('tiles'); - } - else - { - return; - } - - this.tileWidth = this.tileset.tileWidth; - this.tileHeight = this.tileset.tileHeight; - this.tileMargin = this.tileset.tileMargin; - this.tileSpacing = this.tileset.tileSpacing; - - this.updateMax(); - -} - -/** -* Updates the Tilemap data. -* -* @method Phaser.TilemapLayer#updateMapData -* @memberof Phaser.TilemapLayer -* @param {Phaser.Tilemap} tilemap - The tilemap to which this layer belongs. -* @param {number} layer - The layer index within the map. -*/ -Phaser.TilemapLayer.prototype.updateMapData = function (tilemap, layer) { - - if (typeof layer === 'undefined') - { - layer = 0; - } - - if (tilemap instanceof Phaser.Tilemap) - { - this.tilemap = tilemap; - this.layer = this.tilemap.layers[layer]; - this.index = layer; - this.updateMax(); - this.tilemap.dirty = true; - } - -} - -/** -* Take an x coordinate that doesn't account for scrollFactorY and 'fix' it +* Take an x coordinate that doesn't account for scrollFactorX and 'fix' it * into a scrolled local space. Used primarily internally * @method Phaser.TilemapLayer#_fixX * @memberof Phaser.TilemapLayer @@ -39005,19 +42654,22 @@ Phaser.TilemapLayer.prototype.updateMapData = function (tilemap, layer) { */ Phaser.TilemapLayer.prototype._fixX = function(x) { + if (x < 0) + { + x = 0; + } + if (this.scrollFactorX === 1) { return x; } - var leftEdge = x - (this._x / this.scrollFactorX); - - return this._x + leftEdge; + return this._x + (x - (this._x / this.scrollFactorX)); } /** -* Take an x coordinate that _does_ account for scrollFactorY and 'unfix' it +* Take an x coordinate that _does_ account for scrollFactorX and 'unfix' it * back to camera space. Used primarily internally * @method Phaser.TilemapLayer#_unfixX * @memberof Phaser.TilemapLayer @@ -39032,9 +42684,7 @@ Phaser.TilemapLayer.prototype._unfixX = function(x) { return x; } - var leftEdge = x - this._x; - - return (this._x / this.scrollFactorX) + leftEdge; + return (this._x / this.scrollFactorX) + (x - this._x); } @@ -39049,14 +42699,17 @@ Phaser.TilemapLayer.prototype._unfixX = function(x) { */ Phaser.TilemapLayer.prototype._fixY = function(y) { + if (y < 0) + { + y = 0; + } + if (this.scrollFactorY === 1) { return y; } - var topEdge = y - (this._y / this.scrollFactorY); - - return this._y + topEdge; + return this._y + (y - (this._y / this.scrollFactorY)); } @@ -39076,9 +42729,7 @@ Phaser.TilemapLayer.prototype._unfixY = function(y) { return y; } - var topEdge = y - this._y; - - return (this._y / this.scrollFactorY) + topEdge; + return (this._y / this.scrollFactorY) + (y - this._y); } @@ -39091,9 +42742,9 @@ Phaser.TilemapLayer.prototype._unfixY = function(y) { */ Phaser.TilemapLayer.prototype.getTileX = function (x) { - var tileWidth = this.tileWidth * this.scale.x; + // var tileWidth = this.tileWidth * this.scale.x; - return this.game.math.snapToFloor(this._fixX(x), tileWidth) / tileWidth; + return this.game.math.snapToFloor(this._fixX(x), this.map.tileWidth) / this.map.tileWidth; } @@ -39106,9 +42757,9 @@ Phaser.TilemapLayer.prototype.getTileX = function (x) { */ Phaser.TilemapLayer.prototype.getTileY = function (y) { - var tileHeight = this.tileHeight * this.scale.y; + // var tileHeight = this.tileHeight * this.scale.y; - return this.game.math.snapToFloor(this._fixY(y), tileHeight) / tileHeight; + return this.game.math.snapToFloor(this._fixY(y), this.map.tileHeight) / this.map.tileHeight; } @@ -39118,7 +42769,8 @@ Phaser.TilemapLayer.prototype.getTileY = function (y) { * @memberof Phaser.TilemapLayer * @param {number} x - X position of the point in target tile. * @param {number} y - Y position of the point in target tile. -* @return {Phaser.Tile} The tile with specific properties. +* @param {Phaser.Point|object} point - The Point object to set the x and y values on. +* @return {Phaser.Point|object} A Point object with its x and y properties set. */ Phaser.TilemapLayer.prototype.getTileXY = function (x, y, point) { @@ -39130,18 +42782,92 @@ Phaser.TilemapLayer.prototype.getTileXY = function (x, y, point) { } /** -* Get the tiles within the given area. +* Get all tiles that exist within the given area, defined by the top-left corner, width and height. Values given are in pixels, not tiles. * @method Phaser.TilemapLayer#getTiles * @memberof Phaser.TilemapLayer -* @param {number} x - X position of the top left of the area to copy (given in tiles, not pixels) -* @param {number} y - Y position of the top left of the area to copy (given in tiles, not pixels) -* @param {number} width - The width of the area to copy (given in tiles, not pixels) -* @param {number} height - The height of the area to copy (given in tiles, not pixels) -* @param {boolean} collides - If true only return tiles that collide on one or more faces. +* @param {number} x - X position of the top left corner. +* @param {number} y - Y position of the top left corner. +* @param {number} width - Width of the area to get. +* @param {number} height - Height of the area to get. +* @param {boolean} [collides=false] - If true only return tiles that collide on one or more faces. * @return {array} Array with tiles informations (each contains x, y, and the tile). */ Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides) { + // Should we only get tiles that have at least one of their collision flags set? (true = yes, false = no just get them all) + if (typeof collides === 'undefined') { collides = false; } + + // adjust the x,y coordinates for scrollFactor + x = this._fixX(x); + y = this._fixY(y); + + if (width > this.layer.widthInPixels) + { + width = this.layer.widthInPixels; + } + + if (height > this.layer.heightInPixels) + { + height = this.layer.heightInPixels; + } + + // Convert the pixel values into tile coordinates + this._tx = this.game.math.snapToFloor(x, this._cw) / this._cw; + this._ty = this.game.math.snapToFloor(y, this._ch) / this._ch; + this._tw = (this.game.math.snapToCeil(width, this._cw) + this._cw) / this._cw; + this._th = (this.game.math.snapToCeil(height, this._ch) + this._ch) / this._ch; + + // This should apply the layer x/y here + this._results.length = 0; + + var _tile = null; + + for (var wy = this._ty; wy < this._ty + this._th; wy++) + { + for (var wx = this._tx; wx < this._tx + this._tw; wx++) + { + if (this.layer.data[wy] && this.layer.data[wy][wx]) + { + _tile = this.layer.data[wy][wx]; + + if (_tile) + { + if (collides === false || (collides && _tile.collides)) + { + // convert tile coordinates back to camera space for return + var _wx = this._unfixX(wx * this._cw) / this._cw; + var _wy = this._unfixY(wy * this._ch) / this._ch; + + this._results.push({ + x: _wx * this._cw, + y: _wy * this._ch, + right: (_wx * this._cw) + this._cw, + bottom: (_wy * this._ch) + this._ch, + tile: _tile + }); + } + } + } + } + } + + return this._results; + +} + +/** +* Get all tiles that exist within the given area, defined by the top-left corner, width and height. Values given are in pixels, not tiles. +* This function also draws to the context all of the debug areas. +* @method Phaser.TilemapLayer#debugGetTiles +* @memberof Phaser.TilemapLayer +* @param {number} x - X position of the top left corner. +* @param {number} y - Y position of the top left corner. +* @param {number} width - Width of the area to get. +* @param {number} height - Height of the area to get. +* @param {boolean} [collides=false] - If true only return tiles that collide on one or more faces. +* @return {array} Array with tiles informations (each contains x, y, and the tile). +Phaser.TilemapLayer.prototype.debugGetTiles = function (x, y, width, height, collides) { + if (this.tilemap === null) { return; @@ -39149,22 +42875,11 @@ Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides // Should we only get tiles that have at least one of their collision flags set? (true = yes, false = no just get them all) if (typeof collides === 'undefined') { collides = false; } - - // Cap the values - - if (x < 0) - { - x = 0; - } - - if (y < 0) - { - y = 0; - } + if (typeof debug === 'undefined') { debug = false; } // adjust the x,y coordinates for scrollFactor - x = this._fixX( x ); - y = this._fixY( y ); + x = this._fixX(x); + y = this._fixY(y); if (width > this.widthInPixels) { @@ -39176,6 +42891,14 @@ Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides height = this.heightInPixels; } + if (debug) + { + console.log('x', x, 'y', y, 'w', width, 'h', height); + } + + // this.context.fillStyle = 'rgba(255,0,255,0.5)'; + // this.context.fillRect(x, y, width, height); + var tileWidth = this.tileWidth * this.scale.x; var tileHeight = this.tileHeight * this.scale.y; @@ -39185,39 +42908,86 @@ Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides this._tw = (this.game.math.snapToCeil(width, tileWidth) + tileWidth) / tileWidth; this._th = (this.game.math.snapToCeil(height, tileHeight) + tileHeight) / tileHeight; + if (debug) + { + console.log('tx', this._tx, 'ty', this._ty, 'tw', this._tw, 'th', this._th); + } + + // this.context.fillRect(this._tx * tileWidth, this._ty * tileHeight, this._tw * tileWidth, this._th * tileHeight); + // This should apply the layer x/y here - - // this._results.length = 0; - this._results = []; - - // pretty sure we don't use this any more? - // this._results.push( { x: x, y: y, width: width, height: height, tx: this._tx, ty: this._ty, tw: this._tw, th: this._th }); + this._results.length = 0; var _index = 0; var _tile = null; var sx = 0; var sy = 0; + this.context.fillStyle = 'rgba(255,0,0,1)'; + // this.context.strokeStyle = 'rgba(0,0,0,1)'; + for (var wy = this._ty; wy < this._ty + this._th; wy++) { + if (debug) + { + console.log('wy', wy); + } + for (var wx = this._tx; wx < this._tx + this._tw; wx++) { + if (debug) + { + console.log('wx', wx); + } + if (this.layer.data[wy] && this.layer.data[wy][wx]) { // Could combine - _index = this.layer.data[wy][wx] - 1; - _tile = this.tileset.getTile(_index); - - sx = _tile.width * this.scale.x; - sy = _tile.height * this.scale.y; - - if (collides === false || (collides && _tile.collideNone === false)) + // _index = this.layer.data[wy][wx] - 1; + // _tile = this.tileset.getTile(_index); + _tile = this.layer.data[wy][wx]; + + if (debug) { - // convert tile coordinates back to camera space for return - var _wx = this._unfixX( wx*sx ) / tileWidth; - var _wy = this._unfixY( wy*sy ) / tileHeight; - this._results.push({ x: _wx * sx, right: (_wx * sx) + sx, y: _wy * sy, bottom: (_wy * sy) + sy, width: sx, height: sy, tx: _wx, ty: _wy, tile: _tile }); + console.log('tile', _tile); } + + if (_tile) + { + + // sx = _tile.width * this.scale.x; + // sy = _tile.height * this.scale.y; + sx = this.tileWidth * this.scale.x; + sy = this.tileHeight * this.scale.y; + + if (collides === false || (collides && _tile.collides)) + { + if (debug) + { + this.context.fillRect(_tile.x * this.tileWidth, _tile.y * this.tileHeight, this.tileWidth, this.tileHeight); + } + + // this.context.strokeRect(_tile.x * this.tileWidth, _tile.y * this.tileHeight, this.tileWidth, this.tileHeight); + + // convert tile coordinates back to camera space for return + var _wx = this._unfixX(wx * sx) / this.tileWidth; + var _wy = this._unfixY(wy * sy) / this.tileHeight; + + this._results.push({ + x: _wx * sx, + y: _wy * sy, + width: sx, + height: sy, + right: (_wx * sx) + sx, + bottom: (_wy * sy) + sy, + tx: _wx, + ty: _wy, + tile: _tile + }); + } + + } + } } } @@ -39225,6 +42995,7 @@ Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides return this._results; } +*/ /** * Internal function to update maximum values. @@ -39233,8 +43004,8 @@ Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides */ Phaser.TilemapLayer.prototype.updateMax = function () { - this._maxX = this.game.math.ceil(this.canvas.width / this.tileWidth) + 1; - this._maxY = this.game.math.ceil(this.canvas.height / this.tileHeight) + 1; + this._maxX = this.game.math.ceil(this.canvas.width / this.map.tileWidth) + 1; + this._maxY = this.game.math.ceil(this.canvas.height / this.map.tileHeight) + 1; if (this.layer) { @@ -39247,13 +43018,12 @@ Phaser.TilemapLayer.prototype.updateMax = function () { { this._maxY = this.layer.height; } - - this.widthInPixels = this.layer.width * this.tileWidth; - this.heightInPixels = this.layer.height * this.tileHeight; } this.dirty = true; + // console.log('updateMax', this._maxX, this._maxY, 'px', this.layer.widthInPixels, this.layer.heightInPixels, 'rwh', this.layer.width, this.layer.height); + } /** @@ -39263,12 +43033,12 @@ Phaser.TilemapLayer.prototype.updateMax = function () { */ Phaser.TilemapLayer.prototype.render = function () { - if (this.tilemap && this.tilemap.dirty) + if (this.layer.dirty) { this.dirty = true; } - if (!this.dirty || !this.tileset || !this.tilemap || !this.visible) + if (!this.dirty || !this.visible) { return; } @@ -39276,101 +43046,174 @@ Phaser.TilemapLayer.prototype.render = function () { this._prevX = this._dx; this._prevY = this._dy; - this._dx = -(this._x - (this._startX * this.tileWidth)); - this._dy = -(this._y - (this._startY * this.tileHeight)); + this._dx = -(this._x - (this._startX * this.map.tileWidth)); + this._dy = -(this._y - (this._startY * this.map.tileHeight)); this._tx = this._dx; this._ty = this._dy; this.context.clearRect(0, 0, this.canvas.width, this.canvas.height); + this.context.fillStyle = this.tileColor; - for (var y = this._startY; y < this._startY + this._maxY; y++) + var tile; + var set; + var ox = 0; + var oy = 0; + + if (this.debug) + { + this.context.globalAlpha = this.debugAlpha; + } + + for (var y = this._startY, lenY = this._startY + this._maxY; y < lenY; y++) { this._column = this.layer.data[y]; - for (var x = this._startX; x < this._startX + this._maxX; x++) + for (var x = this._startX, lenX = this._startX + this._maxX; x < lenX; x++) { - // only -1 on TILED maps, not CSV - var tile = this.tileset.tiles[this._column[x]-1]; - - if (tile) + if (this._column[x]) { - this.context.drawImage( - this.tileset.image, - tile.x, - tile.y, - this.tileWidth, - this.tileHeight, - Math.floor(this._tx), - Math.floor(this._ty), - this.tileWidth, - this.tileHeight - ); + tile = this._column[x]; + + if (this.map.tiles[tile.index]) + { + set = this.map.tilesets[this.map.tiles[tile.index][2]] + + if (set.image) + { + if (set.tileWidth !== this.map.tileWidth || set.tileHeight !== this.map.tileHeight) + { + // TODO: Smaller sized tile check + this.context.drawImage( + this.map.tilesets[this.map.tiles[tile.index][2]].image, + this.map.tiles[tile.index][0], + this.map.tiles[tile.index][1], + set.tileWidth, + set.tileHeight, + Math.floor(this._tx), + Math.floor(this._ty) - (set.tileHeight - this.map.tileHeight), + set.tileWidth, + set.tileHeight + ); + } + else + { + this.context.drawImage( + this.map.tilesets[this.map.tiles[tile.index][2]].image, + this.map.tiles[tile.index][0], + this.map.tiles[tile.index][1], + this.map.tileWidth, + this.map.tileHeight, + Math.floor(this._tx), + Math.floor(this._ty), + this.map.tileWidth, + this.map.tileHeight + ); + } + } + else + { + this.context.fillRect(Math.floor(this._tx), Math.floor(this._ty), this.map.tileWidth, this.map.tileHeight); + } + } } - this._tx += this.tileWidth; + this._tx += this.map.tileWidth; } this._tx = this._dx; - this._ty += this.tileHeight; + this._ty += this.map.tileHeight; + + } + + if (this.debug) + { + this.context.globalAlpha = 1; + this.renderDebug(); } // Only needed if running in WebGL, otherwise this array will never get cleared down I don't think! - if (this.game.renderType == Phaser.WEBGL) + if (this.game.renderType === Phaser.WEBGL) { PIXI.texturesToUpdate.push(this.baseTexture); } this.dirty = false; - - if (this.tilemap.dirty) - { - this.tilemap.dirty = false; - } + this.layer.dirty = false; return true; } /** -* Returns the absolute delta x value. -* @method Phaser.TilemapLayer#deltaAbsX +* Renders a collision debug overlay on-top of the canvas. Called automatically by render when debug = true. +* @method Phaser.TilemapLayer#renderDebug * @memberof Phaser.TilemapLayer -* @return {number} Absolute delta X value */ -Phaser.TilemapLayer.prototype.deltaAbsX = function () { - return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX()); -} +Phaser.TilemapLayer.prototype.renderDebug = function () { -/** -* Returns the absolute delta y value. -* @method Phaser.TilemapLayer#deltaAbsY -* @memberof Phaser.TilemapLayer -* @return {number} Absolute delta Y value -*/ -Phaser.TilemapLayer.prototype.deltaAbsY = function () { - return (this.deltaY() > 0 ? this.deltaY() : -this.deltaY()); -} + this._tx = this._dx; + this._ty = this._dy; -/** -* Returns the delta x value. -* @method Phaser.TilemapLayer#deltaX -* @memberof Phaser.TilemapLayer -* @return {number} Delta X value -*/ -Phaser.TilemapLayer.prototype.deltaX = function () { - return this._dx - this._prevX; -} + this.context.strokeStyle = this.debugColor; + this.context.fillStyle = this.debugFillColor; + + for (var y = this._startY, lenY = this._startY + this._maxY; y < lenY; y++) + { + this._column = this.layer.data[y]; + + for (var x = this._startX, lenX = this._startX + this._maxX; x < lenX; x++) + { + var tile = this._column[x]; + + if (tile && (tile.faceTop || tile.faceBottom || tile.faceLeft || tile.faceRight)) + { + this._tx = Math.floor(this._tx); + + if (this.debugFill) + { + this.context.fillRect(this._tx, this._ty, this._cw, this._ch); + } + + this.context.beginPath(); + + if (tile.faceTop) + { + this.context.moveTo(this._tx, this._ty); + this.context.lineTo(this._tx + this._cw, this._ty); + } + + if (tile.faceBottom) + { + this.context.moveTo(this._tx, this._ty + this._ch); + this.context.lineTo(this._tx + this._cw, this._ty + this._ch); + } + + if (tile.faceLeft) + { + this.context.moveTo(this._tx, this._ty); + this.context.lineTo(this._tx, this._ty + this._ch); + } + + if (tile.faceRight) + { + this.context.moveTo(this._tx + this._cw, this._ty); + this.context.lineTo(this._tx + this._cw, this._ty + this._ch); + } + + this.context.stroke(); + } + + this._tx += this.map.tileWidth; + + } + + this._tx = this._dx; + this._ty += this.map.tileHeight; + + } -/** -* Returns the delta y value. -* @method Phaser.TilemapLayer#deltaY -* @memberof Phaser.TilemapLayer -* @return {number} Delta Y value -*/ -Phaser.TilemapLayer.prototype.deltaY = function () { - return this._dy - this._prevY; } /** @@ -39385,16 +43228,17 @@ Object.defineProperty(Phaser.TilemapLayer.prototype, "scrollX", { set: function (value) { - if (value !== this._x && value >= 0 && this.layer) + // if (value !== this._x && value >= 0 && this.layer && this.layer.widthInPixels > this.width) + if (value !== this._x && value >= 0 && this.layer.widthInPixels > this.width) { this._x = value; - - if (this._x > (this.widthInPixels - this.renderWidth)) + + if (this._x > (this.layer.widthInPixels - this.width)) { - this._x = this.widthInPixels - this.renderWidth; + this._x = this.layer.widthInPixels - this.width; } - this._startX = this.game.math.floor(this._x / this.tileWidth); + this._startX = this.game.math.floor(this._x / this.map.tileWidth); if (this._startX < 0) { @@ -39425,16 +43269,17 @@ Object.defineProperty(Phaser.TilemapLayer.prototype, "scrollY", { set: function (value) { - if (value !== this._y && value >= 0 && this.layer) + // if (value !== this._y && value >= 0 && this.layer && this.heightInPixels > this.renderHeight) + if (value !== this._y && value >= 0 && this.layer.heightInPixels > this.height) { this._y = value; - if (this._y > (this.heightInPixels - this.renderHeight)) + if (this._y > (this.layer.heightInPixels - this.height)) { - this._y = this.heightInPixels - this.renderHeight; + this._y = this.layer.heightInPixels - this.height; } - this._startY = this.game.math.floor(this._y / this.tileHeight); + this._startY = this.game.math.floor(this._y / this.map.tileHeight); if (this._startY < 0) { @@ -39453,6 +43298,46 @@ Object.defineProperty(Phaser.TilemapLayer.prototype, "scrollY", { }); +/** +* @name Phaser.TilemapLayer#collisionWidth +* @property {number} collisionWidth - The width of the collision tiles. +*/ +Object.defineProperty(Phaser.TilemapLayer.prototype, "collisionWidth", { + + get: function () { + return this._cw; + }, + + set: function (value) { + + this._cw = value; + + this.dirty = true; + + } + +}); + +/** +* @name Phaser.TilemapLayer#collisionHeight +* @property {number} collisionHeight - The height of the collision tiles. +*/ +Object.defineProperty(Phaser.TilemapLayer.prototype, "collisionHeight", { + + get: function () { + return this._ch; + }, + + set: function (value) { + + this._ch = value; + + this.dirty = true; + + } + +}); + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -39470,47 +43355,45 @@ Phaser.TilemapParser = { * Creates a Tileset object. * @method Phaser.TilemapParser.tileset * @param {Phaser.Game} game - Game reference to the currently running game. - * @param {string} key - * @param {number} tileWidth - * @param {number} tileHeight - * @param {number} tileMax - * @param {number} tileMargin - * @param {number} tileSpacing + * @param {string} key - The Cache key of this tileset. + * @param {number} tileWidth - Width of each single tile in pixels. + * @param {number} tileHeight - Height of each single tile in pixels. + * @param {number} [tileMargin=0] - If the tiles have been drawn with a margin, specify the amount here. + * @param {number} [tileSpacing=0] - If the tiles have been drawn with spacing between them, specify the amount here. + * @param {number} [rows=-1] - How many tiles are placed horizontally in each row? If -1 it will calculate rows by dividing the image width by tileWidth. + * @param {number} [columns=-1] - How many tiles are placed vertically in each column? If -1 it will calculate columns by dividing the image height by tileHeight. + * @param {number} [total=-1] - The maximum number of tiles to extract from the image. If -1 it will extract `rows * columns` worth. You can also set a value lower than the actual number of tiles. * @return {Phaser.Tileset} Generated Tileset object. */ - tileset: function (game, key, tileWidth, tileHeight, tileMax, tileMargin, tileSpacing) { + tileset: function (game, key, tileWidth, tileHeight, tileMargin, tileSpacing, rows, columns, total) { // How big is our image? var img = game.cache.getTilesetImage(key); - if (img == null) + if (img === null) { + console.warn("Phaser.TilemapParser.tileSet: Invalid image key given"); return null; } var width = img.width; var height = img.height; - // If no tile width/height is given, try and figure it out (won't work if the tileset has margin/spacing) - if (tileWidth <= 0) + if (rows === -1) { - tileWidth = Math.floor(-width / Math.min(-1, tileWidth)); + rows = Math.round(width / tileWidth); } - if (tileHeight <= 0) + if (columns === -1) { - tileHeight = Math.floor(-height / Math.min(-1, tileHeight)); + columns = Math.round(height / tileHeight); } - var row = Math.round(width / tileWidth); - var column = Math.round(height / tileHeight); - var total = row * column; + if (total === -1) + { + total = rows * columns; + } - if (tileMax !== -1) - { - total = tileMax; - } - // Zero or smaller than tile sizes? if (width === 0 || height === 0 || width < tileWidth || height < tileHeight || total === 0) { @@ -39518,26 +43401,7 @@ Phaser.TilemapParser = { return null; } - // Let's create some tiles - var x = tileMargin; - var y = tileMargin; - - var tileset = new Phaser.Tileset(img, key, tileWidth, tileHeight, tileMargin, tileSpacing); - - for (var i = 0; i < total; i++) - { - tileset.addTile(new Phaser.Tile(tileset, i, x, y, tileWidth, tileHeight)); - - x += tileWidth + tileSpacing; - - if (x === width) - { - x = tileMargin; - y += tileHeight + tileSpacing; - } - } - - return tileset; + return new Phaser.Tileset(img, key, tileWidth, tileHeight, tileMargin, tileSpacing, rows, columns, total); }, @@ -39545,19 +43409,27 @@ Phaser.TilemapParser = { * Parse tileset data from the cache and creates a Tileset object. * @method Phaser.TilemapParser.parse * @param {Phaser.Game} game - Game reference to the currently running game. - * @param {object} data - * @param {string} format - * @return {Phaser.Tileset} Generated Tileset object. + * @param {string} key - The key of the tilemap in the Cache. + * @return {object} The parsed map object. */ - parse: function (game, data, format) { + parse: function (game, key) { - if (format === Phaser.Tilemap.CSV) + var map = game.cache.getTilemapData(key); + + if (map) { - return this.parseCSV(data); + if (map.format === Phaser.Tilemap.CSV) + { + return this.parseCSV(map.data); + } + else if (map.format === Phaser.Tilemap.TILED_JSON) + { + return this.parseTiledJSON(map.data); + } } - else if (format === Phaser.Tilemap.TILED_JSON) + else { - return this.parseTiledJSON(data); + return { layers: [], objects: [], images: [], tilesets: [] }; } }, @@ -39595,6 +43467,8 @@ Phaser.TilemapParser = { } } + // Build collision map + return [{ name: 'csv', width: width, height: height, alpha: 1, visible: true, indexes: [], tileMargin: 0, tileSpacing: 0, data: output }]; }, @@ -39602,66 +43476,243 @@ Phaser.TilemapParser = { /** * Parses a Tiled JSON file into valid map data. * @method Phaser.TilemapParser.parseJSON - * @param {object} json- The Tiled JSON data. - * @return {object} Generated map data. + * @param {object} json - The JSON map data. + * @return {object} Generated and parsed map data. */ parseTiledJSON: function (json) { + if (json.orientation !== 'orthogonal') + { + console.warn('TilemapParser.parseTiledJSON: Only orthogonal map types are supported in this version of Phaser'); + return null; + } + + // Map data will consist of: layers, objects, images, tilesets, sizes + var map = {}; + + map.width = json.width; + map.height = json.height; + map.tileWidth = json.tilewidth; + map.tileHeight = json.tileheight; + map.orientation = json.orientation; + map.version = json.version; + map.properties = json.properties; + map.widthInPixels = map.width * map.tileWidth; + map.heightInPixels = map.height * map.tileHeight; + + // Tile Layers var layers = []; for (var i = 0; i < json.layers.length; i++) { - // Check it's a data layer - if (!json.layers[i].data) + if (json.layers[i].type !== 'tilelayer') { continue; } - // json.tilewidth - // json.tileheight - var layer = { name: json.layers[i].name, + x: json.layers[i].x, + y: json.layers[i].y, width: json.layers[i].width, height: json.layers[i].height, + widthInPixels: json.layers[i].width * json.tilewidth, + heightInPixels: json.layers[i].height * json.tileheight, alpha: json.layers[i].opacity, visible: json.layers[i].visible, - indexes: [], - - tileMargin: json.tilesets[0].margin, - tileSpacing: json.tilesets[0].spacing + properties: {}, + indexes: [] }; - var output = []; - var c = 0; - var row; - - for (var t = 0; t < json.layers[i].data.length; t++) + if (json.layers[i].properties) { - if (c === 0) + layer.properties = json.layers[i].properties; + } + + var x = 0; + var row = []; + var output = []; + + // Loop through the data field in the JSON. + + // This is an array containing the tile indexes, one after the other. 0 = no tile, everything else = the tile index (starting at 1) + // If the map contains multiple tilesets then the indexes are relative to that which the set starts from + // Need to set which tileset in the cache = which tileset in the JSON, if you do this manually it means you can use the same map data but a new tileset. + + for (var t = 0, len = json.layers[i].data.length; t < len; t++) + { + // index, x, y, width, height + if (json.layers[i].data[t] > 0) { - row = []; + row.push(new Phaser.Tile(json.layers[i].data[t], x, output.length, json.tilewidth, json.tileheight)); + } + else + { + row.push(null); } - row.push(json.layers[i].data[t]); - c++; + x++; - if (c == json.layers[i].width) + if (x === json.layers[i].width) { output.push(row); - c = 0; + x = 0; + row = []; } } layer.data = output; - + layers.push(layer); } - return layers; + map.layers = layers; + + // Images + var images = []; + + for (var i = 0; i < json.layers.length; i++) + { + if (json.layers[i].type !== 'imagelayer') + { + continue; + } + + var image = { + + name: json.layers[i].name, + image: json.layers[i].image, + x: json.layers[i].x, + y: json.layers[i].y, + alpha: json.layers[i].opacity, + visible: json.layers[i].visible, + properties: {} + + }; + + if (json.layers[i].properties) + { + image.properties = json.layers[i].properties; + } + + images.push(image); + + } + + map.images = images; + + // Objects + var objects = {}; + + for (var i = 0; i < json.layers.length; i++) + { + if (json.layers[i].type !== 'objectgroup') + { + continue; + } + + objects[json.layers[i].name] = []; + + for (var v = 0, len = json.layers[i].objects.length; v < len; v++) + { + // For now we'll just support object tiles + if (json.layers[i].objects[v].gid) + { + var object = { + + gid: json.layers[i].objects[v].gid, + name: json.layers[i].objects[v].name, + x: json.layers[i].objects[v].x, + y: json.layers[i].objects[v].y, + visible: json.layers[i].objects[v].visible, + properties: json.layers[i].objects[v].properties + + }; + + objects[json.layers[i].name].push(object); + } + + } + } + + map.objects = objects; + + // Tilesets + var tilesets = []; + + for (var i = 0; i < json.tilesets.length; i++) + { + // name, firstgid, width, height, margin, spacing, properties + var set = json.tilesets[i]; + var newSet = new Phaser.Tileset(set.name, set.firstgid, set.tilewidth, set.tileheight, set.margin, set.spacing, set.properties); + + if (set.tileproperties) + { + newSet.tileProperties = set.tileproperties; + } + + newSet.rows = set.imageheight / set.tileheight; + newSet.columns = set.imagewidth / set.tilewidth; + newSet.total = newSet.rows * newSet.columns; + + tilesets.push(newSet); + } + + map.tilesets = tilesets; + + map.tiles = []; + + // Finally lets build our super tileset index + for (var i = 0; i < map.tilesets.length; i++) + { + var set = map.tilesets[i]; + + var x = set.tileMargin; + var y = set.tileMargin; + + var count = 0; + var countX = 0; + var countY = 0; + + for (var t = set.firstgid; t < set.firstgid + set.total; t++) + { + // Can add extra properties here as needed + map.tiles[t] = [x, y, i]; + + x += set.tileWidth + set.tileSpacing; + + count++; + + if (count === set.total) + { + break; + } + + countX++; + + if (countX === set.columns) + { + x = set.tileMargin; + y += set.tileHeight + set.tileSpacing; + + countX = 0; + countY++; + + if (countY === set.rows) + { + break; + } + } + } + + } + + console.log(map); + + return map; } @@ -39675,89 +43726,121 @@ Phaser.TilemapParser = { /** * A Tile set is a combination of an image containing the tiles and collision data per tile. +* You should not normally instantiate this class directly. * * @class Phaser.Tileset * @constructor -* @param {Image} image - The Image object from the Cache. -* @param {string} key - The key of the tileset in the cache. -* @param {number} tileWidth - The width of the tile in pixels. -* @param {number} tileHeight - The height of the tile in pixels. -* @param {number} [tileMargin] - The margin around the tiles in the sheet. -* @param {number} [tileSpacing] - The spacing between the tiles in the sheet. +* @param {string} name - The name of the tileset in the map data. +* @param {number} firstgid - The Tiled firstgid value. +* @param {number} width - Width of each tile in pixels. +* @param {number} height - Height of each tile in pixels. +* @param {number} margin - The amount of margin around the tilesheet. +* @param {number} spacing - The amount of spacing between each tile in the sheet. +* @param {object} properties - Tileset properties. */ -Phaser.Tileset = function (image, key, tileWidth, tileHeight, tileMargin, tileSpacing) { - - if (typeof tileMargin === "undefined") { tileMargin = 0; } - if (typeof tileSpacing === "undefined") { tileSpacing = 0; } +Phaser.Tileset = function (name, firstgid, width, height, margin, spacing, properties) { /** - * @property {string} key - The cache ID. + * @property {string} name - The name of the Tileset. */ - this.key = key; + this.name = name; /** - * @property {object} image - The image used for rendering. + * @property {number} firstgid - The Tiled firstgid value. + * @default */ - this.image = image; + this.firstgid = firstgid; /** * @property {number} tileWidth - The width of a tile in pixels. */ - this.tileWidth = tileWidth; + this.tileWidth = width; /** * @property {number} tileHeight - The height of a tile in pixels. */ - this.tileHeight = tileHeight; + this.tileHeight = height; /** * @property {number} tileMargin - The margin around the tiles in the sheet. */ - this.margin = tileMargin; + this.tileMargin = margin; /** * @property {number} tileSpacing - The margin around the tiles in the sheet. */ - this.spacing = tileSpacing; + this.tileSpacing = spacing; /** - * @property {array} tiles - An array of the tile collision data. + * @property {object} properties - Tileset specific properties (typically defined in the Tiled editor). */ - this.tiles = []; + this.properties = properties; -} + /** + * @property {object} tilePproperties - Tile specific properties (typically defined in the Tiled editor). + */ + this.tileProperties = {}; + + /** + * @property {object} image - The image used for rendering. + */ + this.image = null; + + /** + * @property {number} rows - The number of rows in the tile sheet. + */ + this.rows = 0; + + /** + * @property {number} columns - The number of columns in the tile sheet. + */ + this.columns = 0; + + /** + * @property {number} total - The total number of tiles in the tilesheet. + */ + this.total = 0; + +}; Phaser.Tileset.prototype = { - /** - * Adds a Tile into this set. - * - * @method Phaser.Tileset#addTile - * @param {Phaser.Tile} tile - The tile to add to this set. - */ - addTile: function (tile) { - - this.tiles.push(tile); - - return tile; - - }, - /** * Gets a Tile from this set. * * @method Phaser.Tileset#getTile * @param {number} index - The index of the tile within the set. - * @return {Phaser.Tile} The tile. + * @return {object} The tile object. */ getTile: function (index) { - if (this.tiles[index]) - { - return this.tiles[index]; - } + return this.tiles[index]; - return null; + }, + + /** + * Gets a Tile from this set. + * + * @method Phaser.Tileset#getTileX + * @param {number} index - The index of the tile within the set. + * @return {object} The tile object. + */ + getTileX: function (index) { + + return this.tiles[index][0]; + + }, + + /** + * Gets a Tile from this set. + * + * @method Phaser.Tileset#getTileY + * @param {number} index - The index of the tile within the set. + * @return {object} The tile object. + */ + getTileY: function (index) { + + return this.tiles[index][1]; }, @@ -39775,24 +43858,6 @@ Phaser.Tileset.prototype = { }, - /** - * Checks if the tile at the given index can collide. - * - * @method Phaser.Tileset#canCollide - * @param {number} index - The index of the tile within the set. - * @return {boolean} True or false depending on the tile collision or null if no tile was found at the given index. - */ - canCollide: function (index) { - - if (this.tiles[index]) - { - return this.tiles[index].collideNone; - } - - return null; - - }, - /** * Checks if the tile at the given index exists. * @@ -39804,64 +43869,11 @@ Phaser.Tileset.prototype = { return (this.tiles[index]); - }, - - /** - * Sets collision values on a range of tiles in the set. - * - * @method Phaser.Tileset#setCollisionRange - * @param {number} start - The index to start setting the collision data on. - * @param {number} stop - The index to stop setting the collision data on. - * @param {boolean} left - Should the tile collide on the left? - * @param {boolean} right - Should the tile collide on the right? - * @param {boolean} up - Should the tile collide on the top? - * @param {boolean} down - Should the tile collide on the bottom? - */ - setCollisionRange: function (start, stop, left, right, up, down) { - - if (this.tiles[start] && this.tiles[stop] && start < stop) - { - for (var i = start; i <= stop; i++) - { - this.tiles[i].setCollision(left, right, up, down); - } - } - - }, - - /** - * Sets collision values on a tile in the set. - * - * @method Phaser.Tileset#setCollision - * @param {number} index - The index of the tile within the set. - * @param {boolean} left - Should the tile collide on the left? - * @param {boolean} right - Should the tile collide on the right? - * @param {boolean} up - Should the tile collide on the top? - * @param {boolean} down - Should the tile collide on the bottom? - */ - setCollision: function (index, left, right, up, down) { - - if (this.tiles[index]) - { - this.tiles[index].setCollision(left, right, up, down); - } - } -} +}; -/** -* @name Phaser.Tileset#total -* @property {number} total - The total number of tiles in this Tileset. -* @readonly -*/ -Object.defineProperty(Phaser.Tileset.prototype, "total", { - - get: function () { - return this.tiles.length; - } - -}); +Phaser.Tileset.prototype.constructor = Phaser.Tileset; /** * We're replacing a couple of Pixi's methods here to fix or add some vital functionality: @@ -39889,7 +43901,7 @@ PIXI.CanvasRenderer.prototype.render = function(stage) this.context.setTransform(1, 0, 0, 1, 0, 0); this.context.clearRect(0, 0, this.width, this.height) - this.renderDisplayObject(stage); + this.renderDisplayObject(stage, false); // Remove frame updates if (PIXI.Texture.frameUpdates.length > 0) @@ -39899,7 +43911,9 @@ PIXI.CanvasRenderer.prototype.render = function(stage) } -PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject) +// @param {boolean} [renderHidden=false] - If true displayObjects that have their visible property set to false will still be rendered. + +PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject, renderHidden) { // Once the display object hits this we can break the loop var testObject = displayObject.last._iNext; @@ -39909,7 +43923,7 @@ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject) { //transform = displayObject.worldTransform; - if (!displayObject.visible) + if (!displayObject.visible && !renderHidden) { displayObject = displayObject.last._iNext; continue; @@ -39928,14 +43942,25 @@ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject) if (displayObject.texture.frame) { this.context.globalAlpha = displayObject.worldAlpha; + + this.context.setTransform( + displayObject.worldTransform[0], + displayObject.worldTransform[3], + displayObject.worldTransform[1], + displayObject.worldTransform[4], + displayObject.worldTransform[2], + displayObject.worldTransform[5]); if (displayObject.texture.trimmed) { - this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2] + displayObject.texture.trim.x, displayObject.worldTransform[5] + displayObject.texture.trim.y); + this.context.transform(1, 0, 0, 1, displayObject.texture.trim.x, displayObject.texture.trim.y); } - else + + //if smoothingEnabled is supported and we need to change the smoothing property for this texture + if (this.smoothProperty && this.scaleMode !== displayObject.texture.baseTexture.scaleMode) { - this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2], displayObject.worldTransform[5]); + this.scaleMode = displayObject.texture.baseTexture.scaleMode; + this.context[this.smoothProperty] = (this.scaleMode === PIXI.BaseTexture.SCALE_MODE.LINEAR); } this.context.drawImage( @@ -39944,8 +43969,8 @@ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject) displayObject.texture.frame.y, displayObject.texture.frame.width, displayObject.texture.frame.height, - (displayObject.anchor.x) * -displayObject.texture.frame.width, - (displayObject.anchor.y) * -displayObject.texture.frame.height, + Math.floor((displayObject.anchor.x) * -displayObject.texture.frame.width), + Math.floor((displayObject.anchor.y) * -displayObject.texture.frame.height), displayObject.texture.frame.width, displayObject.texture.frame.height); } diff --git a/build/phaser.min.js b/build/phaser.min.js index 4f17eda8..df42123f 100644 --- a/build/phaser.min.js +++ b/build/phaser.min.js @@ -1,12 +1,13 @@ -/*! Phaser v1.1.3 | (c) 2013 Photon Storm Ltd. */ -!function(a,b){"function"==typeof define&&define.amd?define(b):"object"==typeof exports?module.exports=b():a.Phaser=b()}(this,function(){function a(a){return[(255&a>>16)/255,(255&a>>8)/255,(255&a)/255]}function b(){return c.Matrix="undefined"!=typeof Float32Array?Float32Array:Array,c.Matrix}function a(a){return[(255&a>>16)/255,(255&a>>8)/255,(255&a)/255]}var c=c||{},d=d||{VERSION:"1.1.3",DEV_VERSION:"1.1.3",GAMES:[],AUTO:0,CANVAS:1,WEBGL:2,HEADLESS:3,SPRITE:0,BUTTON:1,BULLET:2,GRAPHICS:3,TEXT:4,TILESPRITE:5,BITMAPTEXT:6,GROUP:7,RENDERTEXTURE:8,TILEMAP:9,TILEMAPLAYER:10,EMITTER:11,POLYGON:12,BITMAPDATA:13,CANVAS_FILTER:14,WEBGL_FILTER:15,NONE:0,LEFT:1,RIGHT:2,UP:3,DOWN:4};c.InteractionManager=function(){},d.Utils={shuffle:function(a){for(var b=a.length-1;b>0;b--){var c=Math.floor(Math.random()*(b+1)),d=a[b];a[b]=a[c],a[c]=d}return a},pad:function(a,b,c,d){if("undefined"==typeof b)var b=0;if("undefined"==typeof c)var c=" ";if("undefined"==typeof d)var d=3;var e=0;if(b+1>=a.length)switch(d){case 1:a=Array(b+1-a.length).join(c)+a;break;case 3:var f=Math.ceil((e=b-a.length)/2),g=e-f;a=Array(g+1).join(c)+a+Array(f+1).join(c);break;default:a+=Array(b+1-a.length).join(c)}return a},isPlainObject:function(a){if("object"!=typeof a||a.nodeType||a===a.window)return!1;try{if(a.constructor&&!hasOwn.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(b){return!1}return!0},extend:function(){var a,b,c,e,f,g,h=arguments[0]||{},i=1,j=arguments.length,k=!1;for("boolean"==typeof h&&(k=h,h=arguments[1]||{},i=2),j===i&&(h=this,--i);j>i;i++)if(null!=(a=arguments[i]))for(b in a)c=h[b],e=a[b],h!==e&&(k&&e&&(d.Utils.isPlainObject(e)||(f=Array.isArray(e)))?(f?(f=!1,g=c&&Array.isArray(c)?c:[]):g=c&&d.Utils.isPlainObject(c)?c:{},h[b]=d.Utils.extend(k,g,e)):void 0!==e&&(h[b]=e));return h}},function(){var a=!1;a&&(window.console=void 0),void 0===window.console&&(window.console={debug:function(){return!0},info:function(){return!1},warn:function(){return!1},log:function(){return!1}}),debug=function(a){window.console.debug(a)},info=function(a){window.console.info(a)},warn=function(a){window.console.warn(a)},log=function(a){window.console.log(a)}}(),"function"!=typeof Function.prototype.bind&&(Function.prototype.bind=function(){var a=Array.prototype.slice;return function(b){function c(){var f=e.concat(a.call(arguments));d.apply(this instanceof c?this:b,f)}var d=this,e=a.call(arguments,1);if("function"!=typeof d)throw new TypeError;return c.prototype=function f(a){return a&&(f.prototype=a),this instanceof f?void 0:new f}(d.prototype),c}}()),b(),c.mat3={},c.mat3.create=function(){var a=new c.Matrix(9);return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=1,a[5]=0,a[6]=0,a[7]=0,a[8]=1,a},c.mat3.identity=function(a){return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=1,a[5]=0,a[6]=0,a[7]=0,a[8]=1,a},c.mat4={},c.mat4.create=function(){var a=new c.Matrix(16);return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=1,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=1,a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1,a},c.mat3.multiply=function(a,b,c){c||(c=a);var d=a[0],e=a[1],f=a[2],g=a[3],h=a[4],i=a[5],j=a[6],k=a[7],l=a[8],m=b[0],n=b[1],o=b[2],p=b[3],q=b[4],r=b[5],s=b[6],t=b[7],u=b[8];return c[0]=m*d+n*g+o*j,c[1]=m*e+n*h+o*k,c[2]=m*f+n*i+o*l,c[3]=p*d+q*g+r*j,c[4]=p*e+q*h+r*k,c[5]=p*f+q*i+r*l,c[6]=s*d+t*g+u*j,c[7]=s*e+t*h+u*k,c[8]=s*f+t*i+u*l,c},c.mat3.clone=function(a){var b=new c.Matrix(9);return b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[4]=a[4],b[5]=a[5],b[6]=a[6],b[7]=a[7],b[8]=a[8],b},c.mat3.transpose=function(a,b){if(!b||a===b){var c=a[1],d=a[2],e=a[5];return a[1]=a[3],a[2]=a[6],a[3]=c,a[5]=a[7],a[6]=d,a[7]=e,a}return b[0]=a[0],b[1]=a[3],b[2]=a[6],b[3]=a[1],b[4]=a[4],b[5]=a[7],b[6]=a[2],b[7]=a[5],b[8]=a[8],b},c.mat3.toMat4=function(a,b){return b||(b=c.mat4.create()),b[15]=1,b[14]=0,b[13]=0,b[12]=0,b[11]=0,b[10]=a[8],b[9]=a[7],b[8]=a[6],b[7]=0,b[6]=a[5],b[5]=a[4],b[4]=a[3],b[3]=0,b[2]=a[2],b[1]=a[1],b[0]=a[0],b},c.mat4.create=function(){var a=new c.Matrix(16);return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=1,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=1,a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1,a},c.mat4.transpose=function(a,b){if(!b||a===b){var c=a[1],d=a[2],e=a[3],f=a[6],g=a[7],h=a[11];return a[1]=a[4],a[2]=a[8],a[3]=a[12],a[4]=c,a[6]=a[9],a[7]=a[13],a[8]=d,a[9]=f,a[11]=a[14],a[12]=e,a[13]=g,a[14]=h,a}return b[0]=a[0],b[1]=a[4],b[2]=a[8],b[3]=a[12],b[4]=a[1],b[5]=a[5],b[6]=a[9],b[7]=a[13],b[8]=a[2],b[9]=a[6],b[10]=a[10],b[11]=a[14],b[12]=a[3],b[13]=a[7],b[14]=a[11],b[15]=a[15],b},c.mat4.multiply=function(a,b,c){c||(c=a);var d=a[0],e=a[1],f=a[2],g=a[3],h=a[4],i=a[5],j=a[6],k=a[7],l=a[8],m=a[9],n=a[10],o=a[11],p=a[12],q=a[13],r=a[14],s=a[15],t=b[0],u=b[1],v=b[2],w=b[3];return c[0]=t*d+u*h+v*l+w*p,c[1]=t*e+u*i+v*m+w*q,c[2]=t*f+u*j+v*n+w*r,c[3]=t*g+u*k+v*o+w*s,t=b[4],u=b[5],v=b[6],w=b[7],c[4]=t*d+u*h+v*l+w*p,c[5]=t*e+u*i+v*m+w*q,c[6]=t*f+u*j+v*n+w*r,c[7]=t*g+u*k+v*o+w*s,t=b[8],u=b[9],v=b[10],w=b[11],c[8]=t*d+u*h+v*l+w*p,c[9]=t*e+u*i+v*m+w*q,c[10]=t*f+u*j+v*n+w*r,c[11]=t*g+u*k+v*o+w*s,t=b[12],u=b[13],v=b[14],w=b[15],c[12]=t*d+u*h+v*l+w*p,c[13]=t*e+u*i+v*m+w*q,c[14]=t*f+u*j+v*n+w*r,c[15]=t*g+u*k+v*o+w*s,c},c.Point=function(a,b){this.x=a||0,this.y=b||0},c.Point.prototype.clone=function(){return new c.Point(this.x,this.y)},c.Point.prototype.constructor=c.Point,c.Rectangle=function(a,b,c,d){this.x=a||0,this.y=b||0,this.width=c||0,this.height=d||0},c.Rectangle.prototype.clone=function(){return new c.Rectangle(this.x,this.y,this.width,this.height)},c.Rectangle.prototype.contains=function(a,b){if(this.width<=0||this.height<=0)return!1;var c=this.x;if(a>=c&&a<=c+this.width){var d=this.y;if(b>=d&&b<=d+this.height)return!0}return!1},c.Rectangle.prototype.constructor=c.Rectangle,c.Polygon=function(a){if(a instanceof Array||(a=Array.prototype.slice.call(arguments)),"number"==typeof a[0]){for(var b=[],d=0,e=a.length;e>d;d+=2)b.push(new c.Point(a[d],a[d+1]));a=b}this.points=a},c.Polygon.prototype.clone=function(){for(var a=[],b=0;bb!=i>b&&(h-f)*(b-g)/(i-g)+f>a;j&&(c=!c)}return c},c.Polygon.prototype.constructor=c.Polygon,c.DisplayObject=function(){this.last=this,this.first=this,this.position=new c.Point,this.scale=new c.Point(1,1),this.pivot=new c.Point(0,0),this.rotation=0,this.alpha=1,this.visible=!0,this.hitArea=null,this.buttonMode=!1,this.renderable=!1,this.parent=null,this.stage=null,this.worldAlpha=1,this._interactive=!1,this.worldTransform=c.mat3.create(),this.localTransform=c.mat3.create(),this.color=[],this.dynamic=!0,this._sr=0,this._cr=1,this.filterArea=new c.Rectangle(0,0,1,1)},c.DisplayObject.prototype.constructor=c.DisplayObject,c.DisplayObject.prototype.setInteractive=function(a){this.interactive=a},Object.defineProperty(c.DisplayObject.prototype,"interactive",{get:function(){return this._interactive},set:function(a){this._interactive=a,this.stage&&(this.stage.dirty=!0)}}),Object.defineProperty(c.DisplayObject.prototype,"mask",{get:function(){return this._mask},set:function(a){a?this._mask?(a.start=this._mask.start,a.end=this._mask.end):(this.addFilter(a),a.renderable=!1):(this.removeFilter(this._mask),this._mask.renderable=!0),this._mask=a}}),Object.defineProperty(c.DisplayObject.prototype,"filters",{get:function(){return this._filters},set:function(a){if(a){this._filters&&this.removeFilter(this._filters),this.addFilter(a);for(var b=[],c=0;c=0&&b<=this.children.length))throw new Error(a+" The index "+b+" supplied is out of bounds "+this.children.length);if(void 0!=a.parent&&a.parent.removeChild(a),a.parent=this,this.stage){var c=a;do c.interactive&&(this.stage.dirty=!0),c.stage=this.stage,c=c._iNext;while(c)}var d,e,f=a.first,g=a.last;if(b==this.children.length){e=this.last;for(var h=this,i=this.last;h;)h.last==i&&(h.last=a.last),h=h.parent}else e=0===b?this:this.children[b-1].last;d=e._iNext,d&&(d._iPrev=g,g._iNext=d),f._iPrev=e,e._iNext=f,this.children.splice(b,0,a),this.__renderGroup&&(a.__renderGroup&&a.__renderGroup.removeDisplayObjectAndChildren(a),this.__renderGroup.addDisplayObjectAndChildren(a))},c.DisplayObjectContainer.prototype.swapChildren=function(){},c.DisplayObjectContainer.prototype.getChildAt=function(a){if(a>=0&&aa;a++)this.children[a].updateTransform()}},c.blendModes={},c.blendModes.NORMAL=0,c.blendModes.SCREEN=1,c.Sprite=function(a){c.DisplayObjectContainer.call(this),this.anchor=new c.Point,this.texture=a,this.blendMode=c.blendModes.NORMAL,this._width=0,this._height=0,a.baseTexture.hasLoaded?this.updateFrame=!0:(this.onTextureUpdateBind=this.onTextureUpdate.bind(this),this.texture.addEventListener("update",this.onTextureUpdateBind)),this.renderable=!0},c.Sprite.prototype=Object.create(c.DisplayObjectContainer.prototype),c.Sprite.prototype.constructor=c.Sprite,Object.defineProperty(c.Sprite.prototype,"width",{get:function(){return this.scale.x*this.texture.frame.width},set:function(a){this.scale.x=a/this.texture.frame.width,this._width=a}}),Object.defineProperty(c.Sprite.prototype,"height",{get:function(){return this.scale.y*this.texture.frame.height},set:function(a){this.scale.y=a/this.texture.frame.height,this._height=a}}),c.Sprite.prototype.setTexture=function(a){this.texture.baseTexture!=a.baseTexture?(this.textureChange=!0,this.texture=a,this.__renderGroup&&this.__renderGroup.updateTexture(this)):this.texture=a,this.updateFrame=!0},c.Sprite.prototype.onTextureUpdate=function(){this._width&&(this.scale.x=this._width/this.texture.frame.width),this._height&&(this.scale.y=this._height/this.texture.frame.height),this.updateFrame=!0},c.Sprite.fromFrame=function(a){var b=c.TextureCache[a];if(!b)throw new Error("The frameId '"+a+"' does not exist in the texture cache"+this);return new c.Sprite(b)},c.Sprite.fromImage=function(a){var b=c.Texture.fromImage(a);return new c.Sprite(b)},c.Stage=function(a){c.DisplayObjectContainer.call(this),this.worldTransform=c.mat3.create(),this.interactive=!0,this.interactionManager=new c.InteractionManager(this),this.dirty=!0,this.__childrenAdded=[],this.__childrenRemoved=[],this.stage=this,this.stage.hitArea=new c.Rectangle(0,0,1e5,1e5),this.setBackgroundColor(a),this.worldVisible=!0},c.Stage.prototype=Object.create(c.DisplayObjectContainer.prototype),c.Stage.prototype.constructor=c.Stage,c.Stage.prototype.setInteractionDelegate=function(a){this.interactionManager.setTargetDomElement(a)},c.Stage.prototype.updateTransform=function(){this.worldAlpha=1,this.vcount=c.visibleCount;for(var a=0,b=this.children.length;b>a;a++)this.children[a].updateTransform();this.dirty&&(this.dirty=!1,this.interactionManager.dirty=!0),this.interactive&&this.interactionManager.update()},c.Stage.prototype.setBackgroundColor=function(b){this.backgroundColor=b||0,this.backgroundColorSplit=a(this.backgroundColor);var c=this.backgroundColor.toString(16);c="000000".substr(0,6-c.length)+c,this.backgroundColorString="#"+c},c.Stage.prototype.getMousePosition=function(){return this.interactionManager.mouse.global},c.CustomRenderable=function(){c.DisplayObject.call(this),this.renderable=!0},c.CustomRenderable.prototype=Object.create(c.DisplayObject.prototype),c.CustomRenderable.prototype.constructor=c.CustomRenderable,c.CustomRenderable.prototype.renderCanvas=function(){},c.CustomRenderable.prototype.initWebGL=function(){},c.CustomRenderable.prototype.renderWebGL=function(){},c.Strip=function(a,b,d){c.DisplayObjectContainer.call(this),this.texture=a,this.blendMode=c.blendModes.NORMAL;try{this.uvs=new Float32Array([0,1,1,1,1,0,0,1]),this.verticies=new Float32Array([0,0,0,0,0,0,0,0,0]),this.colors=new Float32Array([1,1,1,1]),this.indices=new Uint16Array([0,1,2,3])}catch(e){this.uvs=[0,1,1,1,1,0,0,1],this.verticies=[0,0,0,0,0,0,0,0,0],this.colors=[1,1,1,1],this.indices=[0,1,2,3]}this.width=b,this.height=d,a.baseTexture.hasLoaded?(this.width=this.texture.frame.width,this.height=this.texture.frame.height,this.updateFrame=!0):(this.onTextureUpdateBind=this.onTextureUpdate.bind(this),this.texture.addEventListener("update",this.onTextureUpdateBind)),this.renderable=!0},c.Strip.prototype=Object.create(c.DisplayObjectContainer.prototype),c.Strip.prototype.constructor=c.Strip,c.Strip.prototype.setTexture=function(a){this.texture=a,this.width=a.frame.width,this.height=a.frame.height,this.updateFrame=!0},c.Strip.prototype.onTextureUpdate=function(){this.updateFrame=!0},c.Rope=function(a,b){c.Strip.call(this,a),this.points=b;try{this.verticies=new Float32Array(4*b.length),this.uvs=new Float32Array(4*b.length),this.colors=new Float32Array(2*b.length),this.indices=new Uint16Array(2*b.length)}catch(d){this.verticies=verticies,this.uvs=uvs,this.colors=colors,this.indices=indices}this.refresh()},c.Rope.prototype=Object.create(c.Strip.prototype),c.Rope.prototype.constructor=c.Rope,c.Rope.prototype.refresh=function(){var a=this.points;if(!(a.length<1)){var b=this.uvs,c=this.indices,d=this.colors,e=a[0],f=a[0];this.count-=.2,b[0]=0,b[1]=1,b[2]=0,b[3]=1,d[0]=1,d[1]=1,c[0]=0,c[1]=1;for(var g=a.length,h=1;g>h;h++){var f=a[h],i=4*h,j=h/(g-1);h%2?(b[i]=j,b[i+1]=0,b[i+2]=j,b[i+3]=1):(b[i]=j,b[i+1]=0,b[i+2]=j,b[i+3]=1),i=2*h,d[i]=1,d[i+1]=1,i=2*h,c[i]=i,c[i+1]=i+1,e=f}}},c.Rope.prototype.updateTransform=function(){var a=this.points;if(!(a.length<1)){var b,d=this.verticies,e=a[0],f={x:0,y:0},g=a[0];this.count-=.2,d[0]=g.x+f.x,d[1]=g.y+f.y,d[2]=g.x-f.x,d[3]=g.y-f.y;for(var h=a.length,i=1;h>i;i++){var g=a[i],j=4*i;b=i1&&(k=1);var l=Math.sqrt(f.x*f.x+f.y*f.y),m=this.texture.height/2;f.x/=l,f.y/=l,f.x*=m,f.y*=m,d[j]=g.x+f.x,d[j+1]=g.y+f.y,d[j+2]=g.x-f.x,d[j+3]=g.y-f.y,e=g}c.DisplayObjectContainer.prototype.updateTransform.call(this)}},c.Rope.prototype.setTexture=function(a){this.texture=a,this.updateFrame=!0},c.TilingSprite=function(a,b,d){c.DisplayObjectContainer.call(this),this.texture=a,this.width=b,this.height=d,this.tileScale=new c.Point(1,1),this.tilePosition=new c.Point(0,0),this.renderable=!0,this.blendMode=c.blendModes.NORMAL},c.TilingSprite.prototype=Object.create(c.DisplayObjectContainer.prototype),c.TilingSprite.prototype.constructor=c.TilingSprite,c.TilingSprite.prototype.setTexture=function(a){this.texture=a,this.updateFrame=!0},c.TilingSprite.prototype.onTextureUpdate=function(){this.updateFrame=!0},c.AbstractFilter=function(a,b){this.passes=[this],this.dirty=!0,this.padding=0,this.uniforms=b||{},this.fragmentSrc=a||[]},c.FilterBlock=function(){this.visible=!0,this.renderable=!0},c.Graphics=function(){c.DisplayObjectContainer.call(this),this.renderable=!0,this.fillAlpha=1,this.lineWidth=0,this.lineColor="black",this.graphicsData=[],this.currentPath={points:[]}},c.Graphics.prototype=Object.create(c.DisplayObjectContainer.prototype),c.Graphics.prototype.constructor=c.Graphics,c.Graphics.prototype.lineStyle=function(a,b,d){0===this.currentPath.points.length&&this.graphicsData.pop(),this.lineWidth=a||0,this.lineColor=b||0,this.lineAlpha=void 0==d?1:d,this.currentPath={lineWidth:this.lineWidth,lineColor:this.lineColor,lineAlpha:this.lineAlpha,fillColor:this.fillColor,fillAlpha:this.fillAlpha,fill:this.filling,points:[],type:c.Graphics.POLY},this.graphicsData.push(this.currentPath)},c.Graphics.prototype.moveTo=function(a,b){0===this.currentPath.points.length&&this.graphicsData.pop(),this.currentPath=this.currentPath={lineWidth:this.lineWidth,lineColor:this.lineColor,lineAlpha:this.lineAlpha,fillColor:this.fillColor,fillAlpha:this.fillAlpha,fill:this.filling,points:[],type:c.Graphics.POLY},this.currentPath.points.push(a,b),this.graphicsData.push(this.currentPath)},c.Graphics.prototype.lineTo=function(a,b){this.currentPath.points.push(a,b),this.dirty=!0},c.Graphics.prototype.beginFill=function(a,b){this.filling=!0,this.fillColor=a||0,this.fillAlpha=void 0==b?1:b},c.Graphics.prototype.endFill=function(){this.filling=!1,this.fillColor=null,this.fillAlpha=1},c.Graphics.prototype.drawRect=function(a,b,d,e){0===this.currentPath.points.length&&this.graphicsData.pop(),this.currentPath={lineWidth:this.lineWidth,lineColor:this.lineColor,lineAlpha:this.lineAlpha,fillColor:this.fillColor,fillAlpha:this.fillAlpha,fill:this.filling,points:[a,b,d,e],type:c.Graphics.RECT},this.graphicsData.push(this.currentPath),this.dirty=!0},c.Graphics.prototype.drawCircle=function(a,b,d){0===this.currentPath.points.length&&this.graphicsData.pop(),this.currentPath={lineWidth:this.lineWidth,lineColor:this.lineColor,lineAlpha:this.lineAlpha,fillColor:this.fillColor,fillAlpha:this.fillAlpha,fill:this.filling,points:[a,b,d,d],type:c.Graphics.CIRC},this.graphicsData.push(this.currentPath),this.dirty=!0},c.Graphics.prototype.drawElipse=function(a,b,d,e){0===this.currentPath.points.length&&this.graphicsData.pop(),this.currentPath={lineWidth:this.lineWidth,lineColor:this.lineColor,lineAlpha:this.lineAlpha,fillColor:this.fillColor,fillAlpha:this.fillAlpha,fill:this.filling,points:[a,b,d,e],type:c.Graphics.ELIP},this.graphicsData.push(this.currentPath),this.dirty=!0},c.Graphics.prototype.clear=function(){this.lineWidth=0,this.filling=!1,this.dirty=!0,this.clearDirty=!0,this.graphicsData=[],this.bounds=null},c.Graphics.prototype.updateFilterBounds=function(){if(!this.bounds){for(var a,b,d,e=1/0,f=-1/0,g=1/0,h=-1/0,i=0;ib?b:e,f=b+m>f?b+m:f,g=g>d?b:g,h=d+n>h?d+n:h}else if(k===c.Graphics.CIRC||k===c.Graphics.ELIP){b=a.x,d=a.y;var o=a.radius+l/2;e=e>b-o?b-o:e,f=b+o>f?b+o:f,g=g>d-o?d-o:g,h=d+o>h?d+o:h}else for(var p=0;pb-l?b-l:e,f=b+l>f?b+l:f,g=g>d-l?d-l:g,h=d+l>h?d+l:h}this.bounds=new c.Rectangle(e,g,f-e,h-g)}},c.Graphics.POLY=0,c.Graphics.RECT=1,c.Graphics.CIRC=2,c.Graphics.ELIP=3,c.CanvasGraphics=function(){},c.CanvasGraphics.renderGraphics=function(a,b){for(var d=a.worldAlpha,e=0;e1&&(d=1,console.log("Pixi.js warning: masks in canvas can only mask using the first path in the graphics object"));for(var e=0;1>e;e++){var f=a.graphicsData[e],g=f.points;if(f.type==c.Graphics.POLY){b.beginPath(),b.moveTo(g[0],g[1]);for(var h=1;h0&&(c.Texture.frameUpdates=[])},c.CanvasRenderer.prototype.resize=function(a,b){this.width=a,this.height=b,this.view.width=a,this.view.height=b},c.CanvasRenderer.prototype.renderDisplayObject=function(a){var b,d=this.context;d.globalCompositeOperation="source-over";var e=a.last._iNext;a=a.first;do if(b=a.worldTransform,a.visible)if(a.renderable){if(a instanceof c.Sprite){var f=a.texture.frame;f&&f.width&&f.height&&(d.globalAlpha=a.worldAlpha,d.setTransform(b[0],b[3],b[1],b[4],b[2],b[5]),d.drawImage(a.texture.baseTexture.source,f.x,f.y,f.width,f.height,a.anchor.x*-f.width,a.anchor.y*-f.height,f.width,f.height))}else if(a instanceof c.Strip)d.setTransform(b[0],b[3],b[1],b[4],b[2],b[5]),this.renderStrip(a);else if(a instanceof c.TilingSprite)d.setTransform(b[0],b[3],b[1],b[4],b[2],b[5]),this.renderTilingSprite(a);else if(a instanceof c.CustomRenderable)d.setTransform(b[0],b[3],b[1],b[4],b[2],b[5]),a.renderCanvas(this);else if(a instanceof c.Graphics)d.setTransform(b[0],b[3],b[1],b[4],b[2],b[5]),c.CanvasGraphics.renderGraphics(a,d);else if(a instanceof c.FilterBlock&&a.data instanceof c.Graphics){var g=a.data;if(a.open){d.save();var h=g.alpha,i=g.worldTransform;d.setTransform(i[0],i[3],i[1],i[4],i[2],i[5]),g.worldAlpha=.5,d.worldAlpha=0,c.CanvasGraphics.renderGraphicsMask(g,d),d.clip(),g.worldAlpha=h}else d.restore()}a=a._iNext}else a=a._iNext;else a=a.last._iNext;while(a!=e)},c.CanvasRenderer.prototype.renderStripFlat=function(a){var b=this.context,c=a.verticies;a.uvs;var d=c.length/2;this.count++,b.beginPath();for(var e=1;d-2>e;e++){var f=2*e,g=c[f],h=c[f+2],i=c[f+4],j=c[f+1],k=c[f+3],l=c[f+5];b.moveTo(g,j),b.lineTo(h,k),b.lineTo(i,l)}b.fillStyle="#FF0000",b.fill(),b.closePath()},c.CanvasRenderer.prototype.renderTilingSprite=function(a){var b=this.context;b.globalAlpha=a.worldAlpha,a.__tilePattern||(a.__tilePattern=b.createPattern(a.texture.baseTexture.source,"repeat")),b.beginPath();var c=a.tilePosition,d=a.tileScale;b.scale(d.x,d.y),b.translate(c.x,c.y),b.fillStyle=a.__tilePattern,b.fillRect(-c.x,-c.y,a.width/d.x,a.height/d.y),b.scale(1/d.x,1/d.y),b.translate(-c.x,-c.y),b.closePath()},c.CanvasRenderer.prototype.renderStrip=function(a){var b=this.context,c=a.verticies,d=a.uvs,e=c.length/2;this.count++;for(var f=1;e-2>f;f++){var g=2*f,h=c[g],i=c[g+2],j=c[g+4],k=c[g+1],l=c[g+3],m=c[g+5],n=d[g]*a.texture.width,o=d[g+2]*a.texture.width,p=d[g+4]*a.texture.width,q=d[g+1]*a.texture.height,r=d[g+3]*a.texture.height,s=d[g+5]*a.texture.height;b.save(),b.beginPath(),b.moveTo(h,k),b.lineTo(i,l),b.lineTo(j,m),b.closePath(),b.clip();var t=n*r+q*p+o*s-r*p-q*o-n*s,u=h*r+q*j+i*s-r*j-q*i-h*s,v=n*i+h*p+o*j-i*p-h*o-n*j,w=n*r*j+q*i*p+h*o*s-h*r*p-q*o*j-n*i*s,x=k*r+q*m+l*s-r*m-q*l-k*s,y=n*l+k*p+o*m-l*p-k*o-n*m,z=n*r*m+q*l*p+k*o*s-k*r*p-q*o*m-n*l*s;b.transform(u/t,x/t,v/t,y/t,w/t,z/t),b.drawImage(a.texture.baseTexture.source,0,0),b.restore()}},c.PixiShader=function(){this.program,this.fragmentSrc=["precision lowp float;","varying vec2 vTextureCoord;","varying float vColor;","uniform sampler2D uSampler;","void main(void) {","gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor;","}"],this.textureCount=0},c.PixiShader.prototype.init=function(){var a=c.compileProgram(this.vertexSrc||c.PixiShader.defaultVertexSrc,this.fragmentSrc),b=c.gl;b.useProgram(a),this.uSampler=b.getUniformLocation(a,"uSampler"),this.projectionVector=b.getUniformLocation(a,"projectionVector"),this.offsetVector=b.getUniformLocation(a,"offsetVector"),this.dimensions=b.getUniformLocation(a,"dimensions"),this.aVertexPosition=b.getAttribLocation(a,"aVertexPosition"),this.colorAttribute=b.getAttribLocation(a,"aColor"),this.aTextureCoord=b.getAttribLocation(a,"aTextureCoord");for(var d in this.uniforms)this.uniforms[d].uniformLocation=b.getUniformLocation(a,d);this.initUniforms(),this.program=a},c.PixiShader.prototype.initUniforms=function(){this.textureCount=1;var a;for(var b in this.uniforms){var a=this.uniforms[b],d=a.type;"sampler2D"==d?(a._init=!1,null!==a.value&&this.initSampler2D(a)):"mat2"==d||"mat3"==d||"mat4"==d?(a.glMatrix=!0,a.glValueLength=1,"mat2"==d?a.glFunc=c.gl.uniformMatrix2fv:"mat3"==d?a.glFunc=c.gl.uniformMatrix3fv:"mat4"==d&&(a.glFunc=c.gl.uniformMatrix4fv)):(a.glFunc=c.gl["uniform"+d],a.glValueLength="2f"==d||"2i"==d?2:"3f"==d||"3i"==d?3:"4f"==d||"4i"==d?4:1)}},c.PixiShader.prototype.initSampler2D=function(a){if(a.value&&a.value.baseTexture&&a.value.baseTexture.hasLoaded){if(c.gl.activeTexture(c.gl["TEXTURE"+this.textureCount]),c.gl.bindTexture(c.gl.TEXTURE_2D,a.value.baseTexture._glTexture),a.textureData){var b=a.textureData,d=b.magFilter?b.magFilter:c.gl.LINEAR,e=b.minFilter?b.minFilter:c.gl.LINEAR,f=b.wrapS?b.wrapS:c.gl.CLAMP_TO_EDGE,g=b.wrapT?b.wrapT:c.gl.CLAMP_TO_EDGE,h=b.luminance?c.gl.LUMINANCE:c.gl.RGBA;if(b.repeat&&(f=c.gl.REPEAT,g=c.gl.REPEAT),c.gl.pixelStorei(c.gl.UNPACK_FLIP_Y_WEBGL,!1),b.width){var i=b.width?b.width:512,j=b.height?b.height:2,k=b.border?b.border:0;c.gl.texImage2D(c.gl.TEXTURE_2D,0,h,i,j,k,h,c.gl.UNSIGNED_BYTE,null)}else c.gl.texImage2D(c.gl.TEXTURE_2D,0,h,c.gl.RGBA,c.gl.UNSIGNED_BYTE,a.value.baseTexture.source);c.gl.texParameteri(c.gl.TEXTURE_2D,c.gl.TEXTURE_MAG_FILTER,d),c.gl.texParameteri(c.gl.TEXTURE_2D,c.gl.TEXTURE_MIN_FILTER,e),c.gl.texParameteri(c.gl.TEXTURE_2D,c.gl.TEXTURE_WRAP_S,f),c.gl.texParameteri(c.gl.TEXTURE_2D,c.gl.TEXTURE_WRAP_T,g)}c.gl.uniform1i(a.uniformLocation,this.textureCount),a._init=!0,this.textureCount++}},c.PixiShader.prototype.syncUniforms=function(){this.textureCount=1;var a;for(var b in this.uniforms)a=this.uniforms[b],1==a.glValueLength?a.glMatrix===!0?a.glFunc.call(c.gl,a.uniformLocation,a.transpose,a.value):a.glFunc.call(c.gl,a.uniformLocation,a.value):2==a.glValueLength?a.glFunc.call(c.gl,a.uniformLocation,a.value.x,a.value.y):3==a.glValueLength?a.glFunc.call(c.gl,a.uniformLocation,a.value.x,a.value.y,a.value.z):4==a.glValueLength?a.glFunc.call(c.gl,a.uniformLocation,a.value.x,a.value.y,a.value.z,a.value.w):"sampler2D"==a.type&&(a._init?(c.gl.activeTexture(c.gl["TEXTURE"+this.textureCount]),c.gl.bindTexture(c.gl.TEXTURE_2D,a.value.baseTexture._glTexture),c.gl.uniform1i(a.uniformLocation,this.textureCount),this.textureCount++):this.initSampler2D(a))},c.PixiShader.defaultVertexSrc=["attribute vec2 aVertexPosition;","attribute vec2 aTextureCoord;","attribute float aColor;","uniform vec2 projectionVector;","uniform vec2 offsetVector;","varying vec2 vTextureCoord;","varying float vColor;","const vec2 center = vec2(-1.0, 1.0);","void main(void) {","gl_Position = vec4( ((aVertexPosition + offsetVector) / projectionVector) + center , 0.0, 1.0);","vTextureCoord = aTextureCoord;","vColor = aColor;","}"],c.PrimitiveShader=function(){this.program,this.fragmentSrc=["precision mediump float;","varying vec4 vColor;","void main(void) {","gl_FragColor = vColor;","}"],this.vertexSrc=["attribute vec2 aVertexPosition;","attribute vec4 aColor;","uniform mat3 translationMatrix;","uniform vec2 projectionVector;","uniform vec2 offsetVector;","uniform float alpha;","varying vec4 vColor;","void main(void) {","vec3 v = translationMatrix * vec3(aVertexPosition , 1.0);","v -= offsetVector.xyx;","gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / -projectionVector.y + 1.0 , 0.0, 1.0);","vColor = aColor * alpha;","}"] -},c.PrimitiveShader.prototype.init=function(){var a=c.compileProgram(this.vertexSrc,this.fragmentSrc),b=c.gl;b.useProgram(a),this.projectionVector=b.getUniformLocation(a,"projectionVector"),this.offsetVector=b.getUniformLocation(a,"offsetVector"),this.aVertexPosition=b.getAttribLocation(a,"aVertexPosition"),this.colorAttribute=b.getAttribLocation(a,"aColor"),this.translationMatrix=b.getUniformLocation(a,"translationMatrix"),this.alpha=b.getUniformLocation(a,"alpha"),this.program=a},c.StripShader=function(){this.program,this.fragmentSrc=["precision mediump float;","varying vec2 vTextureCoord;","varying float vColor;","uniform float alpha;","uniform sampler2D uSampler;","void main(void) {","gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));","gl_FragColor = gl_FragColor * alpha;","}"],this.vertexSrc=["attribute vec2 aVertexPosition;","attribute vec2 aTextureCoord;","attribute float aColor;","uniform mat3 translationMatrix;","uniform vec2 projectionVector;","varying vec2 vTextureCoord;","varying vec2 offsetVector;","varying float vColor;","void main(void) {","vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);","v -= offsetVector.xyx;","gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / projectionVector.y + 1.0 , 0.0, 1.0);","vTextureCoord = aTextureCoord;","vColor = aColor;","}"]},c.StripShader.prototype.init=function(){var a=c.compileProgram(this.vertexSrc,this.fragmentSrc),b=c.gl;b.useProgram(a),this.uSampler=b.getUniformLocation(a,"uSampler"),this.projectionVector=b.getUniformLocation(a,"projectionVector"),this.offsetVector=b.getUniformLocation(a,"offsetVector"),this.colorAttribute=b.getAttribLocation(a,"aColor"),this.aVertexPosition=b.getAttribLocation(a,"aVertexPosition"),this.aTextureCoord=b.getAttribLocation(a,"aTextureCoord"),this.translationMatrix=b.getUniformLocation(a,"translationMatrix"),this.alpha=b.getUniformLocation(a,"alpha"),this.program=a},c._batchs=[],c._getBatch=function(a){return 0===c._batchs.length?new c.WebGLBatch(a):c._batchs.pop()},c._returnBatch=function(a){a.clean(),c._batchs.push(a)},c._restoreBatchs=function(a){for(var b=0;bc;c++){var d=6*c,e=4*c;this.indices[d+0]=e+0,this.indices[d+1]=e+1,this.indices[d+2]=e+2,this.indices[d+3]=e+0,this.indices[d+4]=e+2,this.indices[d+5]=e+3}a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this.indexBuffer),a.bufferData(a.ELEMENT_ARRAY_BUFFER,this.indices,a.STATIC_DRAW)},c.WebGLBatch.prototype.refresh=function(){this.gl,this.dynamicSizethis.width&&(f.width=this.width),f.y<0&&(f.y=0),f.height>this.height&&(f.height=this.height),b.bindFramebuffer(b.FRAMEBUFFER,e.frameBuffer),b.viewport(0,0,f.width,f.height),c.projection.x=f.width/2,c.projection.y=-f.height/2,c.offset.x=-f.x,c.offset.y=-f.y,b.uniform2f(c.defaultShader.projectionVector,f.width/2,-f.height/2),b.uniform2f(c.defaultShader.offsetVector,-f.x,-f.y),b.colorMask(!0,!0,!0,!0),b.clearColor(0,0,0,0),b.clear(b.COLOR_BUFFER_BIT),a._glFilterTexture=e},c.WebGLFilterManager.prototype.popFilter=function(){var a=c.gl,b=this.filterStack.pop(),d=b.target.filterArea,e=b._glFilterTexture;if(b.filterPasses.length>1){a.viewport(0,0,d.width,d.height),a.bindBuffer(a.ARRAY_BUFFER,this.vertexBuffer),this.vertexArray[0]=0,this.vertexArray[1]=d.height,this.vertexArray[2]=d.width,this.vertexArray[3]=d.height,this.vertexArray[4]=0,this.vertexArray[5]=0,this.vertexArray[6]=d.width,this.vertexArray[7]=0,a.bufferSubData(a.ARRAY_BUFFER,0,this.vertexArray),a.bindBuffer(a.ARRAY_BUFFER,this.uvBuffer),this.uvArray[2]=d.width/this.width,this.uvArray[5]=d.height/this.height,this.uvArray[6]=d.width/this.width,this.uvArray[7]=d.height/this.height,a.bufferSubData(a.ARRAY_BUFFER,0,this.uvArray);var f=e,g=this.texturePool.pop();g||(g=new c.FilterTexture(this.width,this.height)),a.bindFramebuffer(a.FRAMEBUFFER,g.frameBuffer),a.clear(a.COLOR_BUFFER_BIT),a.disable(a.BLEND);for(var h=0;hs?s:E,E=E>t?t:E,E=E>u?u:E,E=E>v?v:E,F=F>w?w:F,F=F>x?x:F,F=F>y?y:F,F=F>z?z:F,C=s>C?s:C,C=t>C?t:C,C=u>C?u:C,C=v>C?v:C,D=w>D?w:D,D=x>D?x:D,D=y>D?y:D,D=z>D?z:D),l=!1,A=A._iNext}while(A!=B);a.filterArea.x=E,a.filterArea.y=F,a.filterArea.width=C-E,a.filterArea.height=D-F},c.FilterTexture=function(a,b){var d=c.gl;this.frameBuffer=d.createFramebuffer(),this.texture=d.createTexture(),d.bindTexture(d.TEXTURE_2D,this.texture),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MAG_FILTER,d.LINEAR),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MIN_FILTER,d.LINEAR),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_S,d.CLAMP_TO_EDGE),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_T,d.CLAMP_TO_EDGE),d.bindFramebuffer(d.FRAMEBUFFER,this.framebuffer),d.bindFramebuffer(d.FRAMEBUFFER,this.frameBuffer),d.framebufferTexture2D(d.FRAMEBUFFER,d.COLOR_ATTACHMENT0,d.TEXTURE_2D,this.texture,0),this.resize(a,b)},c.FilterTexture.prototype.resize=function(a,b){this.width=a,this.height=b;var d=c.gl;d.bindTexture(d.TEXTURE_2D,this.texture),d.texImage2D(d.TEXTURE_2D,0,d.RGBA,a,b,0,d.RGBA,d.UNSIGNED_BYTE,null)},c.WebGLGraphics=function(){},c.WebGLGraphics.renderGraphics=function(a,b){var d=c.gl;a._webGL||(a._webGL={points:[],indices:[],lastIndex:0,buffer:d.createBuffer(),indexBuffer:d.createBuffer()}),a.dirty&&(a.dirty=!1,a.clearDirty&&(a.clearDirty=!1,a._webGL.lastIndex=0,a._webGL.points=[],a._webGL.indices=[]),c.WebGLGraphics.updateGraphics(a)),c.activatePrimitiveShader();var e=c.mat3.clone(a.worldTransform);c.mat3.transpose(e),d.blendFunc(d.ONE,d.ONE_MINUS_SRC_ALPHA),d.uniformMatrix3fv(c.primitiveShader.translationMatrix,!1,e),d.uniform2f(c.primitiveShader.projectionVector,b.x,-b.y),d.uniform2f(c.primitiveShader.offsetVector,-c.offset.x,-c.offset.y),d.uniform1f(c.primitiveShader.alpha,a.worldAlpha),d.bindBuffer(d.ARRAY_BUFFER,a._webGL.buffer),d.vertexAttribPointer(c.primitiveShader.aVertexPosition,2,d.FLOAT,!1,24,0),d.vertexAttribPointer(c.primitiveShader.colorAttribute,4,d.FLOAT,!1,24,8),d.bindBuffer(d.ELEMENT_ARRAY_BUFFER,a._webGL.indexBuffer),d.drawElements(d.TRIANGLE_STRIP,a._webGL.indices.length,d.UNSIGNED_SHORT,0),c.deactivatePrimitiveShader()},c.WebGLGraphics.updateGraphics=function(a){for(var b=a._webGL.lastIndex;b3&&c.WebGLGraphics.buildPoly(d,a._webGL),d.lineWidth>0&&c.WebGLGraphics.buildLine(d,a._webGL)):d.type==c.Graphics.RECT?c.WebGLGraphics.buildRectangle(d,a._webGL):(d.type==c.Graphics.CIRC||d.type==c.Graphics.ELIP)&&c.WebGLGraphics.buildCircle(d,a._webGL)}a._webGL.lastIndex=a.graphicsData.length;var e=c.gl;a._webGL.glPoints=new Float32Array(a._webGL.points),e.bindBuffer(e.ARRAY_BUFFER,a._webGL.buffer),e.bufferData(e.ARRAY_BUFFER,a._webGL.glPoints,e.STATIC_DRAW),a._webGL.glIndicies=new Uint16Array(a._webGL.indices),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,a._webGL.indexBuffer),e.bufferData(e.ELEMENT_ARRAY_BUFFER,a._webGL.glIndicies,e.STATIC_DRAW)},c.WebGLGraphics.buildRectangle=function(b,d){var e=b.points,f=e[0],g=e[1],h=e[2],i=e[3];if(b.fill){var j=a(b.fillColor),k=b.fillAlpha,l=j[0]*k,m=j[1]*k,n=j[2]*k,o=d.points,p=d.indices,q=o.length/6;o.push(f,g),o.push(l,m,n,k),o.push(f+h,g),o.push(l,m,n,k),o.push(f,g+i),o.push(l,m,n,k),o.push(f+h,g+i),o.push(l,m,n,k),p.push(q,q,q+1,q+2,q+3,q+3)}b.lineWidth&&(b.points=[f,g,f+h,g,f+h,g+i,f,g+i,f,g],c.WebGLGraphics.buildLine(b,d))},c.WebGLGraphics.buildCircle=function(b,d){var e=b.points,f=e[0],g=e[1],h=e[2],i=e[3],j=40,k=2*Math.PI/j;if(b.fill){var l=a(b.fillColor),m=b.fillAlpha,n=l[0]*m,o=l[1]*m,p=l[2]*m,q=d.points,r=d.indices,s=q.length/6;r.push(s);for(var t=0;j+1>t;t++)q.push(f,g,n,o,p,m),q.push(f+Math.sin(k*t)*h,g+Math.cos(k*t)*i,n,o,p,m),r.push(s++,s++);r.push(s-1)}if(b.lineWidth){b.points=[];for(var t=0;j+1>t;t++)b.points.push(f+Math.sin(k*t)*h,g+Math.cos(k*t)*i);c.WebGLGraphics.buildLine(b,d)}},c.WebGLGraphics.buildLine=function(b,d){var e=b.points;if(0!==e.length){if(b.lineWidth%2)for(var f=0;ff;f++)k=e[2*(f-1)],l=e[2*(f-1)+1],m=e[2*f],n=e[2*f+1],o=e[2*(f+1)],p=e[2*(f+1)+1],q=-(l-n),r=k-m,E=Math.sqrt(q*q+r*r),q/=E,r/=E,q*=K,r*=K,s=-(n-p),t=m-o,E=Math.sqrt(s*s+t*t),s/=E,t/=E,s*=K,t*=K,w=-r+l-(-r+n),x=-q+m-(-q+k),y=(-q+k)*(-r+n)-(-q+m)*(-r+l),z=-t+p-(-t+n),A=-s+m-(-s+o),B=(-s+o)*(-t+n)-(-s+m)*(-t+p),C=w*A-z*x,Math.abs(C)<.1?(C+=10.1,F.push(m-q,n-r,N,O,P,M),F.push(m+q,n+r,N,O,P,M)):(px=(x*B-A*y)/C,py=(z*y-w*B)/C,D=(px-m)*(px-m)+(py-n)+(py-n),D>19600?(u=q-s,v=r-t,E=Math.sqrt(u*u+v*v),u/=E,v/=E,u*=K,v*=K,F.push(m-u,n-v),F.push(N,O,P,M),F.push(m+u,n+v),F.push(N,O,P,M),F.push(m-u,n-v),F.push(N,O,P,M),I++):(F.push(px,py),F.push(N,O,P,M),F.push(m-(px-m),n-(py-n)),F.push(N,O,P,M)));k=e[2*(H-2)],l=e[2*(H-2)+1],m=e[2*(H-1)],n=e[2*(H-1)+1],q=-(l-n),r=k-m,E=Math.sqrt(q*q+r*r),q/=E,r/=E,q*=K,r*=K,F.push(m-q,n-r),F.push(N,O,P,M),F.push(m+q,n+r),F.push(N,O,P,M),G.push(J);for(var f=0;I>f;f++)G.push(J++);G.push(J-1)}},c.WebGLGraphics.buildPoly=function(b,d){var e=b.points;if(!(e.length<6)){for(var f=d.points,g=d.indices,h=e.length/2,i=a(b.fillColor),j=b.fillAlpha,k=i[0]*j,l=i[1]*j,m=i[2]*j,n=c.PolyK.Triangulate(e),o=f.length/6,p=0;pp;p++)f.push(e[2*p],e[2*p+1],k,l,m,j)}},c._defaultFrame=new c.Rectangle(0,0,1,1),c.gl,c.WebGLRenderer=function(a,b,d,e,f){this.transparent=!!e,this.width=a||800,this.height=b||600,this.view=d||document.createElement("canvas"),this.view.width=this.width,this.view.height=this.height;var g=this;this.view.addEventListener("webglcontextlost",function(a){g.handleContextLost(a)},!1),this.view.addEventListener("webglcontextrestored",function(a){g.handleContextRestored(a)},!1),this.batchs=[];var h={alpha:this.transparent,antialias:!!f,premultipliedAlpha:!1,stencil:!0};try{c.gl=this.gl=this.view.getContext("experimental-webgl",h)}catch(i){try{c.gl=this.gl=this.view.getContext("webgl",h)}catch(i){throw new Error(" This browser does not support webGL. Try using the canvas renderer"+this)}}c.initDefaultShaders();var j=this.gl;j.useProgram(c.defaultShader.program),c.WebGLRenderer.gl=j,this.batch=new c.WebGLBatch(j),j.disable(j.DEPTH_TEST),j.disable(j.CULL_FACE),j.enable(j.BLEND),j.colorMask(!0,!0,!0,this.transparent),c.projection=new c.Point(400,300),c.offset=new c.Point(0,0),this.resize(this.width,this.height),this.contextLost=!1,this.stageRenderGroup=new c.WebGLRenderGroup(this.gl,this.transparent)},c.WebGLRenderer.prototype.constructor=c.WebGLRenderer,c.WebGLRenderer.getBatch=function(){return 0===c._batchs.length?new c.WebGLBatch(c.WebGLRenderer.gl):c._batchs.pop()},c.WebGLRenderer.returnBatch=function(a){a.clean(),c._batchs.push(a)},c.WebGLRenderer.prototype.render=function(a){if(!this.contextLost){this.__stage!==a&&(this.__stage=a,this.stageRenderGroup.setRenderable(a)),c.WebGLRenderer.updateTextures(),c.visibleCount++,a.updateTransform();var b=this.gl;if(b.colorMask(!0,!0,!0,this.transparent),b.viewport(0,0,this.width,this.height),b.bindFramebuffer(b.FRAMEBUFFER,null),b.clearColor(a.backgroundColorSplit[0],a.backgroundColorSplit[1],a.backgroundColorSplit[2],!this.transparent),b.clear(b.COLOR_BUFFER_BIT),this.stageRenderGroup.backgroundColor=a.backgroundColorSplit,c.projection.x=this.width/2,c.projection.y=-this.height/2,this.stageRenderGroup.render(c.projection),a.interactive&&(a._interactiveEventsAdded||(a._interactiveEventsAdded=!0,a.interactionManager.setTarget(this))),c.Texture.frameUpdates.length>0){for(var d=0;dn;n++)renderable=this.batchs[n],renderable instanceof c.WebGLBatch?this.batchs[n].render():this.renderSpecial(renderable,b);endBatch instanceof c.WebGLBatch?endBatch.render(0,h+1):this.renderSpecial(endBatch,b)},c.WebGLRenderGroup.prototype.renderSpecial=function(a,b){var d=a.vcount===c.visibleCount;a instanceof c.TilingSprite?d&&this.renderTilingSprite(a,b):a instanceof c.Strip?d&&this.renderStrip(a,b):a instanceof c.CustomRenderable?d&&a.renderWebGL(this,b):a instanceof c.Graphics?d&&a.renderable&&c.WebGLGraphics.renderGraphics(a,b):a instanceof c.FilterBlock&&this.handleFilterBlock(a,b)},flip=!1;var e=[],f=0;return c.WebGLRenderGroup.prototype.handleFilterBlock=function(a,b){var d=c.gl;if(a.open)a.data instanceof Array?this.filterManager.pushFilter(a):(f++,e.push(a),d.enable(d.STENCIL_TEST),d.colorMask(!1,!1,!1,!1),d.stencilFunc(d.ALWAYS,1,1),d.stencilOp(d.KEEP,d.KEEP,d.INCR),c.WebGLGraphics.renderGraphics(a.data,b),d.colorMask(!0,!0,!0,!0),d.stencilFunc(d.NOTEQUAL,0,e.length),d.stencilOp(d.KEEP,d.KEEP,d.KEEP));else if(a.data instanceof Array)this.filterManager.popFilter();else{var g=e.pop(a);g&&(d.colorMask(!1,!1,!1,!1),d.stencilFunc(d.ALWAYS,1,1),d.stencilOp(d.KEEP,d.KEEP,d.DECR),c.WebGLGraphics.renderGraphics(g.data,b),d.colorMask(!0,!0,!0,!0),d.stencilFunc(d.NOTEQUAL,0,e.length),d.stencilOp(d.KEEP,d.KEEP,d.KEEP)),d.disable(d.STENCIL_TEST)}},c.WebGLRenderGroup.prototype.updateTexture=function(a){this.removeObject(a);for(var b=a.first;b!=this.root&&(b=b._iPrev,!b.renderable||!b.__renderGroup););for(var c=a.last;c._iNext&&(c=c._iNext,!c.renderable||!c.__renderGroup););this.insertObject(a,b,c)},c.WebGLRenderGroup.prototype.addFilterBlocks=function(a,b){a.__renderGroup=this,b.__renderGroup=this;for(var c=a;c!=this.root.first&&(c=c._iPrev,!c.renderable||!c.__renderGroup););this.insertAfter(a,c);for(var d=b;d!=this.root.first&&(d=d._iPrev,!d.renderable||!d.__renderGroup););this.insertAfter(b,d)},c.WebGLRenderGroup.prototype.removeFilterBlocks=function(a,b){this.removeObject(a),this.removeObject(b)},c.WebGLRenderGroup.prototype.addDisplayObjectAndChildren=function(a){a.__renderGroup&&a.__renderGroup.removeDisplayObjectAndChildren(a);for(var b=a.first;b!=this.root.first&&(b=b._iPrev,!b.renderable||!b.__renderGroup););for(var c=a.last;c._iNext&&(c=c._iNext,!c.renderable||!c.__renderGroup););var d=a.first,e=a.last._iNext;do d.__renderGroup=this,d.renderable&&(this.insertObject(d,b,c),b=d),d=d._iNext;while(d!=e)},c.WebGLRenderGroup.prototype.removeDisplayObjectAndChildren=function(a){if(a.__renderGroup==this){a.last;do a.__renderGroup=null,a.renderable&&this.removeObject(a),a=a._iNext;while(a)}},c.WebGLRenderGroup.prototype.insertObject=function(a,b,d){var e=b,f=d;if(a instanceof c.Sprite){var g,h;if(e instanceof c.Sprite){if(g=e.batch,g&&g.texture==a.texture.baseTexture&&g.blendMode==a.blendMode)return g.insertAfter(a,e),void 0}else g=e;if(f)if(f instanceof c.Sprite){if(h=f.batch){if(h.texture==a.texture.baseTexture&&h.blendMode==a.blendMode)return h.insertBefore(a,f),void 0;if(h==g){var i=g.split(f),j=c.WebGLRenderer.getBatch(),k=this.batchs.indexOf(g);return j.init(a),this.batchs.splice(k+1,0,j,i),void 0}}}else h=f;var j=c.WebGLRenderer.getBatch();if(j.init(a),g){var k=this.batchs.indexOf(g);this.batchs.splice(k+1,0,j)}else this.batchs.push(j)}else a instanceof c.TilingSprite?this.initTilingSprite(a):a instanceof c.Strip&&this.initStrip(a),this.insertAfter(a,e)},c.WebGLRenderGroup.prototype.insertAfter=function(a,b){if(b instanceof c.Sprite){var d=b.batch;if(d)if(d.tail==b){var e=this.batchs.indexOf(d);this.batchs.splice(e+1,0,a)}else{var f=d.split(b.__next),e=this.batchs.indexOf(d);this.batchs.splice(e+1,0,a,f)}else this.batchs.push(a)}else{var e=this.batchs.indexOf(b);this.batchs.splice(e+1,0,a)}},c.WebGLRenderGroup.prototype.removeObject=function(a){var b;if(a instanceof c.Sprite){var d=a.batch;if(!d)return;d.remove(a),0==d.size&&(b=d)}else b=a;if(b){var e=this.batchs.indexOf(b);if(-1==e)return;if(0===e||e==this.batchs.length-1)return this.batchs.splice(e,1),b instanceof c.WebGLBatch&&c.WebGLRenderer.returnBatch(b),void 0;if(this.batchs[e-1]instanceof c.WebGLBatch&&this.batchs[e+1]instanceof c.WebGLBatch&&this.batchs[e-1].texture==this.batchs[e+1].texture&&this.batchs[e-1].blendMode==this.batchs[e+1].blendMode)return this.batchs[e-1].merge(this.batchs[e+1]),b instanceof c.WebGLBatch&&c.WebGLRenderer.returnBatch(b),c.WebGLRenderer.returnBatch(this.batchs[e+1]),this.batchs.splice(e,2),void 0;this.batchs.splice(e,1),b instanceof c.WebGLBatch&&c.WebGLRenderer.returnBatch(b)}},c.WebGLRenderGroup.prototype.initTilingSprite=function(a){var b=this.gl;a.verticies=new Float32Array([0,0,a.width,0,a.width,a.height,0,a.height]),a.uvs=new Float32Array([0,0,1,0,1,1,0,1]),a.colors=new Float32Array([1,1,1,1]),a.indices=new Uint16Array([0,1,3,2]),a._vertexBuffer=b.createBuffer(),a._indexBuffer=b.createBuffer(),a._uvBuffer=b.createBuffer(),a._colorBuffer=b.createBuffer(),b.bindBuffer(b.ARRAY_BUFFER,a._vertexBuffer),b.bufferData(b.ARRAY_BUFFER,a.verticies,b.STATIC_DRAW),b.bindBuffer(b.ARRAY_BUFFER,a._uvBuffer),b.bufferData(b.ARRAY_BUFFER,a.uvs,b.DYNAMIC_DRAW),b.bindBuffer(b.ARRAY_BUFFER,a._colorBuffer),b.bufferData(b.ARRAY_BUFFER,a.colors,b.STATIC_DRAW),b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,a._indexBuffer),b.bufferData(b.ELEMENT_ARRAY_BUFFER,a.indices,b.STATIC_DRAW),a.texture.baseTexture._glTexture?(b.bindTexture(b.TEXTURE_2D,a.texture.baseTexture._glTexture),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,b.REPEAT),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,b.REPEAT),a.texture.baseTexture._powerOf2=!0):a.texture.baseTexture._powerOf2=!0},c.WebGLRenderGroup.prototype.renderStrip=function(a,b){var d=this.gl;c.activateStripShader();var e=c.stripShader;e.program;var f=c.mat3.clone(a.worldTransform);c.mat3.transpose(f),d.uniformMatrix3fv(e.translationMatrix,!1,f),d.uniform2f(e.projectionVector,b.x,b.y),d.uniform2f(e.offsetVector,-c.offset.x,-c.offset.y),d.uniform1f(e.alpha,a.worldAlpha),a.dirty?(a.dirty=!1,d.bindBuffer(d.ARRAY_BUFFER,a._vertexBuffer),d.bufferData(d.ARRAY_BUFFER,a.verticies,d.STATIC_DRAW),d.vertexAttribPointer(e.aVertexPosition,2,d.FLOAT,!1,0,0),d.bindBuffer(d.ARRAY_BUFFER,a._uvBuffer),d.bufferData(d.ARRAY_BUFFER,a.uvs,d.STATIC_DRAW),d.vertexAttribPointer(e.aTextureCoord,2,d.FLOAT,!1,0,0),d.activeTexture(d.TEXTURE0),d.bindTexture(d.TEXTURE_2D,a.texture.baseTexture._glTexture),d.bindBuffer(d.ARRAY_BUFFER,a._colorBuffer),d.bufferData(d.ARRAY_BUFFER,a.colors,d.STATIC_DRAW),d.vertexAttribPointer(e.colorAttribute,1,d.FLOAT,!1,0,0),d.bindBuffer(d.ELEMENT_ARRAY_BUFFER,a._indexBuffer),d.bufferData(d.ELEMENT_ARRAY_BUFFER,a.indices,d.STATIC_DRAW)):(d.bindBuffer(d.ARRAY_BUFFER,a._vertexBuffer),d.bufferSubData(d.ARRAY_BUFFER,0,a.verticies),d.vertexAttribPointer(e.aVertexPosition,2,d.FLOAT,!1,0,0),d.bindBuffer(d.ARRAY_BUFFER,a._uvBuffer),d.vertexAttribPointer(e.aTextureCoord,2,d.FLOAT,!1,0,0),d.activeTexture(d.TEXTURE0),d.bindTexture(d.TEXTURE_2D,a.texture.baseTexture._glTexture),d.bindBuffer(d.ARRAY_BUFFER,a._colorBuffer),d.vertexAttribPointer(e.colorAttribute,1,d.FLOAT,!1,0,0),d.bindBuffer(d.ELEMENT_ARRAY_BUFFER,a._indexBuffer)),d.drawElements(d.TRIANGLE_STRIP,a.indices.length,d.UNSIGNED_SHORT,0),c.deactivateStripShader() -},c.WebGLRenderGroup.prototype.renderTilingSprite=function(a,b){var d=this.gl;c.shaderProgram;var e=a.tilePosition,f=a.tileScale,g=e.x/a.texture.baseTexture.width,h=e.y/a.texture.baseTexture.height,i=a.width/a.texture.baseTexture.width/f.x,j=a.height/a.texture.baseTexture.height/f.y;a.uvs[0]=0-g,a.uvs[1]=0-h,a.uvs[2]=1*i-g,a.uvs[3]=0-h,a.uvs[4]=1*i-g,a.uvs[5]=1*j-h,a.uvs[6]=0-g,a.uvs[7]=1*j-h,d.bindBuffer(d.ARRAY_BUFFER,a._uvBuffer),d.bufferSubData(d.ARRAY_BUFFER,0,a.uvs),this.renderStrip(a,b)},c.WebGLRenderGroup.prototype.initStrip=function(a){var b=this.gl;this.shaderProgram,a._vertexBuffer=b.createBuffer(),a._indexBuffer=b.createBuffer(),a._uvBuffer=b.createBuffer(),a._colorBuffer=b.createBuffer(),b.bindBuffer(b.ARRAY_BUFFER,a._vertexBuffer),b.bufferData(b.ARRAY_BUFFER,a.verticies,b.DYNAMIC_DRAW),b.bindBuffer(b.ARRAY_BUFFER,a._uvBuffer),b.bufferData(b.ARRAY_BUFFER,a.uvs,b.STATIC_DRAW),b.bindBuffer(b.ARRAY_BUFFER,a._colorBuffer),b.bufferData(b.ARRAY_BUFFER,a.colors,b.STATIC_DRAW),b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,a._indexBuffer),b.bufferData(b.ELEMENT_ARRAY_BUFFER,a.indices,b.STATIC_DRAW)},c.initDefaultShaders=function(){c.primitiveShader=new c.PrimitiveShader,c.primitiveShader.init(),c.stripShader=new c.StripShader,c.stripShader.init(),c.defaultShader=new c.PixiShader,c.defaultShader.init();var a=c.gl,b=c.defaultShader.program;a.useProgram(b),a.enableVertexAttribArray(c.defaultShader.aVertexPosition),a.enableVertexAttribArray(c.defaultShader.colorAttribute),a.enableVertexAttribArray(c.defaultShader.aTextureCoord)},c.activatePrimitiveShader=function(){var a=c.gl;a.useProgram(c.primitiveShader.program),a.disableVertexAttribArray(c.defaultShader.aVertexPosition),a.disableVertexAttribArray(c.defaultShader.colorAttribute),a.disableVertexAttribArray(c.defaultShader.aTextureCoord),a.enableVertexAttribArray(c.primitiveShader.aVertexPosition),a.enableVertexAttribArray(c.primitiveShader.colorAttribute)},c.deactivatePrimitiveShader=function(){var a=c.gl;a.useProgram(c.defaultShader.program),a.disableVertexAttribArray(c.primitiveShader.aVertexPosition),a.disableVertexAttribArray(c.primitiveShader.colorAttribute),a.enableVertexAttribArray(c.defaultShader.aVertexPosition),a.enableVertexAttribArray(c.defaultShader.colorAttribute),a.enableVertexAttribArray(c.defaultShader.aTextureCoord)},c.activateStripShader=function(){var a=c.gl;a.useProgram(c.stripShader.program)},c.deactivateStripShader=function(){var a=c.gl;a.useProgram(c.defaultShader.program)},c.CompileVertexShader=function(a,b){return c._CompileShader(a,b,a.VERTEX_SHADER)},c.CompileFragmentShader=function(a,b){return c._CompileShader(a,b,a.FRAGMENT_SHADER)},c._CompileShader=function(a,b,c){var d=b.join("\n"),e=a.createShader(c);return a.shaderSource(e,d),a.compileShader(e),a.getShaderParameter(e,a.COMPILE_STATUS)?e:(console.log(a.getShaderInfoLog(e)),null)},c.compileProgram=function(a,b){var d=c.gl,e=c.CompileFragmentShader(d,b),f=c.CompileVertexShader(d,a),g=d.createProgram();return d.attachShader(g,f),d.attachShader(g,e),d.linkProgram(g),d.getProgramParameter(g,d.LINK_STATUS)||console.log("Could not initialise shaders"),g},c.BitmapText=function(a,b){c.DisplayObjectContainer.call(this),this.setText(a),this.setStyle(b),this.updateText(),this.dirty=!1},c.BitmapText.prototype=Object.create(c.DisplayObjectContainer.prototype),c.BitmapText.prototype.constructor=c.BitmapText,c.BitmapText.prototype.setText=function(a){this.text=a||" ",this.dirty=!0},c.BitmapText.prototype.setStyle=function(a){a=a||{},a.align=a.align||"left",this.style=a;var b=a.font.split(" ");this.fontName=b[b.length-1],this.fontSize=b.length>=2?parseInt(b[b.length-2],10):c.BitmapText.fonts[this.fontName].size,this.dirty=!0},c.BitmapText.prototype.updateText=function(){for(var a=c.BitmapText.fonts[this.fontName],b=new c.Point,d=null,e=[],f=0,g=[],h=0,i=this.fontSize/a.size,j=0;j=j;j++){var n=0;"right"==this.style.align?n=f-g[j]:"center"==this.style.align&&(n=(f-g[j])/2),m.push(n)}for(j=0;j0;)this.removeChild(this.getChildAt(0));this.updateText(),this.dirty=!1}c.DisplayObjectContainer.prototype.updateTransform.call(this)},c.BitmapText.fonts={},c.Text=function(a,b){this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),c.Sprite.call(this,c.Texture.fromCanvas(this.canvas)),this.setText(a),this.setStyle(b),this.updateText(),this.dirty=!1},c.Text.prototype=Object.create(c.Sprite.prototype),c.Text.prototype.constructor=c.Text,c.Text.prototype.setStyle=function(a){a=a||{},a.font=a.font||"bold 20pt Arial",a.fill=a.fill||"black",a.align=a.align||"left",a.stroke=a.stroke||"black",a.strokeThickness=a.strokeThickness||0,a.wordWrap=a.wordWrap||!1,a.wordWrapWidth=a.wordWrapWidth||100,this.style=a,this.dirty=!0},c.Text.prototype.setText=function(a){this.text=a.toString()||" ",this.dirty=!0},c.Text.prototype.updateText=function(){this.context.font=this.style.font;var a=this.text;this.style.wordWrap&&(a=this.wordWrap(this.text));for(var b=a.split(/(?:\r\n|\r|\n)/),d=[],e=0,f=0;fe?(g>0&&(b+="\n"),b+=f[g]+" ",e=this.style.wordWrapWidth-h):(e-=i,b+=f[g]+" ")}b+="\n"}return b},c.Text.prototype.destroy=function(a){a&&this.texture.destroy()},c.Text.heightCache={},c.BaseTextureCache={},c.texturesToUpdate=[],c.texturesToDestroy=[],c.BaseTexture=function(a){if(c.EventTarget.call(this),this.width=100,this.height=100,this.hasLoaded=!1,this.source=a,a){if(this.source instanceof Image||this.source instanceof HTMLImageElement)if(this.source.complete)this.hasLoaded=!0,this.width=this.source.width,this.height=this.source.height,c.texturesToUpdate.push(this);else{var b=this;this.source.onload=function(){b.hasLoaded=!0,b.width=b.source.width,b.height=b.source.height,c.texturesToUpdate.push(b),b.dispatchEvent({type:"loaded",content:b})}}else this.hasLoaded=!0,this.width=this.source.width,this.height=this.source.height,c.texturesToUpdate.push(this);this._powerOf2=!1}},c.BaseTexture.prototype.constructor=c.BaseTexture,c.BaseTexture.prototype.destroy=function(){this.source instanceof Image&&(this.source.src=null),this.source=null,c.texturesToDestroy.push(this)},c.BaseTexture.fromImage=function(a,b){var d=c.BaseTextureCache[a];if(!d){var e=new Image;b&&(e.crossOrigin=""),e.src=a,d=new c.BaseTexture(e),c.BaseTextureCache[a]=d}return d},c.TextureCache={},c.FrameCache={},c.Texture=function(a,b){if(c.EventTarget.call(this),b||(this.noFrame=!0,b=new c.Rectangle(0,0,1,1)),a instanceof c.Texture&&(a=a.baseTexture),this.baseTexture=a,this.frame=b,this.trim=new c.Point,this.scope=this,a.hasLoaded)this.noFrame&&(b=new c.Rectangle(0,0,a.width,a.height)),this.setFrame(b);else{var d=this;a.addEventListener("loaded",function(){d.onBaseTextureLoaded()})}},c.Texture.prototype.constructor=c.Texture,c.Texture.prototype.onBaseTextureLoaded=function(){var a=this.baseTexture;a.removeEventListener("loaded",this.onLoaded),this.noFrame&&(this.frame=new c.Rectangle(0,0,a.width,a.height)),this.noFrame=!1,this.width=this.frame.width,this.height=this.frame.height,this.scope.dispatchEvent({type:"update",content:this})},c.Texture.prototype.destroy=function(a){a&&this.baseTexture.destroy()},c.Texture.prototype.setFrame=function(a){if(this.frame=a,this.width=a.width,this.height=a.height,a.x+a.width>this.baseTexture.width||a.y+a.height>this.baseTexture.height)throw new Error("Texture Error: frame does not fit inside the base Texture dimensions "+this);this.updateFrame=!0,c.Texture.frameUpdates.push(this)},c.Texture.fromImage=function(a,b){var d=c.TextureCache[a];return d||(d=new c.Texture(c.BaseTexture.fromImage(a,b)),c.TextureCache[a]=d),d},c.Texture.fromFrame=function(a){var b=c.TextureCache[a];if(!b)throw new Error("The frameId '"+a+"' does not exist in the texture cache "+this);return b},c.Texture.fromCanvas=function(a){var b=new c.BaseTexture(a);return new c.Texture(b)},c.Texture.addTextureToCache=function(a,b){c.TextureCache[b]=a},c.Texture.removeTextureFromCache=function(a){var b=c.TextureCache[a];return c.TextureCache[a]=null,b},c.Texture.frameUpdates=[],c.RenderTexture=function(a,b){c.EventTarget.call(this),this.width=a||100,this.height=b||100,this.indetityMatrix=c.mat3.create(),this.frame=new c.Rectangle(0,0,this.width,this.height),c.gl?this.initWebGL():this.initCanvas()},c.RenderTexture.prototype=Object.create(c.Texture.prototype),c.RenderTexture.prototype.constructor=c.RenderTexture,c.RenderTexture.prototype.initWebGL=function(){var a=c.gl;this.glFramebuffer=a.createFramebuffer(),a.bindFramebuffer(a.FRAMEBUFFER,this.glFramebuffer),this.glFramebuffer.width=this.width,this.glFramebuffer.height=this.height,this.baseTexture=new c.BaseTexture,this.baseTexture.width=this.width,this.baseTexture.height=this.height,this.baseTexture._glTexture=a.createTexture(),a.bindTexture(a.TEXTURE_2D,this.baseTexture._glTexture),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,this.width,this.height,0,a.RGBA,a.UNSIGNED_BYTE,null),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE),this.baseTexture.isRender=!0,a.bindFramebuffer(a.FRAMEBUFFER,this.glFramebuffer),a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,this.baseTexture._glTexture,0),this.projection=new c.Point(this.width/2,-this.height/2),this.render=this.renderWebGL},c.RenderTexture.prototype.resize=function(a,b){if(this.width=a,this.height=b,c.gl){this.projection.x=this.width/2,this.projection.y=-this.height/2;var d=c.gl;d.bindTexture(d.TEXTURE_2D,this.baseTexture._glTexture),d.texImage2D(d.TEXTURE_2D,0,d.RGBA,this.width,this.height,0,d.RGBA,d.UNSIGNED_BYTE,null)}else this.frame.width=this.width,this.frame.height=this.height,this.renderer.resize(this.width,this.height)},c.RenderTexture.prototype.initCanvas=function(){this.renderer=new c.CanvasRenderer(this.width,this.height,null,0),this.baseTexture=new c.BaseTexture(this.renderer.view),this.frame=new c.Rectangle(0,0,this.width,this.height),this.render=this.renderCanvas},c.RenderTexture.prototype.renderWebGL=function(a,b,d){var e=c.gl;e.colorMask(!0,!0,!0,!0),e.viewport(0,0,this.width,this.height),e.bindFramebuffer(e.FRAMEBUFFER,this.glFramebuffer),d&&(e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT));var f=a.children,g=a.worldTransform;a.worldTransform=c.mat3.create(),a.worldTransform[4]=-1,a.worldTransform[5]=-2*this.projection.y,b&&(a.worldTransform[2]=b.x,a.worldTransform[5]-=b.y),c.visibleCount++,a.vcount=c.visibleCount;for(var h=0,i=f.length;i>h;h++)f[h].updateTransform();var j=a.__renderGroup;j?a==j.root?j.render(this.projection,this.glFramebuffer):j.renderSpecific(a,this.projection,this.glFramebuffer):(this.renderGroup||(this.renderGroup=new c.WebGLRenderGroup(e)),this.renderGroup.setRenderable(a),this.renderGroup.render(this.projection,this.glFramebuffer)),a.worldTransform=g},c.RenderTexture.prototype.renderCanvas=function(a,b,d){var e=a.children;a.worldTransform=c.mat3.create(),b&&(a.worldTransform[2]=b.x,a.worldTransform[5]=b.y);for(var f=0,g=e.length;g>f;f++)e[f].updateTransform();d&&this.renderer.context.clearRect(0,0,this.width,this.height),this.renderer.renderDisplayObject(a),this.renderer.context.setTransform(1,0,0,1,0,0)},c.EventTarget=function(){var a={};this.addEventListener=this.on=function(b,c){void 0===a[b]&&(a[b]=[]),-1===a[b].indexOf(c)&&a[b].push(c)},this.dispatchEvent=this.emit=function(b){if(a[b.type]&&a[b.type].length)for(var c=0,d=a[b.type].length;d>c;c++)a[b.type][c](b)},this.removeEventListener=this.off=function(b,c){var d=a[b].indexOf(c);-1!==d&&a[b].splice(d,1)}},c.PolyK={},c.PolyK.Triangulate=function(a){var b=!0,d=a.length>>1;if(3>d)return[];for(var e=[],f=[],g=0;d>g;g++)f.push(g);for(var g=0,h=d;h>3;){var i=f[(g+0)%h],j=f[(g+1)%h],k=f[(g+2)%h],l=a[2*i],m=a[2*i+1],n=a[2*j],o=a[2*j+1],p=a[2*k],q=a[2*k+1],r=!1;if(c.PolyK._convex(l,m,n,o,p,q,b)){r=!0;for(var s=0;h>s;s++){var t=f[s];if(t!=i&&t!=j&&t!=k&&c.PolyK._PointInTriangle(a[2*t],a[2*t+1],l,m,n,o,p,q)){r=!1;break}}}if(r)e.push(i,j,k),f.splice((g+1)%h,1),h--,g=0;else if(g++>3*h){if(!b)return console.log("PIXI Warning: shape too complex to fill"),[];var e=[];f=[];for(var g=0;d>g;g++)f.push(g);g=0,h=d,b=!1}}return e.push(f[0],f[1],f[2]),e},c.PolyK._PointInTriangle=function(a,b,c,d,e,f,g,h){var i=g-c,j=h-d,k=e-c,l=f-d,m=a-c,n=b-d,o=i*i+j*j,p=i*k+j*l,q=i*m+j*n,r=k*k+l*l,s=k*m+l*n,t=1/(o*r-p*p),u=(r*q-p*s)*t,v=(o*s-p*q)*t;return u>=0&&v>=0&&1>u+v},c.PolyK._convex=function(a,b,c,d,e,f,g){return(b-d)*(e-c)+(c-a)*(f-d)>=0==g},d.Camera=function(a,b,c,e,f,g){this.game=a,this.world=a.world,this.id=0,this.view=new d.Rectangle(c,e,f,g),this.screenView=new d.Rectangle(c,e,f,g),this.bounds=new d.Rectangle(c,e,f,g),this.deadzone=null,this.visible=!0,this.atLimit={x:!1,y:!1},this.target=null,this._edge=0,this.displayObject=null},d.Camera.FOLLOW_LOCKON=0,d.Camera.FOLLOW_PLATFORMER=1,d.Camera.FOLLOW_TOPDOWN=2,d.Camera.FOLLOW_TOPDOWN_TIGHT=3,d.Camera.prototype={follow:function(a,b){"undefined"==typeof b&&(b=d.Camera.FOLLOW_LOCKON),this.target=a;var c;switch(b){case d.Camera.FOLLOW_PLATFORMER:var e=this.width/8,f=this.height/3;this.deadzone=new d.Rectangle((this.width-e)/2,(this.height-f)/2-.25*f,e,f);break;case d.Camera.FOLLOW_TOPDOWN:c=Math.max(this.width,this.height)/4,this.deadzone=new d.Rectangle((this.width-c)/2,(this.height-c)/2,c,c);break;case d.Camera.FOLLOW_TOPDOWN_TIGHT:c=Math.max(this.width,this.height)/8,this.deadzone=new d.Rectangle((this.width-c)/2,(this.height-c)/2,c,c);break;case d.Camera.FOLLOW_LOCKON:this.deadzone=null;break;default:this.deadzone=null}},focusOn:function(a){this.setPosition(Math.round(a.x-this.view.halfWidth),Math.round(a.y-this.view.halfHeight))},focusOnXY:function(a,b){this.setPosition(Math.round(a-this.view.halfWidth),Math.round(b-this.view.halfHeight))},update:function(){this.target&&this.updateTarget(),this.bounds&&this.checkBounds(),this.displayObject.position.x=-this.view.x,this.displayObject.position.y=-this.view.y},updateTarget:function(){this.deadzone?(this._edge=this.target.x-this.deadzone.x,this.view.x>this._edge&&(this.view.x=this._edge),this._edge=this.target.x+this.target.width-this.deadzone.x-this.deadzone.width,this.view.xthis._edge&&(this.view.y=this._edge),this._edge=this.target.y+this.target.height-this.deadzone.y-this.deadzone.height,this.view.ythis.bounds.right-this.width&&(this.atLimit.x=!0,this.view.x=this.bounds.right-this.width+1),this.view.ythis.bounds.bottom-this.height&&(this.atLimit.y=!0,this.view.y=this.bounds.bottom-this.height+1),this.view.floor()},setPosition:function(a,b){this.view.x=a,this.view.y=b,this.bounds&&this.checkBounds()},setSize:function(a,b){this.view.width=a,this.view.height=b}},Object.defineProperty(d.Camera.prototype,"x",{get:function(){return this.view.x},set:function(a){this.view.x=a,this.bounds&&this.checkBounds()}}),Object.defineProperty(d.Camera.prototype,"y",{get:function(){return this.view.y},set:function(a){this.view.y=a,this.bounds&&this.checkBounds()}}),Object.defineProperty(d.Camera.prototype,"width",{get:function(){return this.view.width},set:function(a){this.view.width=a}}),Object.defineProperty(d.Camera.prototype,"height",{get:function(){return this.view.height},set:function(a){this.view.height=a}}),d.State=function(){this.game=null,this.add=null,this.camera=null,this.cache=null,this.input=null,this.load=null,this.math=null,this.sound=null,this.stage=null,this.time=null,this.tweens=null,this.world=null,this.particles=null,this.physics=null},d.State.prototype={preload:function(){},loadUpdate:function(){},loadRender:function(){},create:function(){},update:function(){},render:function(){},paused:function(){},destroy:function(){}},d.StateManager=function(a,b){this.game=a,this.states={},this._pendingState=null,null!==b&&(this._pendingState=b),this._created=!1,this.current="",this.onInitCallback=null,this.onPreloadCallback=null,this.onCreateCallback=null,this.onUpdateCallback=null,this.onRenderCallback=null,this.onPreRenderCallback=null,this.onLoadUpdateCallback=null,this.onLoadRenderCallback=null,this.onPausedCallback=null,this.onShutDownCallback=null},d.StateManager.prototype={boot:function(){this.game.onPause.add(this.pause,this),this.game.onResume.add(this.resume,this),null!==this._pendingState&&("string"==typeof this._pendingState?this.start(this._pendingState,!1,!1):this.add("default",this._pendingState,!0))},add:function(a,b,c){"undefined"==typeof c&&(c=!1);var e;return b instanceof d.State?e=b:"object"==typeof b?(e=b,e.game=this.game):"function"==typeof b&&(e=new b(this.game)),this.states[a]=e,c&&(this.game.isBooted?this.start(a):this._pendingState=a),e},remove:function(a){this.current==a&&(this.callbackContext=null,this.onInitCallback=null,this.onShutDownCallback=null,this.onPreloadCallback=null,this.onLoadRenderCallback=null,this.onLoadUpdateCallback=null,this.onCreateCallback=null,this.onUpdateCallback=null,this.onRenderCallback=null,this.onPausedCallback=null,this.onDestroyCallback=null),delete this.states[a]},start:function(a,b,c){return"undefined"==typeof b&&(b=!0),"undefined"==typeof c&&(c=!1),this.game.isBooted===!1?(this._pendingState=a,void 0):(this.checkState(a)!==!1&&(this.current&&this.onShutDownCallback.call(this.callbackContext,this.game),b&&(this.game.tweens.removeAll(),this.game.world.destroy(),c===!0&&this.game.cache.destroy()),this.setCurrentState(a),this.onPreloadCallback?(this.game.load.reset(),this.onPreloadCallback.call(this.callbackContext,this.game),0===this.game.load.totalQueuedFiles()?this.game.loadComplete():this.game.load.start()):this.game.loadComplete()),void 0)},dummy:function(){},checkState:function(a){if(this.states[a]){var b=!1;return this.states[a].preload&&(b=!0),b===!1&&this.states[a].loadRender&&(b=!0),b===!1&&this.states[a].loadUpdate&&(b=!0),b===!1&&this.states[a].create&&(b=!0),b===!1&&this.states[a].update&&(b=!0),b===!1&&this.states[a].preRender&&(b=!0),b===!1&&this.states[a].render&&(b=!0),b===!1&&this.states[a].paused&&(b=!0),b===!1?(console.warn("Invalid Phaser State object given. Must contain at least a one of the required functions."),!1):!0}return console.warn("Phaser.StateManager - No state found with the key: "+a),!1},link:function(a){this.states[a].game=this.game,this.states[a].add=this.game.add,this.states[a].camera=this.game.camera,this.states[a].cache=this.game.cache,this.states[a].input=this.game.input,this.states[a].load=this.game.load,this.states[a].math=this.game.math,this.states[a].sound=this.game.sound,this.states[a].stage=this.game.stage,this.states[a].time=this.game.time,this.states[a].tweens=this.game.tweens,this.states[a].world=this.game.world,this.states[a].particles=this.game.particles,this.states[a].physics=this.game.physics,this.states[a].rnd=this.game.rnd},setCurrentState:function(a){this.callbackContext=this.states[a],this.link(a),this.onInitCallback=this.states[a].init||this.dummy,this.onPreloadCallback=this.states[a].preload||null,this.onLoadRenderCallback=this.states[a].loadRender||null,this.onLoadUpdateCallback=this.states[a].loadUpdate||null,this.onCreateCallback=this.states[a].create||null,this.onUpdateCallback=this.states[a].update||null,this.onPreRenderCallback=this.states[a].preRender||null,this.onRenderCallback=this.states[a].render||null,this.onPausedCallback=this.states[a].paused||null,this.onShutDownCallback=this.states[a].shutdown||this.dummy,this.current=a,this._created=!1,this.onInitCallback.call(this.callbackContext,this.game)},loadComplete:function(){this._created===!1&&this.onCreateCallback?(this._created=!0,this.onCreateCallback.call(this.callbackContext,this.game)):this._created=!0},pause:function(){this._created&&this.onPausedCallback&&this.onPausedCallback.call(this.callbackContext,this.game,!0)},resume:function(){this._created&&this.onre&&this.onPausedCallback.call(this.callbackContext,this.game,!1)},update:function(){this._created&&this.onUpdateCallback?this.onUpdateCallback.call(this.callbackContext,this.game):this.onLoadUpdateCallback&&this.onLoadUpdateCallback.call(this.callbackContext,this.game)},preRender:function(){this.onPreRenderCallback&&this.onPreRenderCallback.call(this.callbackContext,this.game)},render:function(){this._created&&this.onRenderCallback?(this.game.renderType===d.CANVAS&&(this.game.context.save(),this.game.context.setTransform(1,0,0,1,0,0)),this.onRenderCallback.call(this.callbackContext,this.game),this.game.renderType===d.CANVAS&&this.game.context.restore()):this.onLoadRenderCallback&&this.onLoadRenderCallback.call(this.callbackContext,this.game)},destroy:function(){this.callbackContext=null,this.onInitCallback=null,this.onShutDownCallback=null,this.onPreloadCallback=null,this.onLoadRenderCallback=null,this.onLoadUpdateCallback=null,this.onCreateCallback=null,this.onUpdateCallback=null,this.onRenderCallback=null,this.onPausedCallback=null,this.onDestroyCallback=null,this.game=null,this.states={},this._pendingState=null}},d.LinkedList=function(){this.next=null,this.prev=null,this.first=null,this.last=null,this.total=0},d.LinkedList.prototype={add:function(a){return 0===this.total&&null==this.first&&null==this.last?(this.first=a,this.last=a,this.next=a,a.prev=this,this.total++,a):(this.last.next=a,a.prev=this.last,this.last=a,this.total++,a)},remove:function(a){a==this.first?this.first=this.first.next:a==this.last&&(this.last=this.last.prev),a.prev&&(a.prev.next=a.next),a.next&&(a.next.prev=a.prev),a.next=a.prev=null,null==this.first&&(this.last=null),this.total--},callAll:function(a){if(this.first&&this.last){var b=this.first;do b&&b[a]&&b[a].call(b),b=b.next;while(b!=this.last.next)}}},d.Signal=function(){this._bindings=[],this._prevParams=null;var a=this;this.dispatch=function(){d.Signal.prototype.dispatch.apply(a,arguments)}},d.Signal.prototype={memorize:!1,_shouldPropagate:!0,active:!0,validateListener:function(a,b){if("function"!=typeof a)throw new Error("listener is a required param of {fn}() and should be a Function.".replace("{fn}",b))},_registerListener:function(a,b,c,e){var f,g=this._indexOfListener(a,c);if(-1!==g){if(f=this._bindings[g],f.isOnce()!==b)throw new Error("You cannot add"+(b?"":"Once")+"() then add"+(b?"Once":"")+"() the same listener without removing the relationship first.")}else f=new d.SignalBinding(this,a,b,c,e),this._addBinding(f);return this.memorize&&this._prevParams&&f.execute(this._prevParams),f},_addBinding:function(a){var b=this._bindings.length;do--b;while(this._bindings[b]&&a._priority<=this._bindings[b]._priority);this._bindings.splice(b+1,0,a)},_indexOfListener:function(a,b){for(var c,d=this._bindings.length;d--;)if(c=this._bindings[d],c._listener===a&&c.context===b)return d;return-1},has:function(a,b){return-1!==this._indexOfListener(a,b)},add:function(a,b,c){return this.validateListener(a,"add"),this._registerListener(a,!1,b,c)},addOnce:function(a,b,c){return this.validateListener(a,"addOnce"),this._registerListener(a,!0,b,c)},remove:function(a,b){this.validateListener(a,"remove");var c=this._indexOfListener(a,b);return-1!==c&&(this._bindings[c]._destroy(),this._bindings.splice(c,1)),a},removeAll:function(){for(var a=this._bindings.length;a--;)this._bindings[a]._destroy();this._bindings.length=0},getNumListeners:function(){return this._bindings.length},halt:function(){this._shouldPropagate=!1},dispatch:function(){if(this.active){var a,b=Array.prototype.slice.call(arguments),c=this._bindings.length;if(this.memorize&&(this._prevParams=b),c){a=this._bindings.slice(),this._shouldPropagate=!0;do c--;while(a[c]&&this._shouldPropagate&&a[c].execute(b)!==!1)}}},forget:function(){this._prevParams=null},dispose:function(){this.removeAll(),delete this._bindings,delete this._prevParams},toString:function(){return"[Phaser.Signal active:"+this.active+" numListeners:"+this.getNumListeners()+"]"}},d.SignalBinding=function(a,b,c,d,e){this._listener=b,this._isOnce=c,this.context=d,this._signal=a,this._priority=e||0},d.SignalBinding.prototype={active:!0,params:null,execute:function(a){var b,c;return this.active&&this._listener&&(c=this.params?this.params.concat(a):a,b=this._listener.apply(this.context,c),this._isOnce&&this.detach()),b},detach:function(){return this.isBound()?this._signal.remove(this._listener,this.context):null},isBound:function(){return!!this._signal&&!!this._listener},isOnce:function(){return this._isOnce},getListener:function(){return this._listener},getSignal:function(){return this._signal},_destroy:function(){delete this._signal,delete this._listener,delete this.context},toString:function(){return"[Phaser.SignalBinding isOnce:"+this._isOnce+", isBound:"+this.isBound()+", active:"+this.active+"]"}},d.Filter=function(a,b,c){this.game=a,this.type=d.WEBGL_FILTER,this.passes=[this],this.dirty=!0,this.padding=0,this.uniforms={time:{type:"1f",value:0},resolution:{type:"2f",value:{x:256,y:256}},mouse:{type:"2f",value:{x:0,y:0}}},this.fragmentSrc=c||[]},d.Filter.prototype={init:function(){},setResolution:function(a,b){this.uniforms.resolution.value.x=a,this.uniforms.resolution.value.y=b},update:function(a){"undefined"!=typeof a&&(a.x>0&&(this.uniforms.mouse.x=a.x.toFixed(2)),a.y>0&&(this.uniforms.mouse.y=a.y.toFixed(2))),this.uniforms.time.value=this.game.time.totalElapsedSeconds()},destroy:function(){this.game=null}},Object.defineProperty(d.Filter.prototype,"width",{get:function(){return this.uniforms.resolution.value.x},set:function(a){this.uniforms.resolution.value.x=a}}),Object.defineProperty(d.Filter.prototype,"height",{get:function(){return this.uniforms.resolution.value.y},set:function(a){this.uniforms.resolution.value.y=a}}),d.Plugin=function(a,b){"undefined"==typeof b&&(b=null),this.game=a,this.parent=b,this.active=!1,this.visible=!1,this.hasPreUpdate=!1,this.hasUpdate=!1,this.hasPostUpdate=!1,this.hasRender=!1,this.hasPostRender=!1},d.Plugin.prototype={preUpdate:function(){},update:function(){},render:function(){},postRender:function(){},destroy:function(){this.game=null,this.parent=null,this.active=!1,this.visible=!1}},d.PluginManager=function(a,b){this.game=a,this._parent=b,this.plugins=[],this._pluginsLength=0},d.PluginManager.prototype={add:function(a){var b=!1;return"function"==typeof a?a=new a(this.game,this._parent):(a.game=this.game,a.parent=this._parent),"function"==typeof a.preUpdate&&(a.hasPreUpdate=!0,b=!0),"function"==typeof a.update&&(a.hasUpdate=!0,b=!0),"function"==typeof a.postUpdate&&(a.hasPostUpdate=!0,b=!0),"function"==typeof a.render&&(a.hasRender=!0,b=!0),"function"==typeof a.postRender&&(a.hasPostRender=!0,b=!0),b?((a.hasPreUpdate||a.hasUpdate||a.hasPostUpdate)&&(a.active=!0),(a.hasRender||a.hasPostRender)&&(a.visible=!0),this._pluginsLength=this.plugins.push(a),"function"==typeof a.init&&a.init(),a):null},remove:function(a){if(0!==this._pluginsLength)for(this._p=0;this._pthis._nextOffsetCheck&&(d.Canvas.getOffset(this.canvas,this.offset),this._nextOffsetCheck=this.game.time.now+this.checkOffsetInterval)},visibilityChange:function(a){this.disableVisibilityChange||(this.game.paused="pagehide"==a.type||"blur"==a.type||document.hidden===!0||document.webkitHidden===!0?!0:!1)}},Object.defineProperty(d.Stage.prototype,"backgroundColor",{get:function(){return this._backgroundColor},set:function(a){this._backgroundColor=a,this.game.transparent===!1&&(this.game.renderType==d.CANVAS?this.game.canvas.style.backgroundColor=a:("string"==typeof a&&(a=d.Color.hexToRGB(a)),this._stage.setBackgroundColor(a)))}}),d.Group=function(a,b,e,f){("undefined"==typeof b||null===typeof b)&&(b=a.world),"undefined"==typeof f&&(f=!1),this.game=a,this.name=e||"group",f?this._container=this.game.stage._stage:(this._container=new c.DisplayObjectContainer,this._container.name=this.name,b?b instanceof d.Group?(b._container.addChild(this._container),b._container.updateTransform()):(b.addChild(this._container),b.updateTransform()):(this.game.stage._stage.addChild(this._container),this.game.stage._stage.updateTransform())),this.type=d.GROUP,this.exists=!0,this.scale=new d.Point(1,1),this.cursor=null},d.Group.RETURN_NONE=0,d.Group.RETURN_TOTAL=1,d.Group.RETURN_CHILD=2,d.Group.SORT_ASCENDING=-1,d.Group.SORT_DESCENDING=1,d.Group.prototype={add:function(a){return a.group!==this&&(a.group=this,a.events&&a.events.onAddedToGroup.dispatch(a,this),this._container.addChild(a),a.updateTransform(),null===this.cursor&&(this.cursor=a)),a},addAt:function(a,b){return a.group!==this&&(a.group=this,a.events&&a.events.onAddedToGroup.dispatch(a,this),this._container.addChildAt(a,b),a.updateTransform(),null===this.cursor&&(this.cursor=a)),a},getAt:function(a){return this._container.getChildAt(a)},create:function(a,b,c,e,f){"undefined"==typeof f&&(f=!0);var g=new d.Sprite(this.game,a,b,c,e);return g.group=this,g.exists=f,g.visible=f,g.alive=f,g.events&&g.events.onAddedToGroup.dispatch(g,this),this._container.addChild(g),g.updateTransform(),null===this.cursor&&(this.cursor=g),g},createMultiple:function(a,b,c,e){"undefined"==typeof e&&(e=!1);for(var f=0;a>f;f++){var g=new d.Sprite(this.game,0,0,b,c);g.group=this,g.exists=e,g.visible=e,g.alive=e,g.events&&g.events.onAddedToGroup.dispatch(g,this),this._container.addChild(g),g.updateTransform(),null===this.cursor&&(this.cursor=g)}},next:function(){this.cursor&&(this.cursor=this.cursor==this._container.last?this._container._iNext:this.cursor._iNext)},previous:function(){this.cursor&&(this.cursor=this.cursor==this._container._iNext?this._container.last:this.cursor._iPrev)},childTest:function(a,b){var c=a+" next: ";c+=b._iNext?b._iNext.name:"-null-",c=c+" "+a+" prev: ",c+=b._iPrev?b._iPrev.name:"-null-",console.log(c)},swapIndex:function(a,b){var c=this.getAt(a),d=this.getAt(b);console.log("swapIndex ",a," with ",b),this.swap(c,d)},swap:function(a,b){if(a===b||!a.parent||!b.parent||a.group!==this||b.group!==this)return!1;var c=a._iPrev,d=a._iNext,e=b._iPrev,f=b._iNext,g=this._container.last._iNext,h=this.game.stage._stage;do h!==a&&h!==b&&(h.first===a?h.first=b:h.first===b&&(h.first=a),h.last===a?h.last=b:h.last===b&&(h.last=a)),h=h._iNext;while(h!=g);return a._iNext==b?(a._iNext=f,a._iPrev=b,b._iNext=a,b._iPrev=c,c&&(c._iNext=b),f&&(f._iPrev=a),a.__renderGroup&&a.__renderGroup.updateTexture(a),b.__renderGroup&&b.__renderGroup.updateTexture(b),!0):b._iNext==a?(a._iNext=b,a._iPrev=e,b._iNext=d,b._iPrev=a,e&&(e._iNext=a),d&&(d._iPrev=b),a.__renderGroup&&a.__renderGroup.updateTexture(a),b.__renderGroup&&b.__renderGroup.updateTexture(b),!0):(a._iNext=f,a._iPrev=e,b._iNext=d,b._iPrev=c,c&&(c._iNext=b),d&&(d._iPrev=b),e&&(e._iNext=a),f&&(f._iPrev=a),a.__renderGroup&&a.__renderGroup.updateTexture(a),b.__renderGroup&&b.__renderGroup.updateTexture(b),!0)},bringToTop:function(a){return a.group===this&&(this.remove(a),this.add(a)),a},getIndex:function(a){return this._container.children.indexOf(a)},replace:function(a,b){if(this._container.first._iNext){var c=this.getIndex(a);-1!=c&&(void 0!==b.parent&&(b.events.onRemovedFromGroup.dispatch(b,this),b.parent.removeChild(b)),this._container.removeChild(a),this._container.addChildAt(b,c),b.events.onAddedToGroup.dispatch(b,this),b.updateTransform(),this.cursor==a&&(this.cursor=this._container._iNext))}},setProperty:function(a,b,c,d){d=d||0;var e=b.length;1==e?0===d?a[b[0]]=c:1==d?a[b[0]]+=c:2==d?a[b[0]]-=c:3==d?a[b[0]]*=c:4==d&&(a[b[0]]/=c):2==e?0===d?a[b[0]][b[1]]=c:1==d?a[b[0]][b[1]]+=c:2==d?a[b[0]][b[1]]-=c:3==d?a[b[0]][b[1]]*=c:4==d&&(a[b[0]][b[1]]/=c):3==e?0===d?a[b[0]][b[1]][b[2]]=c:1==d?a[b[0]][b[1]][b[2]]+=c:2==d?a[b[0]][b[1]][b[2]]-=c:3==d?a[b[0]][b[1]][b[2]]*=c:4==d&&(a[b[0]][b[1]][b[2]]/=c):4==e&&(0===d?a[b[0]][b[1]][b[2]][b[3]]=c:1==d?a[b[0]][b[1]][b[2]][b[3]]+=c:2==d?a[b[0]][b[1]][b[2]][b[3]]-=c:3==d?a[b[0]][b[1]][b[2]][b[3]]*=c:4==d&&(a[b[0]][b[1]][b[2]][b[3]]/=c))},setAll:function(a,b,c,d,e){if(a=a.split("."),"undefined"==typeof c&&(c=!1),"undefined"==typeof d&&(d=!1),e=e||0,this._container.children.length>0&&this._container.first._iNext){var f=this._container.first._iNext;do(c===!1||c&&f.alive)&&(d===!1||d&&f.visible)&&this.setProperty(f,a,b,e),f=f._iNext;while(f!=this._container.last._iNext)}},addAll:function(a,b,c,d){this.setAll(a,b,c,d,1)},subAll:function(a,b,c,d){this.setAll(a,b,c,d,2)},multiplyAll:function(a,b,c,d){this.setAll(a,b,c,d,3)},divideAll:function(a,b,c,d){this.setAll(a,b,c,d,4)},callAllExists:function(a,b){var c=Array.prototype.splice.call(arguments,2);if(this._container.children.length>0&&this._container.first._iNext){var d=this._container.first._iNext;do d.exists==b&&d[a]&&d[a].apply(d,c),d=d._iNext;while(d!=this._container.last._iNext)}},callbackFromArray:function(a,b,c){if(1==c){if(a[b[0]])return a[b[0]]}else if(2==c){if(a[b[0]][b[1]])return a[b[0]][b[1]]}else if(3==c){if(a[b[0]][b[1]][b[2]])return a[b[0]][b[1]][b[2]]}else if(4==c){if(a[b[0]][b[1]][b[2]][b[3]])return a[b[0]][b[1]][b[2]][b[3]]}else if(a[b])return a[b];return!1},callAll:function(a,b){if("undefined"!=typeof a){a=a.split(".");var c=a.length;if("undefined"==typeof b)b=null;else if("string"==typeof b){b=b.split(".");var d=b.length}var e=Array.prototype.splice.call(arguments,2),f=null,g=null;if(this._container.children.length>0&&this._container.first._iNext){var h=this._container.first._iNext;do f=this.callbackFromArray(h,a,c),b&&f?(g=this.callbackFromArray(h,b,d),f&&f.apply(g,e)):f&&f.apply(h,e),h=h._iNext;while(h!=this._container.last._iNext)}}},forEach:function(a,b,c){"undefined"==typeof c&&(c=!1);var d=Array.prototype.splice.call(arguments,3);if(d.unshift(null),this._container.children.length>0&&this._container.first._iNext){var e=this._container.first._iNext;do(c===!1||c&&e.exists)&&(d[0]=e,a.apply(b,d)),e=e._iNext;while(e!=this._container.last._iNext)}},forEachExists:function(a,b){var c=Array.prototype.splice.call(arguments,2);c.unshift(null),this.iterate("exists",!0,d.Group.RETURN_TOTAL,a,b,c)},forEachAlive:function(a,b){var c=Array.prototype.splice.call(arguments,2);c.unshift(null),this.iterate("alive",!0,d.Group.RETURN_TOTAL,a,b,c)},forEachDead:function(a,b){var c=Array.prototype.splice.call(arguments,2);c.unshift(null),this.iterate("alive",!1,d.Group.RETURN_TOTAL,a,b,c)},sort:function(a,b){"undefined"==typeof a&&(a="y"),"undefined"==typeof b&&(b=d.Group.SORT_ASCENDING);var c,e;do{c=!1;for(var f=0,g=this._container.children.length-1;g>f;f++)b==d.Group.SORT_ASCENDING?this._container.children[f][a]>this._container.children[f+1][a]&&(this.swap(this.getAt(f),this.getAt(f+1)),e=this._container.children[f],this._container.children[f]=this._container.children[f+1],this._container.children[f+1]=e,c=!0):this._container.children[f][a]0&&this._container.first._iNext){var i=this._container.first._iNext;do{if(i[a]===b&&(h++,e&&(g[0]=i,e.apply(f,g)),c==d.Group.RETURN_CHILD))return i;i=i._iNext}while(i!=this._container.last._iNext)}return c==d.Group.RETURN_TOTAL?h:c==d.Group.RETURN_CHILD?null:void 0},getFirstExists:function(a){return"boolean"!=typeof a&&(a=!0),this.iterate("exists",a,d.Group.RETURN_CHILD)},getFirstAlive:function(){return this.iterate("alive",!0,d.Group.RETURN_CHILD)},getFirstDead:function(){return this.iterate("alive",!1,d.Group.RETURN_CHILD)},countLiving:function(){return this.iterate("alive",!0,d.Group.RETURN_TOTAL)},countDead:function(){return this.iterate("alive",!1,d.Group.RETURN_TOTAL)},getRandom:function(a,b){return 0===this._container.children.length?null:(a=a||0,b=b||this._container.children.length,this.game.math.getRandom(this._container.children,a,b))},remove:function(a){return a.group!==this?!1:(a.events&&a.events.onRemovedFromGroup.dispatch(a,this),a.parent===this._container&&this._container.removeChild(a),this.cursor==a&&(this.cursor=this._container._iNext?this._container._iNext:null),a.group=null,!0)},removeAll:function(){if(0!==this._container.children.length){do this._container.children[0].events&&this._container.children[0].events.onRemovedFromGroup.dispatch(this._container.children[0],this),this._container.removeChild(this._container.children[0]);while(this._container.children.length>0);this.cursor=null}},removeBetween:function(a,b){if(0!==this._container.children.length){if(a>b||0>a||b>this._container.children.length)return!1;for(var c=a;b>c;c++){var d=this._container.children[c];d.events.onRemovedFromGroup.dispatch(d,this),this._container.removeChild(d),this.cursor==d&&(this.cursor=this._container._iNext?this._container._iNext:null)}}},destroy:function(){this.removeAll(),this._container.parent.removeChild(this._container),this._container=null,this.game=null,this.exists=!1,this.cursor=null},validate:function(){var a=this.game.stage._stage.last._iNext,b=this.game.stage._stage,c=null,d=null,e=0;do{if(e>0){if(b!==c)return console.log("check next fail"),!1;if(b._iPrev!==d)return console.log("check previous fail"),!1}c=b._iNext,d=b,b=b._iNext,e++}while(b!=a);return!0},dump:function(a){"undefined"==typeof a&&(a=!1);var b=20,c="\n"+d.Utils.pad("Node",b)+"|"+d.Utils.pad("Next",b)+"|"+d.Utils.pad("Previous",b)+"|"+d.Utils.pad("First",b)+"|"+d.Utils.pad("Last",b);console.log(c);var c=d.Utils.pad("----------",b)+"|"+d.Utils.pad("----------",b)+"|"+d.Utils.pad("----------",b)+"|"+d.Utils.pad("----------",b)+"|"+d.Utils.pad("----------",b);if(console.log(c),a)var e=this.game.stage._stage.last._iNext,f=this.game.stage._stage;else var e=this._container.last._iNext,f=this._container;do{var g=f.name||"*";if(this.cursor==f)var g="> "+g;var h="-",i="-",j="-",k="-";f._iNext&&(h=f._iNext.name),f._iPrev&&(i=f._iPrev.name),f.first&&(j=f.first.name),f.last&&(k=f.last.name),"undefined"==typeof h&&(h="-"),"undefined"==typeof i&&(i="-"),"undefined"==typeof j&&(j="-"),"undefined"==typeof k&&(k="-");var c=d.Utils.pad(g,b)+"|"+d.Utils.pad(h,b)+"|"+d.Utils.pad(i,b)+"|"+d.Utils.pad(j,b)+"|"+d.Utils.pad(k,b);console.log(c),f=f._iNext}while(f!=e)}},Object.defineProperty(d.Group.prototype,"total",{get:function(){return this.iterate("exists",!0,d.Group.RETURN_TOTAL)}}),Object.defineProperty(d.Group.prototype,"length",{get:function(){return this.iterate("exists",!0,d.Group.RETURN_TOTAL)}}),Object.defineProperty(d.Group.prototype,"x",{get:function(){return this._container.position.x},set:function(a){this._container.position.x=a}}),Object.defineProperty(d.Group.prototype,"y",{get:function(){return this._container.position.y},set:function(a){this._container.position.y=a}}),Object.defineProperty(d.Group.prototype,"angle",{get:function(){return d.Math.radToDeg(this._container.rotation)},set:function(a){this._container.rotation=d.Math.degToRad(a)}}),Object.defineProperty(d.Group.prototype,"rotation",{get:function(){return this._container.rotation},set:function(a){this._container.rotation=a}}),Object.defineProperty(d.Group.prototype,"visible",{get:function(){return this._container.visible},set:function(a){this._container.visible=a}}),Object.defineProperty(d.Group.prototype,"alpha",{get:function(){return this._container.alpha},set:function(a){this._container.alpha=a}}),d.World=function(a){d.Group.call(this,a,null,"__world",!1),this.scale=new d.Point(1,1),this.bounds=new d.Rectangle(0,0,a.width,a.height),this.camera=null,this.currentRenderOrderID=0},d.World.prototype=Object.create(d.Group.prototype),d.World.prototype.constructor=d.World,d.World.prototype.boot=function(){this.camera=new d.Camera(this.game,0,0,0,this.game.width,this.game.height),this.camera.displayObject=this._container,this.game.camera=this.camera},d.World.prototype.update=function(){if(this.currentRenderOrderID=0,this.game.stage._stage.first._iNext){var a,b=this.game.stage._stage.first._iNext;do a=!1,b.preUpdate&&(a=b.preUpdate()===!1),b.update&&(a=b.update()===!1||a),b=a?b.last._iNext:b._iNext;while(b!=this.game.stage._stage.last._iNext)}},d.World.prototype.postUpdate=function(){if(this.game.stage._stage.first._iNext){var a=this.game.stage._stage.first._iNext;do a.postUpdate&&a.postUpdate(),a=a._iNext;while(a!=this.game.stage._stage.last._iNext)}this.camera.update()},d.World.prototype.setBounds=function(a,b,c,d){this.bounds.setTo(a,b,c,d),this.camera.bounds&&this.camera.bounds.setTo(a,b,c,d)},d.World.prototype.destroy=function(){this.camera.x=0,this.camera.y=0,this.game.input.reset(!0),this.removeAll()},Object.defineProperty(d.World.prototype,"width",{get:function(){return this.bounds.width},set:function(a){this.bounds.width=a}}),Object.defineProperty(d.World.prototype,"height",{get:function(){return this.bounds.height},set:function(a){this.bounds.height=a}}),Object.defineProperty(d.World.prototype,"centerX",{get:function(){return this.bounds.halfWidth}}),Object.defineProperty(d.World.prototype,"centerY",{get:function(){return this.bounds.halfHeight}}),Object.defineProperty(d.World.prototype,"randomX",{get:function(){return this.bounds.x<0?this.game.rnd.integerInRange(this.bounds.x,this.bounds.width-Math.abs(this.bounds.x)):this.game.rnd.integerInRange(this.bounds.x,this.bounds.width)}}),Object.defineProperty(d.World.prototype,"randomY",{get:function(){return this.bounds.y<0?this.game.rnd.integerInRange(this.bounds.y,this.bounds.height-Math.abs(this.bounds.y)):this.game.rnd.integerInRange(this.bounds.y,this.bounds.height)}}),Object.defineProperty(d.World.prototype,"visible",{get:function(){return this._container.visible},set:function(a){this._container.visible=a}}),d.Game=function(a,b,c,e,f,g,h){a=a||800,b=b||600,c=c||d.AUTO,e=e||"",f=f||null,"undefined"==typeof g&&(g=!1),"undefined"==typeof h&&(h=!0),this.id=d.GAMES.push(this)-1,this.parent=e,this.width=a,this.height=b,this.transparent=g,this.antialias=h,this.renderer=null,this.state=new d.StateManager(this,f),this._paused=!1,this.renderType=c,this._loadComplete=!1,this.isBooted=!1,this.isRunning=!1,this.raf=null,this.add=null,this.cache=null,this.input=null,this.load=null,this.math=null,this.net=null,this.sound=null,this.stage=null,this.time=null,this.tweens=null,this.world=null,this.physics=null,this.rnd=null,this.device=null,this.camera=null,this.canvas=null,this.context=null,this.debug=null,this.particles=null;var i=this;return this._onBoot=function(){return i.boot()},"complete"===document.readyState||"interactive"===document.readyState?window.setTimeout(this._onBoot,0):(document.addEventListener("DOMContentLoaded",this._onBoot,!1),window.addEventListener("load",this._onBoot,!1)),this},d.Game.prototype={boot:function(){this.isBooted||(document.body?(document.removeEventListener("DOMContentLoaded",this._onBoot),window.removeEventListener("load",this._onBoot),this.onPause=new d.Signal,this.onResume=new d.Signal,this.isBooted=!0,this.device=new d.Device,this.math=d.Math,this.rnd=new d.RandomDataGenerator([(Date.now()*Math.random()).toString()]),this.stage=new d.Stage(this,this.width,this.height),this.setUpRenderer(),this.world=new d.World(this),this.add=new d.GameObjectFactory(this),this.cache=new d.Cache(this),this.load=new d.Loader(this),this.time=new d.Time(this),this.tweens=new d.TweenManager(this),this.input=new d.Input(this),this.sound=new d.SoundManager(this),this.physics=new d.Physics.Arcade(this),this.particles=new d.Particles(this),this.plugins=new d.PluginManager(this,this),this.net=new d.Net(this),this.debug=new d.Utils.Debug(this),this.stage.boot(),this.world.boot(),this.input.boot(),this.sound.boot(),this.state.boot(),this.load.onLoadComplete.add(this.loadComplete,this),this.showDebugHeader(),this.isRunning=!0,this._loadComplete=!1,this.raf=new d.RequestAnimationFrame(this),this.raf.start()):window.setTimeout(this._onBoot,20))},showDebugHeader:function(){var a=d.DEV_VERSION,b="Canvas",c="HTML Audio";if(this.renderType==d.WEBGL?b="WebGL":this.renderType==d.HEADLESS&&(b="Headless"),this.device.webAudio&&(c="WebAudio"),this.device.chrome){var e=["%c %c %c Phaser v"+a+" - Renderer: "+b+" - Audio: "+c+" %c %c ","background: #00bff3","background: #0072bc","color: #ffffff; background: #003471","background: #0072bc","background: #00bff3"];console.log.apply(console,e)}else console.log("Phaser v"+a+" - Renderer: "+b+" - Audio: "+c)},setUpRenderer:function(){if(this.renderType===d.HEADLESS||this.renderType===d.CANVAS||this.renderType===d.AUTO&&this.device.webGL===!1){if(!this.device.canvas)throw new Error("Phaser.Game - cannot create Canvas or WebGL context, aborting.");this.renderType===d.AUTO&&(this.renderType=d.CANVAS),this.renderer=new c.CanvasRenderer(this.width,this.height,this.stage.canvas,this.transparent),d.Canvas.setSmoothingEnabled(this.renderer.context,this.antialias),this.canvas=this.renderer.view,this.context=this.renderer.context}else this.renderType=d.WEBGL,this.renderer=new c.WebGLRenderer(this.width,this.height,this.stage.canvas,this.transparent,this.antialias),this.canvas=this.renderer.view,this.context=null;d.Canvas.addToDOM(this.renderer.view,this.parent,!0),d.Canvas.setTouchAction(this.renderer.view)},loadComplete:function(){this._loadComplete=!0,this.state.loadComplete()},update:function(a){this.time.update(a),this._paused?(this.renderer.render(this.stage._stage),this.plugins.render(),this.state.render()):(this.plugins.preUpdate(),this.physics.preUpdate(),this.stage.update(),this.input.update(),this.tweens.update(),this.sound.update(),this.world.update(),this.particles.update(),this.state.update(),this.plugins.update(),this.world.postUpdate(),this.plugins.postUpdate(),this.renderType!==d.HEADLESS&&(this.renderer.render(this.stage._stage),this.plugins.render(),this.state.render(),this.plugins.postRender()))},destroy:function(){this.raf.stop(),this.input.destroy(),this.state.destroy(),this.state=null,this.cache=null,this.input=null,this.load=null,this.sound=null,this.stage=null,this.time=null,this.world=null,this.isBooted=!1}},Object.defineProperty(d.Game.prototype,"paused",{get:function(){return this._paused},set:function(a){a===!0?this._paused===!1&&(this._paused=!0,this.onPause.dispatch(this)):this._paused&&(this._paused=!1,this.onResume.dispatch(this))}}),d.Input=function(a){this.game=a,this.hitCanvas=null,this.hitContext=null},d.Input.MOUSE_OVERRIDES_TOUCH=0,d.Input.TOUCH_OVERRIDES_MOUSE=1,d.Input.MOUSE_TOUCH_COMBINE=2,d.Input.prototype={pollRate:0,_pollCounter:0,_oldPosition:null,_x:0,_y:0,disabled:!1,multiInputOverride:d.Input.MOUSE_TOUCH_COMBINE,position:null,speed:null,circle:null,scale:null,maxPointers:10,currentPointers:0,tapRate:200,doubleTapRate:300,holdRate:2e3,justPressedRate:200,justReleasedRate:200,recordPointerHistory:!1,recordRate:100,recordLimit:100,pointer1:null,pointer2:null,pointer3:null,pointer4:null,pointer5:null,pointer6:null,pointer7:null,pointer8:null,pointer9:null,pointer10:null,activePointer:null,mousePointer:null,mouse:null,keyboard:null,touch:null,mspointer:null,onDown:null,onUp:null,onTap:null,onHold:null,interactiveItems:new d.LinkedList,boot:function(){this.mousePointer=new d.Pointer(this.game,0),this.pointer1=new d.Pointer(this.game,1),this.pointer2=new d.Pointer(this.game,2),this.mouse=new d.Mouse(this.game),this.keyboard=new d.Keyboard(this.game),this.touch=new d.Touch(this.game),this.mspointer=new d.MSPointer(this.game),this.onDown=new d.Signal,this.onUp=new d.Signal,this.onTap=new d.Signal,this.onHold=new d.Signal,this.scale=new d.Point(1,1),this.speed=new d.Point,this.position=new d.Point,this._oldPosition=new d.Point,this.circle=new d.Circle(0,0,44),this.activePointer=this.mousePointer,this.currentPointers=0,this.hitCanvas=document.createElement("canvas"),this.hitCanvas.width=1,this.hitCanvas.height=1,this.hitContext=this.hitCanvas.getContext("2d"),this.mouse.start(),this.keyboard.start(),this.touch.start(),this.mspointer.start(),this.mousePointer.active=!0},destroy:function(){this.mouse.stop(),this.keyboard.stop(),this.touch.stop(),this.mspointer.stop()},addPointer:function(){for(var a=0,b=10;b>0;b--)null===this["pointer"+b]&&(a=b);return 0===a?(console.warn("You can only have 10 Pointer objects"),null):(this["pointer"+a]=new d.Pointer(this.game,a),this["pointer"+a])},update:function(){return this.pollRate>0&&this._pollCounter=b;b++)this["pointer"+b]&&this["pointer"+b].reset();this.currentPointers=0,this.game.stage.canvas.style.cursor="default",a===!0&&(this.onDown.dispose(),this.onUp.dispose(),this.onTap.dispose(),this.onHold.dispose(),this.onDown=new d.Signal,this.onUp=new d.Signal,this.onTap=new d.Signal,this.onHold=new d.Signal,this.interactiveItems.callAll("reset")),this._pollCounter=0}},resetSpeed:function(a,b){this._oldPosition.setTo(a,b),this.speed.setTo(0,0)},startPointer:function(a){if(this.maxPointers<10&&this.totalActivePointers==this.maxPointers)return null;if(this.pointer1.active===!1)return this.pointer1.start(a);if(this.pointer2.active===!1)return this.pointer2.start(a);for(var b=3;10>=b;b++)if(this["pointer"+b]&&this["pointer"+b].active===!1)return this["pointer"+b].start(a);return null},updatePointer:function(a){if(this.pointer1.active&&this.pointer1.identifier==a.identifier)return this.pointer1.move(a);if(this.pointer2.active&&this.pointer2.identifier==a.identifier)return this.pointer2.move(a);for(var b=3;10>=b;b++)if(this["pointer"+b]&&this["pointer"+b].active&&this["pointer"+b].identifier==a.identifier)return this["pointer"+b].move(a);return null},stopPointer:function(a){if(this.pointer1.active&&this.pointer1.identifier==a.identifier)return this.pointer1.stop(a);if(this.pointer2.active&&this.pointer2.identifier==a.identifier)return this.pointer2.stop(a);for(var b=3;10>=b;b++)if(this["pointer"+b]&&this["pointer"+b].active&&this["pointer"+b].identifier==a.identifier)return this["pointer"+b].stop(a);return null},getPointer:function(a){if(a=a||!1,this.pointer1.active==a)return this.pointer1;if(this.pointer2.active==a)return this.pointer2;for(var b=3;10>=b;b++)if(this["pointer"+b]&&this["pointer"+b].active==a)return this["pointer"+b];return null},getPointerFromIdentifier:function(a){if(this.pointer1.identifier==a)return this.pointer1;if(this.pointer2.identifier==a)return this.pointer2;for(var b=3;10>=b;b++)if(this["pointer"+b]&&this["pointer"+b].identifier==a)return this["pointer"+b];return null}},Object.defineProperty(d.Input.prototype,"x",{get:function(){return this._x},set:function(a){this._x=Math.floor(a)}}),Object.defineProperty(d.Input.prototype,"y",{get:function(){return this._y},set:function(a){this._y=Math.floor(a)}}),Object.defineProperty(d.Input.prototype,"pollLocked",{get:function(){return this.pollRate>0&&this._pollCounter=a;a++)this["pointer"+a]&&this["pointer"+a].active&&this.currentPointers++;return this.currentPointers}}),Object.defineProperty(d.Input.prototype,"worldX",{get:function(){return this.game.camera.view.x+this.x}}),Object.defineProperty(d.Input.prototype,"worldY",{get:function(){return this.game.camera.view.y+this.y}}),d.Key=function(a,b){this.game=a,this.isDown=!1,this.isUp=!1,this.altKey=!1,this.ctrlKey=!1,this.shiftKey=!1,this.timeDown=0,this.duration=0,this.timeUp=0,this.repeats=0,this.keyCode=b,this.onDown=new d.Signal,this.onUp=new d.Signal},d.Key.prototype={processKeyDown:function(a){this.altKey=a.altKey,this.ctrlKey=a.ctrlKey,this.shiftKey=a.shiftKey,this.isDown?(this.duration=a.timeStamp-this.timeDown,this.repeats++):(this.isDown=!0,this.isUp=!1,this.timeDown=a.timeStamp,this.duration=0,this.repeats=0,this.onDown.dispatch(this))},processKeyUp:function(a){this.isDown=!1,this.isUp=!0,this.timeUp=a.timeStamp,this.onUp.dispatch(this)},justPressed:function(a){return"undefined"==typeof a&&(a=250),this.isDown&&this.duration=this.game.input.holdRate&&((this.game.input.multiInputOverride==d.Input.MOUSE_OVERRIDES_TOUCH||this.game.input.multiInputOverride==d.Input.MOUSE_TOUCH_COMBINE||this.game.input.multiInputOverride==d.Input.TOUCH_OVERRIDES_MOUSE&&0===this.game.input.currentPointers)&&this.game.input.onHold.dispatch(this),this._holdSent=!0),this.game.input.recordPointerHistory&&this.game.time.now>=this._nextDrop&&(this._nextDrop=this.game.time.now+this.game.input.recordRate,this._history.push({x:this.position.x,y:this.position.y}),this._history.length>this.game.input.recordLimit&&this._history.shift()))},move:function(a){if(!this.game.input.pollLocked){if("undefined"!=typeof a.button&&(this.button=a.button),this.clientX=a.clientX,this.clientY=a.clientY,this.pageX=a.pageX,this.pageY=a.pageY,this.screenX=a.screenX,this.screenY=a.screenY,this.x=(this.pageX-this.game.stage.offset.x)*this.game.input.scale.x,this.y=(this.pageY-this.game.stage.offset.y)*this.game.input.scale.y,this.position.setTo(this.x,this.y),this.circle.x=this.x,this.circle.y=this.y,(this.game.input.multiInputOverride==d.Input.MOUSE_OVERRIDES_TOUCH||this.game.input.multiInputOverride==d.Input.MOUSE_TOUCH_COMBINE||this.game.input.multiInputOverride==d.Input.TOUCH_OVERRIDES_MOUSE&&0===this.game.input.currentPointers)&&(this.game.input.activePointer=this,this.game.input.x=this.x,this.game.input.y=this.y,this.game.input.position.setTo(this.game.input.x,this.game.input.y),this.game.input.circle.x=this.game.input.x,this.game.input.circle.y=this.game.input.y),this.game.paused)return this;if(null!==this.targetObject&&this.targetObject.isDragged===!0)return this.targetObject.update(this)===!1&&(this.targetObject=null),this;if(this._highestRenderOrderID=-1,this._highestRenderObject=null,this._highestInputPriorityID=-1,this.game.input.interactiveItems.total>0){var b=this.game.input.interactiveItems.next;do(b.pixelPerfect||b.priorityID>this._highestInputPriorityID||b.priorityID==this._highestInputPriorityID&&b.sprite.renderOrderID>this._highestRenderOrderID)&&b.checkPointerOver(this)&&(this._highestRenderOrderID=b.sprite.renderOrderID,this._highestInputPriorityID=b.priorityID,this._highestRenderObject=b),b=b.next;while(null!=b)}return null==this._highestRenderObject?this.targetObject&&(this.targetObject._pointerOutHandler(this),this.targetObject=null):null==this.targetObject?(this.targetObject=this._highestRenderObject,this._highestRenderObject._pointerOverHandler(this)):this.targetObject==this._highestRenderObject?this._highestRenderObject.update(this)===!1&&(this.targetObject=null):(this.targetObject._pointerOutHandler(this),this.targetObject=this._highestRenderObject,this.targetObject._pointerOverHandler(this)),this}},leave:function(a){this.withinGame=!1,this.move(a)},stop:function(a){if(this._stateReset)return a.preventDefault(),void 0;if(this.timeUp=this.game.time.now,(this.game.input.multiInputOverride==d.Input.MOUSE_OVERRIDES_TOUCH||this.game.input.multiInputOverride==d.Input.MOUSE_TOUCH_COMBINE||this.game.input.multiInputOverride==d.Input.TOUCH_OVERRIDES_MOUSE&&0===this.game.input.currentPointers)&&(this.game.input.onUp.dispatch(this,a),this.duration>=0&&this.duration<=this.game.input.tapRate&&(this.timeUp-this.previousTapTime0&&(this.active=!1),this.withinGame=!1,this.isDown=!1,this.isUp=!0,this.isMouse===!1&&this.game.input.currentPointers--,this.game.input.interactiveItems.total>0){var b=this.game.input.interactiveItems.next;do b&&b._releasedHandler(this),b=b.next;while(null!=b)}return this.targetObject&&this.targetObject._releasedHandler(this),this.targetObject=null,this},justPressed:function(a){return a=a||this.game.input.justPressedRate,this.isDown===!0&&this.timeDown+a>this.game.time.now},justReleased:function(a){return a=a||this.game.input.justReleasedRate,this.isUp===!0&&this.timeUp+a>this.game.time.now},reset:function(){this.isMouse===!1&&(this.active=!1),this.identifier=null,this.isDown=!1,this.isUp=!0,this.totalTouches=0,this._holdSent=!1,this._history.length=0,this._stateReset=!0,this.targetObject&&this.targetObject._releasedHandler(this),this.targetObject=null}},Object.defineProperty(d.Pointer.prototype,"duration",{get:function(){return this.isUp?-1:this.game.time.now-this.timeDown}}),Object.defineProperty(d.Pointer.prototype,"worldX",{get:function(){return this.game.world.camera.x+this.x}}),Object.defineProperty(d.Pointer.prototype,"worldY",{get:function(){return this.game.world.camera.y+this.y}}),d.Touch=function(a){this.game=a,this.disabled=!1,this.callbackContext=this.game,this.touchStartCallback=null,this.touchMoveCallback=null,this.touchEndCallback=null,this.touchEnterCallback=null,this.touchLeaveCallback=null,this.touchCancelCallback=null,this.preventDefault=!0,this.event=null,this._onTouchStart=null,this._onTouchMove=null,this._onTouchEnd=null,this._onTouchEnter=null,this._onTouchLeave=null,this._onTouchCancel=null,this._onTouchMove=null},d.Touch.prototype={start:function(){var a=this;this.game.device.touch&&(this._onTouchStart=function(b){return a.onTouchStart(b)},this._onTouchMove=function(b){return a.onTouchMove(b)},this._onTouchEnd=function(b){return a.onTouchEnd(b)},this._onTouchEnter=function(b){return a.onTouchEnter(b)},this._onTouchLeave=function(b){return a.onTouchLeave(b)},this._onTouchCancel=function(b){return a.onTouchCancel(b)},this.game.renderer.view.addEventListener("touchstart",this._onTouchStart,!1),this.game.renderer.view.addEventListener("touchmove",this._onTouchMove,!1),this.game.renderer.view.addEventListener("touchend",this._onTouchEnd,!1),this.game.renderer.view.addEventListener("touchenter",this._onTouchEnter,!1),this.game.renderer.view.addEventListener("touchleave",this._onTouchLeave,!1),this.game.renderer.view.addEventListener("touchcancel",this._onTouchCancel,!1))},consumeDocumentTouches:function(){this._documentTouchMove=function(a){a.preventDefault()},document.addEventListener("touchmove",this._documentTouchMove,!1)},onTouchStart:function(a){if(this.event=a,this.touchStartCallback&&this.touchStartCallback.call(this.callbackContext,a),!this.game.input.disabled&&!this.disabled){this.preventDefault&&a.preventDefault();for(var b=0;bc;c++)this._pointerData[c]={id:c,x:0,y:0,isDown:!1,isUp:!1,isOver:!1,isOut:!1,timeOver:0,timeOut:0,timeDown:0,timeUp:0,downDuration:0,isDragged:!1};this.snapOffset=new d.Point,this.enabled=!0,this.sprite.events&&null==this.sprite.events.onInputOver&&(this.sprite.events.onInputOver=new d.Signal,this.sprite.events.onInputOut=new d.Signal,this.sprite.events.onInputDown=new d.Signal,this.sprite.events.onInputUp=new d.Signal,this.sprite.events.onDragStart=new d.Signal,this.sprite.events.onDragStop=new d.Signal)}return this.sprite},reset:function(){this.enabled=!1;for(var a=0;10>a;a++)this._pointerData[a]={id:a,x:0,y:0,isDown:!1,isUp:!1,isOver:!1,isOut:!1,timeOver:0,timeOut:0,timeDown:0,timeUp:0,downDuration:0,isDragged:!1}},stop:function(){this.enabled!==!1&&(this.enabled=!1,this.game.input.interactiveItems.remove(this))},destroy:function(){this.enabled&&(this.enabled=!1,this.game.input.interactiveItems.remove(this),this.stop(),this.sprite=null)},pointerX:function(a){return a=a||0,this._pointerData[a].x},pointerY:function(a){return a=a||0,this._pointerData[a].y},pointerDown:function(a){return a=a||0,this._pointerData[a].isDown},pointerUp:function(a){return a=a||0,this._pointerData[a].isUp},pointerTimeDown:function(a){return a=a||0,this._pointerData[a].timeDown},pointerTimeUp:function(a){return a=a||0,this._pointerData[a].timeUp},pointerOver:function(a){if(this.enabled){if("undefined"!=typeof a)return this._pointerData[a].isOver;for(var b=0;10>b;b++)if(this._pointerData[b].isOver)return!0}return!1},pointerOut:function(a){if(this.enabled){if("undefined"!=typeof a)return this._pointerData[a].isOut;for(var b=0;10>b;b++)if(this._pointerData[b].isOut)return!0}return!1},pointerTimeOver:function(a){return a=a||0,this._pointerData[a].timeOver},pointerTimeOut:function(a){return a=a||0,this._pointerData[a].timeOut},pointerDragged:function(a){return a=a||0,this._pointerData[a].isDragged},checkPointerOver:function(a){return this.enabled===!1||this.sprite.visible===!1||this.sprite.group&&this.sprite.group.visible===!1?!1:(this.sprite.getLocalUnmodifiedPosition(this._tempPoint,a.x,a.y),this._tempPoint.x>=0&&this._tempPoint.x<=this.sprite.currentFrame.width&&this._tempPoint.y>=0&&this._tempPoint.y<=this.sprite.currentFrame.height?this.pixelPerfect?this.checkPixel(this._tempPoint.x,this._tempPoint.y):!0:void 0)},checkPixel:function(a,b){if(this.sprite.texture.baseTexture.source){this.game.input.hitContext.clearRect(0,0,1,1),a+=this.sprite.texture.frame.x,b+=this.sprite.texture.frame.y,this.game.input.hitContext.drawImage(this.sprite.texture.baseTexture.source,a,b,1,1,0,0,1,1);var c=this.game.input.hitContext.getImageData(0,0,1,1);if(c.data[3]>=this.pixelPerfectAlpha)return!0}return!1},update:function(a){return this.enabled===!1||this.sprite.visible===!1||this.sprite.group&&this.sprite.group.visible===!1?(this._pointerOutHandler(a),!1):this.draggable&&this._draggedPointerID==a.id?this.updateDrag(a):this._pointerData[a.id].isOver===!0?this.checkPointerOver(a)?(this._pointerData[a.id].x=a.x-this.sprite.x,this._pointerData[a.id].y=a.y-this.sprite.y,!0):(this._pointerOutHandler(a),!1):void 0},_pointerOverHandler:function(a){this._pointerData[a.id].isOver===!1&&(this._pointerData[a.id].isOver=!0,this._pointerData[a.id].isOut=!1,this._pointerData[a.id].timeOver=this.game.time.now,this._pointerData[a.id].x=a.x-this.sprite.x,this._pointerData[a.id].y=a.y-this.sprite.y,this.useHandCursor&&this._pointerData[a.id].isDragged===!1&&(this.game.stage.canvas.style.cursor="pointer"),this.sprite.events.onInputOver.dispatch(this.sprite,a))},_pointerOutHandler:function(a){this._pointerData[a.id].isOver=!1,this._pointerData[a.id].isOut=!0,this._pointerData[a.id].timeOut=this.game.time.now,this.useHandCursor&&this._pointerData[a.id].isDragged===!1&&(this.game.stage.canvas.style.cursor="default"),this.sprite&&this.sprite.events&&this.sprite.events.onInputOut.dispatch(this.sprite,a)},_touchedHandler:function(a){return this._pointerData[a.id].isDown===!1&&this._pointerData[a.id].isOver===!0&&(this._pointerData[a.id].isDown=!0,this._pointerData[a.id].isUp=!1,this._pointerData[a.id].timeDown=this.game.time.now,this.sprite.events.onInputDown.dispatch(this.sprite,a),this.draggable&&this.isDragged===!1&&this.startDrag(a),this.bringToTop&&this.sprite.bringToTop()),this.consumePointerEvent},_releasedHandler:function(a){this._pointerData[a.id].isDown&&a.isUp&&(this._pointerData[a.id].isDown=!1,this._pointerData[a.id].isUp=!0,this._pointerData[a.id].timeUp=this.game.time.now,this._pointerData[a.id].downDuration=this._pointerData[a.id].timeUp-this._pointerData[a.id].timeDown,this.checkPointerOver(a)?this.sprite.events.onInputUp.dispatch(this.sprite,a):this.useHandCursor&&(this.game.stage.canvas.style.cursor="default"),this.draggable&&this.isDragged&&this._draggedPointerID==a.id&&this.stopDrag(a))},updateDrag:function(a){return a.isUp?(this.stopDrag(a),!1):(this.allowHorizontalDrag&&(this.sprite.x=a.x+this._dragPoint.x+this.dragOffset.x),this.allowVerticalDrag&&(this.sprite.y=a.y+this._dragPoint.y+this.dragOffset.y),this.boundsRect&&this.checkBoundsRect(),this.boundsSprite&&this.checkBoundsSprite(),this.snapOnDrag&&(this.sprite.x=Math.round(this.sprite.x/this.snapX)*this.snapX,this.sprite.y=Math.round(this.sprite.y/this.snapY)*this.snapY),!0)},justOver:function(a,b){return a=a||0,b=b||500,this._pointerData[a].isOver&&this.overDuration(a)a;a++)this._pointerData[a].isDragged=!1;this.draggable=!1,this.isDragged=!1,this._draggedPointerID=-1},startDrag:function(a){this.isDragged=!0,this._draggedPointerID=a.id,this._pointerData[a.id].isDragged=!0,this.dragFromCenter?(this.sprite.centerOn(a.x,a.y),this._dragPoint.setTo(this.sprite.x-a.x,this.sprite.y-a.y)):this._dragPoint.setTo(this.sprite.x-a.x,this.sprite.y-a.y),this.updateDrag(a),this.bringToTop&&this.sprite.bringToTop(),this.sprite.events.onDragStart.dispatch(this.sprite,a)},stopDrag:function(a){this.isDragged=!1,this._draggedPointerID=-1,this._pointerData[a.id].isDragged=!1,this.snapOnRelease&&(this.sprite.x=Math.round(this.sprite.x/this.snapX)*this.snapX,this.sprite.y=Math.round(this.sprite.y/this.snapY)*this.snapY),this.sprite.events.onDragStop.dispatch(this.sprite,a),this.sprite.events.onInputUp.dispatch(this.sprite,a),this.checkPointerOver(a)===!1&&this._pointerOutHandler(a)},setDragLock:function(a,b){"undefined"==typeof a&&(a=!0),"undefined"==typeof b&&(b=!0),this.allowHorizontalDrag=a,this.allowVerticalDrag=b},enableSnap:function(a,b,c,d){"undefined"==typeof c&&(c=!0),"undefined"==typeof d&&(d=!1),this.snapX=a,this.snapY=b,this.snapOnDrag=c,this.snapOnRelease=d},disableSnap:function(){this.snapOnDrag=!1,this.snapOnRelease=!1},checkBoundsRect:function(){this.sprite.xthis.boundsRect.right&&(this.sprite.x=this.boundsRect.right-this.sprite.width),this.sprite.ythis.boundsRect.bottom&&(this.sprite.y=this.boundsRect.bottom-this.sprite.height)},checkBoundsSprite:function(){this.sprite.xthis.boundsSprite.x+this.boundsSprite.width&&(this.sprite.x=this.boundsSprite.x+this.boundsSprite.width-this.sprite.width),this.sprite.ythis.boundsSprite.y+this.boundsSprite.height&&(this.sprite.y=this.boundsSprite.y+this.boundsSprite.height-this.sprite.height)}},d.Events=function(a){this.parent=a,this.onAddedToGroup=new d.Signal,this.onRemovedFromGroup=new d.Signal,this.onKilled=new d.Signal,this.onRevived=new d.Signal,this.onOutOfBounds=new d.Signal,this.onInputOver=null,this.onInputOut=null,this.onInputDown=null,this.onInputUp=null,this.onDragStart=null,this.onDragStop=null,this.onAnimationStart=null,this.onAnimationComplete=null,this.onAnimationLoop=null},d.Events.prototype={destroy:function(){this.parent=null,this.onAddedToGroup.dispose(),this.onRemovedFromGroup.dispose(),this.onKilled.dispose(),this.onRevived.dispose(),this.onOutOfBounds.dispose(),this.onInputOver&&(this.onInputOver.dispose(),this.onInputOut.dispose(),this.onInputDown.dispose(),this.onInputUp.dispose(),this.onDragStart.dispose(),this.onDragStop.dispose()),this.onAnimationStart&&(this.onAnimationStart.dispose(),this.onAnimationComplete.dispose(),this.onAnimationLoop.dispose())}},d.GameObjectFactory=function(a){this.game=a,this.world=this.game.world},d.GameObjectFactory.prototype={existing:function(a){return this.world.add(a)},sprite:function(a,b,c,d){return this.world.create(a,b,c,d)},child:function(a,b,c,d,e){return a.create(b,c,d,e)},tween:function(a){return this.game.tweens.create(a)},group:function(a,b){return new d.Group(this.game,a,b)},audio:function(a,b,c,d){return this.game.sound.add(a,b,c,d)},tileSprite:function(a,b,c,e,f,g){return this.world.add(new d.TileSprite(this.game,a,b,c,e,f,g))},text:function(a,b,c,e){return this.world.add(new d.Text(this.game,a,b,c,e))},button:function(a,b,c,e,f,g,h,i){return this.world.add(new d.Button(this.game,a,b,c,e,f,g,h,i))},graphics:function(a,b){return this.world.add(new d.Graphics(this.game,a,b))},emitter:function(a,b,c){return this.game.particles.add(new d.Particles.Arcade.Emitter(this.game,a,b,c))},bitmapText:function(a,b,c,e){return this.world.add(new d.BitmapText(this.game,a,b,c,e))},tilemap:function(a){return new d.Tilemap(this.game,a)},tileset:function(a){return this.game.cache.getTileset(a)},tilemapLayer:function(a,b,c,e,f,g,h){return this.world.add(new d.TilemapLayer(this.game,a,b,c,e,f,g,h))},renderTexture:function(a,b,c){var e=new d.RenderTexture(this.game,a,b,c);return this.game.cache.addRenderTexture(a,e),e},bitmapData:function(a,b){return new d.BitmapData(this.game,a,b)},filter:function(a){var b=Array.prototype.splice.call(arguments,1),a=new d.Filter[a](this.game);return a.init.apply(a,b),a}},d.BitmapData=function(a,b,e){"undefined"==typeof b&&(b=256),"undefined"==typeof e&&(e=256),this.game=a,this.name="",this.width=b,this.height=e,this.canvas=d.Canvas.create(b,e),this.context=this.canvas.getContext("2d"),this.imageData=this.context.getImageData(0,0,b,e),this.pixels=this.imageData.data.buffer?this.imageData.data.buffer:this.imageData.data,this.baseTexture=new c.BaseTexture(this.canvas),this.texture=new c.Texture(this.baseTexture),this.textureFrame=new d.Frame(0,0,0,b,e,"bitmapData",a.rnd.uuid()),this.type=d.BITMAPDATA,this._dirty=!1},d.BitmapData.prototype={add:function(a){a.loadTexture(this)},addTo:function(a){for(var b=0;b=0&&a<=this.width&&b>=0&&b<=this.height&&(this.pixels[b*this.width+a]=f<<24|e<<16|d<<8|c,this.context.putImageData(this.imageData,0,0),this._dirty=!0)},setPixel:function(a,b,c,d,e){this.setPixel32(a,b,c,d,e,255)},getPixel:function(a,b){return a>=0&&a<=this.width&&b>=0&&b<=this.height?this.data32[b*this.width+a]:void 0},getPixel32:function(a,b){return a>=0&&a<=this.width&&b>=0&&b<=this.height?this.data32[b*this.width+a]:void 0},getPixels:function(a){return this.context.getImageData(a.x,a.y,a.width,a.height)},arc:function(a,b,c,d,e,f){return"undefined"==typeof f&&(f=!1),this._dirty=!0,this.context.arc(a,b,c,d,e,f),this},arcTo:function(a,b,c,d,e){return this._dirty=!0,this.context.arcTo(a,b,c,d,e),this},beginFill:function(a){return this.fillStyle(a),this},beginLinearGradientFill:function(a,b,c,d,e,f){for(var g=this.createLinearGradient(c,d,e,f),h=0,i=a.length;i>h;h++)g.addColorStop(b[h],a[h]);return this.fillStyle(g),this},beginLinearGradientStroke:function(a,b,c,d,e,f){for(var g=this.createLinearGradient(c,d,e,f),h=0,i=a.length;i>h;h++)g.addColorStop(b[h],a[h]);return this.strokeStyle(g),this},beginRadialGradientStroke:function(a,b,c,d,e,f,g,h){for(var i=this.createRadialGradient(c,d,e,f,g,h),j=0,k=a.length;k>j;j++)i.addColorStop(b[j],a[j]);return this.strokeStyle(i),this},beginPath:function(){return this.context.beginPath(),this},beginStroke:function(a){return this.strokeStyle(a),this},bezierCurveTo:function(a,b,c,d,e,f){return this._dirty=!0,this.context.bezierCurveTo(a,b,c,d,e,f),this},circle:function(a,b,c){return this.arc(a,b,c,0,2*Math.PI),this},clearRect:function(a,b,c,d){return this._dirty=!0,this.context.clearRect(a,b,c,d),this},clip:function(){return this._dirty=!0,this.context.clip(),this},closePath:function(){return this._dirty=!0,this.context.closePath(),this},createLinearGradient:function(a,b,c,d){return this.context.createLinearGradient(a,b,c,d)},createRadialGradient:function(a,b,c,d,e,f){return this.context.createRadialGradient(a,b,c,d,e,f)},ellipse:function(a,b,c,d){var e=.5522848,f=c/2*e,g=d/2*e,h=a+c,i=b+d,j=a+c/2,k=b+d/2;return this.moveTo(a,k),this.bezierCurveTo(a,k-g,j-f,b,j,b),this.bezierCurveTo(j+f,b,h,k-g,h,k),this.bezierCurveTo(h,k+g,j+f,i,j,i),this.bezierCurveTo(j-f,i,a,k+g,a,k),this},fill:function(){return this._dirty=!0,this.context.fill(),this},fillRect:function(a,b,c,d){return this._dirty=!0,this.context.fillRect(a,b,c,d),this},fillStyle:function(a){return this.context.fillStyle=a,this},font:function(a){return this.context.font=a,this},globalAlpha:function(a){return this.context.globalAlpha=a,this},globalCompositeOperation:function(a){return this.context.globalCompositeOperation=a,this},lineCap:function(a){return this.context.lineCap=a,this},lineDashOffset:function(a){return this.context.lineDashOffset=a,this},lineJoin:function(a){return this.context.lineJoin=a,this},lineWidth:function(a){return this.context.lineWidth=a,this},miterLimit:function(a){return this.context.miterLimit=a,this},lineTo:function(a,b){return this._dirty=!0,this.context.lineTo(a,b),this},moveTo:function(a,b){return this.context.moveTo(a,b),this},quadraticCurveTo:function(a,b,c,d){return this._dirty=!0,this.context.quadraticCurveTo(a,b,c,d),this},rect:function(a,b,c,d){return this._dirty=!0,this.context.rect(a,b,c,d),this},restore:function(){return this._dirty=!0,this.context.restore(),this},rotate:function(a){return this._dirty=!0,this.context.rotate(a),this},setStrokeStyle:function(a,b,c,d,e){return"undefined"==typeof a&&(a=1),"undefined"==typeof b&&(b="butt"),"undefined"==typeof c&&(c="miter"),"undefined"==typeof d&&(d=10),e=!1,this.lineWidth(a),this.lineCap(b),this.lineJoin(c),this.miterLimit(d),this},save:function(){return this._dirty=!0,this.context.save(),this},scale:function(a,b){return this._dirty=!0,this.context.scale(a,b),this},scrollPathIntoView:function(){return this._dirty=!0,this.context.scrollPathIntoView(),this},stroke:function(){return this._dirty=!0,this.context.stroke(),this},strokeRect:function(a,b,c,d){return this._dirty=!0,this.context.strokeRect(a,b,c,d),this},strokeStyle:function(a){return this.context.strokeStyle=a,this},render:function(){this._dirty&&(this.game.renderType==d.WEBGL&&c.texturesToUpdate.push(this.baseTexture),this._dirty=!1)}},d.BitmapData.prototype.mt=d.BitmapData.prototype.moveTo,d.BitmapData.prototype.lt=d.BitmapData.prototype.lineTo,d.BitmapData.prototype.at=d.BitmapData.prototype.arcTo,d.BitmapData.prototype.bt=d.BitmapData.prototype.bezierCurveTo,d.BitmapData.prototype.qt=d.BitmapData.prototype.quadraticCurveTo,d.BitmapData.prototype.a=d.BitmapData.prototype.arc,d.BitmapData.prototype.r=d.BitmapData.prototype.rect,d.BitmapData.prototype.cp=d.BitmapData.prototype.closePath,d.BitmapData.prototype.c=d.BitmapData.prototype.clear,d.BitmapData.prototype.f=d.BitmapData.prototype.beginFill,d.BitmapData.prototype.lf=d.BitmapData.prototype.beginLinearGradientFill,d.BitmapData.prototype.rf=d.BitmapData.prototype.beginRadialGradientFill,d.BitmapData.prototype.ef=d.BitmapData.prototype.endFill,d.BitmapData.prototype.ss=d.BitmapData.prototype.setStrokeStyle,d.BitmapData.prototype.s=d.BitmapData.prototype.beginStroke,d.BitmapData.prototype.ls=d.BitmapData.prototype.beginLinearGradientStroke,d.BitmapData.prototype.rs=d.BitmapData.prototype.beginRadialGradientStroke,d.BitmapData.prototype.dr=d.BitmapData.prototype.rect,d.BitmapData.prototype.dc=d.BitmapData.prototype.circle,d.BitmapData.prototype.de=d.BitmapData.prototype.ellipse,d.Sprite=function(a,b,e,f,g){b=b||0,e=e||0,f=f||null,g=g||null,this.game=a,this.exists=!0,this.alive=!0,this.group=null,this.name="",this.type=d.SPRITE,this.renderOrderID=-1,this.lifespan=0,this.events=new d.Events(this),this.animations=new d.AnimationManager(this),this.input=new d.InputHandler(this),this.key=f,this.currentFrame=null,f instanceof d.RenderTexture?(c.Sprite.call(this,f),this.currentFrame=this.game.cache.getTextureFrame(f.name)):f instanceof d.BitmapData?(c.Sprite.call(this,f.texture,f.textureFrame),this.currentFrame=f.textureFrame):f instanceof c.Texture?(c.Sprite.call(this,f),this.currentFrame=g):(null===f||"undefined"==typeof f?(f="__default",this.key=f):"string"==typeof f&&this.game.cache.checkImageKey(f)===!1&&(f="__missing",this.key=f),c.Sprite.call(this,c.TextureCache[f]),this.game.cache.isSpriteSheet(f)?(this.animations.loadFrameData(this.game.cache.getFrameData(f)),null!==g&&("string"==typeof g?this.frameName=g:this.frame=g)):this.currentFrame=this.game.cache.getFrame(f)),this.textureRegion=new d.Rectangle(this.texture.frame.x,this.texture.frame.y,this.texture.frame.width,this.texture.frame.height),this.anchor=new d.Point,this.x=b,this.y=e,this.position.x=b,this.position.y=e,this.world=new d.Point(b,e),this.autoCull=!1,this.scale=new d.Point(1,1),this._cache={dirty:!1,a00:-1,a01:-1,a02:-1,a10:-1,a11:-1,a12:-1,id:-1,i01:-1,i10:-1,idi:-1,left:null,right:null,top:null,bottom:null,prevX:b,prevY:e,x:-1,y:-1,scaleX:1,scaleY:1,width:this.currentFrame.sourceSizeW,height:this.currentFrame.sourceSizeH,halfWidth:Math.floor(this.currentFrame.sourceSizeW/2),halfHeight:Math.floor(this.currentFrame.sourceSizeH/2),calcWidth:-1,calcHeight:-1,frameID:-1,frameWidth:this.currentFrame.width,frameHeight:this.currentFrame.height,cameraVisible:!0,cropX:0,cropY:0,cropWidth:this.currentFrame.sourceSizeW,cropHeight:this.currentFrame.sourceSizeH},this.offset=new d.Point,this.center=new d.Point(b+Math.floor(this._cache.width/2),e+Math.floor(this._cache.height/2)),this.topLeft=new d.Point(b,e),this.topRight=new d.Point(b+this._cache.width,e),this.bottomRight=new d.Point(b+this._cache.width,e+this._cache.height),this.bottomLeft=new d.Point(b,e+this._cache.height),this.bounds=new d.Rectangle(b,e,this._cache.width,this._cache.height),this.body=new d.Physics.Arcade.Body(this),this.health=1,this.inWorld=d.Rectangle.intersects(this.bounds,this.game.world.bounds),this.inWorldThreshold=0,this.outOfBoundsKill=!1,this._outOfBoundsFired=!1,this.fixedToCamera=!1,this.cameraOffset=new d.Point,this.crop=new d.Rectangle(0,0,this._cache.width,this._cache.height),this.cropEnabled=!1,this.updateCache(),this.updateBounds() -},d.Sprite.prototype=Object.create(c.Sprite.prototype),d.Sprite.prototype.constructor=d.Sprite,d.Sprite.prototype.preUpdate=function(){return!this.exists||this.group&&!this.group.exists?(this.renderOrderID=-1,!1):this.lifespan>0&&(this.lifespan-=this.game.time.elapsed,this.lifespan<=0)?(this.kill(),!1):(this._cache.dirty=!1,this.visible&&(this.renderOrderID=this.game.world.currentRenderOrderID++),this.updateCache(),this.updateAnimation(),this.updateCrop(),(this._cache.dirty||this.world.x!==this._cache.prevX||this.world.y!==this._cache.prevY)&&this.updateBounds(),this.body&&this.body.preUpdate(),!0)},d.Sprite.prototype.updateCache=function(){this._cache.prevX=this.world.x,this._cache.prevY=this.world.y,this.fixedToCamera&&(this.x=this.game.camera.view.x+this.cameraOffset.x,this.y=this.game.camera.view.y+this.cameraOffset.y),this.world.setTo(this.game.camera.x+this.worldTransform[2],this.game.camera.y+this.worldTransform[5]),(this.worldTransform[1]!=this._cache.i01||this.worldTransform[3]!=this._cache.i10||this.worldTransform[0]!=this._cache.a00||this.worldTransform[41]!=this._cache.a11)&&(this._cache.a00=this.worldTransform[0],this._cache.a01=this.worldTransform[1],this._cache.a10=this.worldTransform[3],this._cache.a11=this.worldTransform[4],this._cache.i01=this.worldTransform[1],this._cache.i10=this.worldTransform[3],this._cache.scaleX=Math.sqrt(this._cache.a00*this._cache.a00+this._cache.a01*this._cache.a01),this._cache.scaleY=Math.sqrt(this._cache.a10*this._cache.a10+this._cache.a11*this._cache.a11),this._cache.a01*=-1,this._cache.a10*=-1,this._cache.id=1/(this._cache.a00*this._cache.a11+this._cache.a01*-this._cache.a10),this._cache.idi=1/(this._cache.a00*this._cache.a11+this._cache.i01*-this._cache.i10),this._cache.dirty=!0),this._cache.a02=this.worldTransform[2],this._cache.a12=this.worldTransform[5]},d.Sprite.prototype.updateAnimation=function(){(this.animations.update()||this.currentFrame&&this.currentFrame.uuid!=this._cache.frameID)&&(this._cache.frameID=this.currentFrame.uuid,this._cache.frameWidth=this.texture.frame.width,this._cache.frameHeight=this.texture.frame.height,this._cache.width=this.currentFrame.width,this._cache.height=this.currentFrame.height,this._cache.halfWidth=Math.floor(this._cache.width/2),this._cache.halfHeight=Math.floor(this._cache.height/2),this._cache.dirty=!0)},d.Sprite.prototype.updateCrop=function(){!this.cropEnabled||this.crop.width==this._cache.cropWidth&&this.crop.height==this._cache.cropHeight&&this.crop.x==this._cache.cropX&&this.crop.y==this._cache.cropY||(this.crop.floorAll(),this._cache.cropX=this.crop.x,this._cache.cropY=this.crop.y,this._cache.cropWidth=this.crop.width,this._cache.cropHeight=this.crop.height,this.texture.frame=this.crop,this.texture.width=this.crop.width,this.texture.height=this.crop.height,this.texture.updateFrame=!0,c.Texture.frameUpdates.push(this.texture))},d.Sprite.prototype.updateBounds=function(){this.offset.setTo(this._cache.a02-this.anchor.x*this.width,this._cache.a12-this.anchor.y*this.height),this.getLocalPosition(this.center,this.offset.x+this.width/2,this.offset.y+this.height/2),this.getLocalPosition(this.topLeft,this.offset.x,this.offset.y),this.getLocalPosition(this.topRight,this.offset.x+this.width,this.offset.y),this.getLocalPosition(this.bottomLeft,this.offset.x,this.offset.y+this.height),this.getLocalPosition(this.bottomRight,this.offset.x+this.width,this.offset.y+this.height),this._cache.left=d.Math.min(this.topLeft.x,this.topRight.x,this.bottomLeft.x,this.bottomRight.x),this._cache.right=d.Math.max(this.topLeft.x,this.topRight.x,this.bottomLeft.x,this.bottomRight.x),this._cache.top=d.Math.min(this.topLeft.y,this.topRight.y,this.bottomLeft.y,this.bottomRight.y),this._cache.bottom=d.Math.max(this.topLeft.y,this.topRight.y,this.bottomLeft.y,this.bottomRight.y),this.bounds.setTo(this._cache.left,this._cache.top,this._cache.right-this._cache.left,this._cache.bottom-this._cache.top),this.updateFrame=!0,this.inWorld===!1?(this.inWorld=d.Rectangle.intersects(this.bounds,this.game.world.bounds,this.inWorldThreshold),this.inWorld&&(this._outOfBoundsFired=!1)):(this.inWorld=d.Rectangle.intersects(this.bounds,this.game.world.bounds,this.inWorldThreshold),this.inWorld===!1&&(this.events.onOutOfBounds.dispatch(this),this._outOfBoundsFired=!0,this.outOfBoundsKill&&this.kill())),this._cache.cameraVisible=d.Rectangle.intersects(this.game.world.camera.screenView,this.bounds,0),this.autoCull&&(this.renderable=this._cache.cameraVisible),this.body&&this.body.updateBounds(this.center.x,this.center.y,this._cache.scaleX,this._cache.scaleY)},d.Sprite.prototype.getLocalPosition=function(a,b,c){return a.x=(this._cache.a11*this._cache.id*b+-this._cache.a01*this._cache.id*c+(this._cache.a12*this._cache.a01-this._cache.a02*this._cache.a11)*this._cache.id)*this.scale.x+this._cache.a02,a.y=(this._cache.a00*this._cache.id*c+-this._cache.a10*this._cache.id*b+(-this._cache.a12*this._cache.a00+this._cache.a02*this._cache.a10)*this._cache.id)*this.scale.y+this._cache.a12,a},d.Sprite.prototype.getLocalUnmodifiedPosition=function(a,b,c){return a.x=this._cache.a11*this._cache.idi*b+-this._cache.i01*this._cache.idi*c+(this._cache.a12*this._cache.i01-this._cache.a02*this._cache.a11)*this._cache.idi+this.anchor.x*this._cache.width,a.y=this._cache.a00*this._cache.idi*c+-this._cache.i10*this._cache.idi*b+(-this._cache.a12*this._cache.a00+this._cache.a02*this._cache.i10)*this._cache.idi+this.anchor.y*this._cache.height,a},d.Sprite.prototype.resetCrop=function(){this.crop=new d.Rectangle(0,0,this._cache.width,this._cache.height),this.texture.setFrame(this.crop),this.cropEnabled=!1},d.Sprite.prototype.postUpdate=function(){this.key instanceof d.BitmapData&&this.key._dirty&&this.key.render(),this.exists&&(this.body&&this.body.postUpdate(),this.fixedToCamera?(this._cache.x=this.game.camera.view.x+this.cameraOffset.x,this._cache.y=this.game.camera.view.y+this.cameraOffset.y):(this._cache.x=this.x,this._cache.y=this.y),this.world.setTo(this.game.camera.x+this.worldTransform[2],this.game.camera.y+this.worldTransform[5]),this.position.x=this._cache.x,this.position.y=this._cache.y)},d.Sprite.prototype.loadTexture=function(a,b){this.key=a,a instanceof d.RenderTexture?this.currentFrame=this.game.cache.getTextureFrame(a.name):a instanceof d.BitmapData?(this.setTexture(a.texture),this.currentFrame=a.textureFrame):a instanceof c.Texture?this.currentFrame=b:(("undefined"==typeof a||this.game.cache.checkImageKey(a)===!1)&&(a="__default",this.key=a),this.game.cache.isSpriteSheet(a)?(this.animations.loadFrameData(this.game.cache.getFrameData(a)),"undefined"!=typeof b&&("string"==typeof b?this.frameName=b:this.frame=b)):(this.currentFrame=this.game.cache.getFrame(a),this.setTexture(c.TextureCache[a])))},d.Sprite.prototype.centerOn=function(a,b){return this.x=a+(this.x-this.center.x),this.y=b+(this.y-this.center.y),this},d.Sprite.prototype.revive=function(a){return"undefined"==typeof a&&(a=1),this.alive=!0,this.exists=!0,this.visible=!0,this.health=a,this.events&&this.events.onRevived.dispatch(this),this},d.Sprite.prototype.kill=function(){return this.alive=!1,this.exists=!1,this.visible=!1,this.events&&this.events.onKilled.dispatch(this),this},d.Sprite.prototype.destroy=function(){this.group&&this.group.remove(this),this.input&&this.input.destroy(),this.events&&this.events.destroy(),this.animations&&this.animations.destroy(),this.alive=!1,this.exists=!1,this.visible=!1,this.game=null},d.Sprite.prototype.damage=function(a){return this.alive&&(this.health-=a,this.health<0&&this.kill()),this},d.Sprite.prototype.reset=function(a,b,c){return"undefined"==typeof c&&(c=1),this.x=a,this.y=b,this.position.x=this.x,this.position.y=this.y,this.alive=!0,this.exists=!0,this.visible=!0,this.renderable=!0,this._outOfBoundsFired=!1,this.health=c,this.body&&this.body.reset(),this},d.Sprite.prototype.bringToTop=function(){return this.group?this.group.bringToTop(this):this.game.world.bringToTop(this),this},d.Sprite.prototype.play=function(a,b,c,d){return this.animations?this.animations.play(a,b,c,d):void 0},Object.defineProperty(d.Sprite.prototype,"angle",{get:function(){return d.Math.wrapAngle(d.Math.radToDeg(this.rotation))},set:function(a){this.rotation=d.Math.degToRad(d.Math.wrapAngle(a))}}),Object.defineProperty(d.Sprite.prototype,"frame",{get:function(){return this.animations.frame},set:function(a){this.animations.frame=a}}),Object.defineProperty(d.Sprite.prototype,"frameName",{get:function(){return this.animations.frameName},set:function(a){this.animations.frameName=a}}),Object.defineProperty(d.Sprite.prototype,"inCamera",{get:function(){return this._cache.cameraVisible}}),Object.defineProperty(d.Sprite.prototype,"width",{get:function(){return this.scale.x*this.currentFrame.width},set:function(a){this.scale.x=a/this.currentFrame.width,this._cache.scaleX=a/this.currentFrame.width,this._width=a}}),Object.defineProperty(d.Sprite.prototype,"height",{get:function(){return this.scale.y*this.currentFrame.height},set:function(a){this.scale.y=a/this.currentFrame.height,this._cache.scaleY=a/this.currentFrame.height,this._height=a}}),Object.defineProperty(d.Sprite.prototype,"inputEnabled",{get:function(){return this.input.enabled},set:function(a){console.log("inputEnabled",a,this.input),a?this.input.enabled===!1&&this.input.start():this.input.enabled&&this.input.stop()}}),d.TileSprite=function(a,b,e,f,g,h,i){b=b||0,e=e||0,f=f||256,g=g||256,h=h||null,i=i||null,d.Sprite.call(this,a,b,e,h,i),this.texture=c.TextureCache[h],c.TilingSprite.call(this,this.texture,f,g),this.type=d.TILESPRITE,this.tileScale=new d.Point(1,1),this.tilePosition=new d.Point(0,0)},d.TileSprite.prototype=d.Utils.extend(!0,c.TilingSprite.prototype,d.Sprite.prototype),d.TileSprite.prototype.constructor=d.TileSprite,d.Text=function(a,b,e,f,g){b=b||0,e=e||0,f=f||"",g=g||"",this.game=a,this.exists=!0,this.alive=!0,this.group=null,this.name="",this.type=d.TEXT,this._text=f,this._style=g,c.Text.call(this,f,g),this.position.x=this.x=b,this.position.y=this.y=e,this.anchor=new d.Point,this.scale=new d.Point(1,1),this._cache={dirty:!1,a00:1,a01:0,a02:b,a10:0,a11:1,a12:e,id:1,x:-1,y:-1,scaleX:1,scaleY:1},this._cache.x=this.x,this._cache.y=this.y,this.renderable=!0},d.Text.prototype=Object.create(c.Text.prototype),d.Text.prototype.constructor=d.Text,d.Text.prototype.update=function(){this.exists&&(this._cache.dirty=!1,this._cache.x=this.x,this._cache.y=this.y,(this.position.x!=this._cache.x||this.position.y!=this._cache.y)&&(this.position.x=this._cache.x,this.position.y=this._cache.y,this._cache.dirty=!0))},d.Text.prototype.destroy=function(){this.group&&this.group.remove(this),this.canvas.parentNode?this.canvas.parentNode.removeChild(this.canvas):(this.canvas=null,this.context=null),this.exists=!1,this.group=null},Object.defineProperty(d.Text.prototype,"angle",{get:function(){return d.Math.radToDeg(this.rotation)},set:function(a){this.rotation=d.Math.degToRad(a)}}),Object.defineProperty(d.Text.prototype,"x",{get:function(){return this.position.x},set:function(a){this.position.x=a}}),Object.defineProperty(d.Text.prototype,"y",{get:function(){return this.position.y},set:function(a){this.position.y=a}}),Object.defineProperty(d.Text.prototype,"content",{get:function(){return this._text},set:function(a){a!==this._text&&(this._text=a,this.setText(a))}}),Object.defineProperty(d.Text.prototype,"font",{get:function(){return this._style},set:function(a){a!==this._style&&(this._style=a,this.setStyle(a))}}),d.BitmapText=function(a,b,e,f,g){b=b||0,e=e||0,f=f||"",g=g||"",this.game=a,this.exists=!0,this.alive=!0,this.group=null,this.name="",this.type=d.BITMAPTEXT,c.BitmapText.call(this,f,g),this.position.x=b,this.position.y=e,this.anchor=new d.Point,this.scale=new d.Point(1,1),this._cache={dirty:!1,a00:1,a01:0,a02:b,a10:0,a11:1,a12:e,id:1,x:-1,y:-1,scaleX:1,scaleY:1},this._cache.x=this.x,this._cache.y=this.y,this.renderable=!0},d.BitmapText.prototype=Object.create(c.BitmapText.prototype),d.BitmapText.prototype.constructor=d.BitmapText,d.BitmapText.prototype.update=function(){this.exists&&(this._cache.dirty=!1,this._cache.x=this.x,this._cache.y=this.y,(this.position.x!=this._cache.x||this.position.y!=this._cache.y)&&(this.position.x=this._cache.x,this.position.y=this._cache.y,this._cache.dirty=!0),this.pivot.x=this.anchor.x*this.width,this.pivot.y=this.anchor.y*this.height)},d.BitmapText.prototype.destroy=function(){this.group&&this.group.remove(this),this.canvas&&this.canvas.parentNode?this.canvas.parentNode.removeChild(this.canvas):(this.canvas=null,this.context=null),this.exists=!1,this.group=null},Object.defineProperty(d.BitmapText.prototype,"angle",{get:function(){return d.Math.radToDeg(this.rotation)},set:function(a){this.rotation=d.Math.degToRad(a)}}),Object.defineProperty(d.BitmapText.prototype,"x",{get:function(){return this.position.x},set:function(a){this.position.x=a}}),Object.defineProperty(d.BitmapText.prototype,"y",{get:function(){return this.position.y},set:function(a){this.position.y=a}}),d.Button=function(a,b,c,e,f,g,h,i,j){b=b||0,c=c||0,e=e||null,f=f||null,g=g||this,d.Sprite.call(this,a,b,c,e,i),this.type=d.BUTTON,this._onOverFrameName=null,this._onOutFrameName=null,this._onDownFrameName=null,this._onUpFrameName=null,this._onOverFrameID=null,this._onOutFrameID=null,this._onDownFrameID=null,this._onUpFrameID=null,this.onOverSound=null,this.onOutSound=null,this.onDownSound=null,this.onUpSound=null,this.onOverSoundMarker="",this.onOutSoundMarker="",this.onDownSoundMarker="",this.onUpSoundMarker="",this.onInputOver=new d.Signal,this.onInputOut=new d.Signal,this.onInputDown=new d.Signal,this.onInputUp=new d.Signal,this.freezeFrames=!1,this.forceOut=!0,this.setFrames(h,i,j),null!==f&&this.onInputUp.add(f,g),this.input.start(0,!0),this.events.onInputOver.add(this.onInputOverHandler,this),this.events.onInputOut.add(this.onInputOutHandler,this),this.events.onInputDown.add(this.onInputDownHandler,this),this.events.onInputUp.add(this.onInputUpHandler,this)},d.Button.prototype=Object.create(d.Sprite.prototype),d.Button.prototype=d.Utils.extend(!0,d.Button.prototype,d.Sprite.prototype,c.Sprite.prototype),d.Button.prototype.constructor=d.Button,d.Button.prototype.setFrames=function(a,b,c){null!==a&&("string"==typeof a?(this._onOverFrameName=a,this.input.pointerOver()&&(this.frameName=a)):(this._onOverFrameID=a,this.input.pointerOver()&&(this.frame=a))),null!==b&&("string"==typeof b?(this._onOutFrameName=b,this._onUpFrameName=b,this.input.pointerOver()===!1&&(this.frameName=b)):(this._onOutFrameID=b,this._onUpFrameID=b,this.input.pointerOver()===!1&&(this.frame=b))),null!==c&&("string"==typeof c?(this._onDownFrameName=c,this.input.pointerDown()&&(this.frameName=c)):(this._onDownFrameID=c,this.input.pointerDown()&&(this.frame=c)))},d.Button.prototype.setSounds=function(a,b,c,d,e,f,g,h){this.setOverSound(a,b),this.setOutSound(e,f),this.setUpSound(g,h),this.setDownSound(c,d)},d.Button.prototype.setOverSound=function(a,b){this.onOverSound=null,this.onOverSoundMarker="",a instanceof d.Sound&&(this.onOverSound=a),"string"==typeof b&&(this.onOverSoundMarker=b)},d.Button.prototype.setOutSound=function(a,b){this.onOutSound=null,this.onOutSoundMarker="",a instanceof d.Sound&&(this.onOutSound=a),"string"==typeof b&&(this.onOutSoundMarker=b)},d.Button.prototype.setUpSound=function(a,b){this.onUpSound=null,this.onUpSoundMarker="",a instanceof d.Sound&&(this.onUpSound=a),"string"==typeof b&&(this.onUpSoundMarker=b)},d.Button.prototype.setDownSound=function(a,b){this.onDownSound=null,this.onDownSoundMarker="",a instanceof d.Sound&&(this.onDownSound=a),"string"==typeof b&&(this.onDownSoundMarker=b)},d.Button.prototype.onInputOverHandler=function(a){this.freezeFrames===!1&&(null!=this._onOverFrameName?this.frameName=this._onOverFrameName:null!=this._onOverFrameID&&(this.frame=this._onOverFrameID)),this.onOverSound&&this.onOverSound.play(this.onOverSoundMarker),this.onInputOver&&this.onInputOver.dispatch(this,a)},d.Button.prototype.onInputOutHandler=function(a){this.freezeFrames===!1&&(null!=this._onOutFrameName?this.frameName=this._onOutFrameName:null!=this._onOutFrameID&&(this.frame=this._onOutFrameID)),this.onOutSound&&this.onOutSound.play(this.onOutSoundMarker),this.onInputOut&&this.onInputOut.dispatch(this,a)},d.Button.prototype.onInputDownHandler=function(a){this.freezeFrames===!1&&(null!=this._onDownFrameName?this.frameName=this._onDownFrameName:null!=this._onDownFrameID&&(this.frame=this._onDownFrameID)),this.onDownSound&&this.onDownSound.play(this.onDownSoundMarker),this.onInputDown&&this.onInputDown.dispatch(this,a)},d.Button.prototype.onInputUpHandler=function(a){this.freezeFrames===!1&&(null!=this._onUpFrameName?this.frameName=this._onUpFrameName:null!=this._onUpFrameID&&(this.frame=this._onUpFrameID)),this.onUpSound&&this.onUpSound.play(this.onUpSoundMarker),this.forceOut&&this.freezeFrames===!1&&(null!=this._onOutFrameName?this.frameName=this._onOutFrameName:null!=this._onOutFrameID&&(this.frame=this._onOutFrameID)),this.onInputUp&&this.onInputUp.dispatch(this,a)},d.Graphics=function(a,b,e){this.game=a,c.Graphics.call(this),this.type=d.GRAPHICS,this.position.x=b,this.position.y=e},d.Graphics.prototype=Object.create(c.Graphics.prototype),d.Graphics.prototype.constructor=d.Graphics,d.Graphics.prototype.destroy=function(){this.clear(),this.group&&this.group.remove(this),this.game=null},d.Graphics.prototype.drawPolygon=function(a){this.moveTo(a.points[0].x,a.points[0].y);for(var b=1;bh;h++)f[h].updateTransform();var j=a.__renderGroup;j?a==j.root?j.render(this.projection,this.glFramebuffer):j.renderSpecific(a,this.projection,this.glFramebuffer):(this.renderGroup||(this.renderGroup=new c.WebGLRenderGroup(e)),this.renderGroup.setRenderable(a),this.renderGroup.render(this.projection,this.glFramebuffer)),a.worldTransform=g},d.RenderTexture.prototype.renderCanvas=function(a,b,d){var e=a.children;a.worldTransform=c.mat3.create(),b&&(a.worldTransform[2]=b.x,a.worldTransform[5]=b.y);for(var f=0,g=e.length;g>f;f++)e[f].updateTransform();d&&this.renderer.context.clearRect(0,0,this.width,this.height),this.renderer.renderDisplayObject(a),this.renderer.context.setTransform(1,0,0,1,0,0)},d.Canvas={create:function(a,b){a=a||256,b=b||256;var c=document.createElement("canvas");return c.width=a,c.height=b,c.style.display="block",c},getOffset:function(a,b){b=b||new d.Point;var c=a.getBoundingClientRect(),e=a.clientTop||document.body.clientTop||0,f=a.clientLeft||document.body.clientLeft||0,g=window.pageYOffset||a.scrollTop||document.body.scrollTop,h=window.pageXOffset||a.scrollLeft||document.body.scrollLeft;return b.x=c.left+h-f,b.y=c.top+g-e,b},getAspectRatio:function(a){return a.width/a.height},setBackgroundColor:function(a,b){return b=b||"rgb(0,0,0)",a.style.backgroundColor=b,a},setTouchAction:function(a,b){return b=b||"none",a.style.msTouchAction=b,a.style["ms-touch-action"]=b,a.style["touch-action"]=b,a},setUserSelect:function(a,b){return b=b||"none",a.style["-webkit-touch-callout"]=b,a.style["-webkit-user-select"]=b,a.style["-khtml-user-select"]=b,a.style["-moz-user-select"]=b,a.style["-ms-user-select"]=b,a.style["user-select"]=b,a.style["-webkit-tap-highlight-color"]="rgba(0, 0, 0, 0)",a},addToDOM:function(a,b,c){var d;return"undefined"==typeof c&&(c=!0),b&&("string"==typeof b?d=document.getElementById(b):"object"==typeof b&&1===b.nodeType&&(d=b),c&&(d.style.overflow="hidden")),d||(d=document.body),d.appendChild(a),a},setTransform:function(a,b,c,d,e,f,g){return a.setTransform(d,f,g,e,b,c),a},setSmoothingEnabled:function(a,b){return a.imageSmoothingEnabled=b,a.mozImageSmoothingEnabled=b,a.oImageSmoothingEnabled=b,a.webkitImageSmoothingEnabled=b,a.msImageSmoothingEnabled=b,a},setImageRenderingCrisp:function(a){return a.style["image-rendering"]="crisp-edges",a.style["image-rendering"]="-moz-crisp-edges",a.style["image-rendering"]="-webkit-optimize-contrast",a.style.msInterpolationMode="nearest-neighbor",a},setImageRenderingBicubic:function(a){return a.style["image-rendering"]="auto",a.style.msInterpolationMode="bicubic",a}},d.StageScaleMode=function(a,b,c){this.game=a,this.width=b,this.height=c,this.minWidth=null,this.maxWidth=null,this.minHeight=null,this.maxHeight=null,this._startHeight=0,this.forceLandscape=!1,this.forcePortrait=!1,this.incorrectOrientation=!1,this.pageAlignHorizontally=!1,this.pageAlignVertically=!1,this._width=0,this._height=0,this.maxIterations=5,this.orientationSprite=null,this.enterLandscape=new d.Signal,this.enterPortrait=new d.Signal,this.enterIncorrectOrientation=new d.Signal,this.leaveIncorrectOrientation=new d.Signal,this.hasResized=new d.Signal,this.orientation=window.orientation?window.orientation:window.outerWidth>window.outerHeight?90:0,this.scaleFactor=new d.Point(1,1),this.scaleFactorInversed=new d.Point(1,1),this.margin=new d.Point(0,0),this.aspectRatio=0,this.event=null;var e=this;window.addEventListener("orientationchange",function(a){return e.checkOrientation(a)},!1),window.addEventListener("resize",function(a){return e.checkResize(a)},!1),document.addEventListener("webkitfullscreenchange",function(a){return e.fullScreenChange(a)},!1),document.addEventListener("mozfullscreenchange",function(a){return e.fullScreenChange(a)},!1),document.addEventListener("fullscreenchange",function(a){return e.fullScreenChange(a)},!1)},d.StageScaleMode.EXACT_FIT=0,d.StageScaleMode.NO_SCALE=1,d.StageScaleMode.SHOW_ALL=2,d.StageScaleMode.prototype={startFullScreen:function(a){if(!this.isFullScreen){"undefined"!=typeof a&&d.Canvas.setSmoothingEnabled(this.game.context,a);var b=this.game.canvas;this._width=this.width,this._height=this.height,console.log("startFullScreen",this._width,this._height),b.requestFullScreen?b.requestFullScreen():b.mozRequestFullScreen?b.mozRequestFullScreen():b.webkitRequestFullScreen&&b.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT)}},stopFullScreen:function(){document.cancelFullScreen?document.cancelFullScreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen&&document.webkitCancelFullScreen()},fullScreenChange:function(a){this.event=a,this.isFullScreen?(this.game.stage.canvas.style.width="100%",this.game.stage.canvas.style.height="100%",this.setMaximum(),this.game.input.scale.setTo(this.game.width/this.width,this.game.height/this.height),this.aspectRatio=this.width/this.height,this.scaleFactor.x=this.game.width/this.width,this.scaleFactor.y=this.game.height/this.height):(this.game.stage.canvas.style.width=this.game.width+"px",this.game.stage.canvas.style.height=this.game.height+"px",this.width=this._width,this.height=this._height,this.game.input.scale.setTo(this.game.width/this.width,this.game.height/this.height),this.aspectRatio=this.width/this.height,this.scaleFactor.x=this.game.width/this.width,this.scaleFactor.y=this.game.height/this.height)},forceOrientation:function(a,b,d){"undefined"==typeof b&&(b=!1),this.forceLandscape=a,this.forcePortrait=b,"undefined"!=typeof d&&((null==d||this.game.cache.checkImageKey(d)===!1)&&(d="__default"),this.orientationSprite=new c.Sprite(c.TextureCache[d]),this.orientationSprite.anchor.x=.5,this.orientationSprite.anchor.y=.5,this.orientationSprite.position.x=this.game.width/2,this.orientationSprite.position.y=this.game.height/2,this.checkOrientationState(),this.incorrectOrientation?(this.orientationSprite.visible=!0,this.game.world.visible=!1):(this.orientationSprite.visible=!1,this.game.world.visible=!0),this.game.stage._stage.addChild(this.orientationSprite))},checkOrientationState:function(){this.incorrectOrientation?(this.forceLandscape&&window.innerWidth>window.innerHeight||this.forcePortrait&&window.innerHeight>window.innerWidth)&&(this.game.paused=!1,this.incorrectOrientation=!1,this.leaveIncorrectOrientation.dispatch(),this.orientationSprite&&(this.orientationSprite.visible=!1,this.game.world.visible=!0),this.refresh()):(this.forceLandscape&&window.innerWidthwindow.outerHeight?90:0,this.isLandscape?this.enterLandscape.dispatch(this.orientation,!0,!1):this.enterPortrait.dispatch(this.orientation,!1,!0),this.game.stage.scaleMode!==d.StageScaleMode.NO_SCALE&&this.refresh(),this.checkOrientationState()},refresh:function(){if(this.game.device.iPad===!1&&this.game.device.webApp===!1&&this.game.device.desktop===!1&&(this.game.device.android&&this.game.device.chrome===!1?window.scrollTo(0,1):window.scrollTo(0,0)),null==this._check&&this.maxIterations>0){this._iterations=this.maxIterations;var a=this;this._check=window.setInterval(function(){return a.setScreenSize()},10),this.setScreenSize()}},setScreenSize:function(a){"undefined"==typeof a&&(a=!1),this.game.device.iPad===!1&&this.game.device.webApp===!1&&this.game.device.desktop===!1&&(this.game.device.android&&this.game.device.chrome===!1?window.scrollTo(0,1):window.scrollTo(0,0)),this._iterations--,(a||window.innerHeight>this._startHeight||this._iterations<0)&&(document.documentElement.style.minHeight=window.innerHeight+"px",this.incorrectOrientation===!0?this.setMaximum():this.game.stage.scaleMode==d.StageScaleMode.EXACT_FIT?this.setExactFit():this.game.stage.scaleMode==d.StageScaleMode.SHOW_ALL&&this.setShowAll(),this.setSize(),clearInterval(this._check),this._check=null)},setSize:function(){this.incorrectOrientation===!1&&(this.maxWidth&&this.width>this.maxWidth&&(this.width=this.maxWidth),this.maxHeight&&this.height>this.maxHeight&&(this.height=this.maxHeight),this.minWidth&&this.widththis.maxWidth?this.maxWidth:a,this.height=this.maxHeight&&b>this.maxHeight?this.maxHeight:b}},Object.defineProperty(d.StageScaleMode.prototype,"isFullScreen",{get:function(){return document.fullscreenElement||document.mozFullScreenElement||document.webkitFullscreenElement}}),Object.defineProperty(d.StageScaleMode.prototype,"isPortrait",{get:function(){return 0===this.orientation||180==this.orientation}}),Object.defineProperty(d.StageScaleMode.prototype,"isLandscape",{get:function(){return 90===this.orientation||-90===this.orientation}}),d.Device=function(){this.patchAndroidClearRectBug=!1,this.desktop=!1,this.iOS=!1,this.cocoonJS=!1,this.android=!1,this.chromeOS=!1,this.linux=!1,this.macOS=!1,this.windows=!1,this.canvas=!1,this.file=!1,this.fileSystem=!1,this.localStorage=!1,this.webGL=!1,this.worker=!1,this.touch=!1,this.mspointer=!1,this.css3D=!1,this.pointerLock=!1,this.typedArray=!1,this.arora=!1,this.chrome=!1,this.epiphany=!1,this.firefox=!1,this.ie=!1,this.ieVersion=0,this.mobileSafari=!1,this.midori=!1,this.opera=!1,this.safari=!1,this.webApp=!1,this.audioData=!1,this.webAudio=!1,this.ogg=!1,this.opus=!1,this.mp3=!1,this.wav=!1,this.m4a=!1,this.webm=!1,this.iPhone=!1,this.iPhone4=!1,this.iPad=!1,this.pixelRatio=0,this.littleEndian=!1,this._checkAudio(),this._checkBrowser(),this._checkCSS3D(),this._checkDevice(),this._checkFeatures(),this._checkOS() -},d.Device.prototype={_checkOS:function(){var a=navigator.userAgent;/Android/.test(a)?this.android=!0:/CrOS/.test(a)?this.chromeOS=!0:/iP[ao]d|iPhone/i.test(a)?this.iOS=!0:/Linux/.test(a)?this.linux=!0:/Mac OS/.test(a)?this.macOS=!0:/Windows/.test(a)&&(this.windows=!0),(this.windows||this.macOS||this.linux)&&(this.desktop=!0)},_checkFeatures:function(){this.canvas=!!window.CanvasRenderingContext2D;try{this.localStorage=!!localStorage.getItem}catch(a){this.localStorage=!1}this.file=!!(window.File&&window.FileReader&&window.FileList&&window.Blob),this.fileSystem=!!window.requestFileSystem,this.webGL=function(){try{var a=document.createElement("canvas");return!!window.WebGLRenderingContext&&(a.getContext("webgl")||a.getContext("experimental-webgl"))}catch(b){return!1}}(),this.webGL=null===this.webGL||this.webGL===!1?!1:!0,this.worker=!!window.Worker,("ontouchstart"in document.documentElement||window.navigator.maxTouchPoints&&window.navigator.maxTouchPoints>1)&&(this.touch=!0),(window.navigator.msPointerEnabled||window.navigator.pointerEnabled)&&(this.mspointer=!0),this.pointerLock="pointerLockElement"in document||"mozPointerLockElement"in document||"webkitPointerLockElement"in document},_checkBrowser:function(){var a=navigator.userAgent;/Arora/.test(a)?this.arora=!0:/Chrome/.test(a)?this.chrome=!0:/Epiphany/.test(a)?this.epiphany=!0:/Firefox/.test(a)?this.firefox=!0:/Mobile Safari/.test(a)?this.mobileSafari=!0:/MSIE (\d+\.\d+);/.test(a)?(this.ie=!0,this.ieVersion=parseInt(RegExp.$1,10)):/Midori/.test(a)?this.midori=!0:/Opera/.test(a)?this.opera=!0:/Safari/.test(a)&&(this.safari=!0),navigator.standalone&&(this.webApp=!0),navigator.isCocoonJS&&(this.cocoonJS=!0)},_checkAudio:function(){this.audioData=!!window.Audio,this.webAudio=!(!window.webkitAudioContext&&!window.AudioContext);var a=document.createElement("audio"),b=!1;try{(b=!!a.canPlayType)&&(a.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,"")&&(this.ogg=!0),a.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/,"")&&(this.opus=!0),a.canPlayType("audio/mpeg;").replace(/^no$/,"")&&(this.mp3=!0),a.canPlayType('audio/wav; codecs="1"').replace(/^no$/,"")&&(this.wav=!0),(a.canPlayType("audio/x-m4a;")||a.canPlayType("audio/aac;").replace(/^no$/,""))&&(this.m4a=!0),a.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/,"")&&(this.webm=!0))}catch(c){}},_checkDevice:function(){this.pixelRatio=window.devicePixelRatio||1,this.iPhone=-1!=navigator.userAgent.toLowerCase().indexOf("iphone"),this.iPhone4=2==this.pixelRatio&&this.iPhone,this.iPad=-1!=navigator.userAgent.toLowerCase().indexOf("ipad"),"undefined"!=typeof Int8Array?(this.littleEndian=new Int8Array(new Int16Array([1]).buffer)[0]>0,this.typedArray=!0):(this.littleEndian=!1,this.typedArray=!1)},_checkCSS3D:function(){var a,b=document.createElement("p"),c={webkitTransform:"-webkit-transform",OTransform:"-o-transform",msTransform:"-ms-transform",MozTransform:"-moz-transform",transform:"transform"};document.body.insertBefore(b,null);for(var d in c)void 0!==b.style[d]&&(b.style[d]="translate3d(1px,1px,1px)",a=window.getComputedStyle(b).getPropertyValue(c[d]));document.body.removeChild(b),this.css3D=void 0!==a&&a.length>0&&"none"!==a},canPlayAudio:function(a){return"mp3"==a&&this.mp3?!0:"ogg"==a&&(this.ogg||this.opus)?!0:"m4a"==a&&this.m4a?!0:"wav"==a&&this.wav?!0:"webm"==a&&this.webm?!0:!1},isConsoleOpen:function(){return window.console&&window.console.firebug?!0:window.console?(console.profile(),console.profileEnd(),console.clear&&console.clear(),console.profiles.length>0):!1}},d.RequestAnimationFrame=function(a){this.game=a,this.isRunning=!1;for(var b=["ms","moz","webkit","o"],c=0;c>>0,b-=d,b*=d,d=b>>>0,b-=d,d+=4294967296*b;return 2.3283064365386963e-10*(d>>>0)},integer:function(){return 4294967296*this.rnd.apply(this)},frac:function(){return this.rnd.apply(this)+1.1102230246251565e-16*(0|2097152*this.rnd.apply(this))},real:function(){return this.integer()+this.frac()},integerInRange:function(a,b){return Math.floor(this.realInRange(a,b))},realInRange:function(a,b){return this.frac()*(b-a)+a},normal:function(){return 1-2*this.frac()},uuid:function(){var a="",b="";for(b=a="";a++<36;b+=~a%5|4&3*a?(15^a?8^this.frac()*(20^a?16:4):4).toString(16):"-");return b},pick:function(a){return a[this.integerInRange(0,a.length)]},weightedPick:function(a){return a[~~(Math.pow(this.frac(),2)*a.length)]},timestamp:function(a,b){return this.realInRange(a||9466848e5,b||1577862e6)},angle:function(){return this.integerInRange(-180,180)}},d.Math={PI2:2*Math.PI,fuzzyEqual:function(a,b,c){return"undefined"==typeof c&&(c=1e-4),Math.abs(a-b)a},fuzzyGreaterThan:function(a,b,c){return"undefined"==typeof c&&(c=1e-4),a>b-c},fuzzyCeil:function(a,b){return"undefined"==typeof b&&(b=1e-4),Math.ceil(a-b)},fuzzyFloor:function(a,b){return"undefined"==typeof b&&(b=1e-4),Math.floor(a+b)},average:function(){for(var a=[],b=0;b0?Math.floor(a):Math.ceil(a)},shear:function(a){return a%1},snapTo:function(a,b,c){return"undefined"==typeof c&&(c=0),0===b?a:(a-=c,a=b*Math.round(a/b),c+a)},snapToFloor:function(a,b,c){return"undefined"==typeof c&&(c=0),0===b?a:(a-=c,a=b*Math.floor(a/b),c+a)},snapToCeil:function(a,b,c){return"undefined"==typeof c&&(c=0),0===b?a:(a-=c,a=b*Math.ceil(a/b),c+a)},snapToInArray:function(a,b,c){if("undefined"==typeof c&&(c=!0),c&&b.sort(),a=f-a?f:e},roundTo:function(a,b,c){"undefined"==typeof b&&(b=0),"undefined"==typeof c&&(c=10);var d=Math.pow(c,-b);return Math.round(a*d)/d},floorTo:function(a,b,c){"undefined"==typeof b&&(b=0),"undefined"==typeof c&&(c=10);var d=Math.pow(c,-b);return Math.floor(a*d)/d},ceilTo:function(a,b,c){"undefined"==typeof b&&(b=0),"undefined"==typeof c&&(c=10);var d=Math.pow(c,-b);return Math.ceil(a*d)/d},interpolateFloat:function(a,b,c){return(b-a)*c+a},angleBetween:function(a,b,c,d){return Math.atan2(d-b,c-a)},normalizeAngle:function(a,b){"undefined"==typeof b&&(b=!0);var c=b?Math.PI:180;return this.wrap(a,-c,c)},nearestAngleBetween:function(a,b,c){"undefined"==typeof c&&(c=!0);var d=c?Math.PI:180;return a=this.normalizeAngle(a,c),b=this.normalizeAngle(b,c),-d/2>a&&b>d/2&&(a+=2*d),-d/2>b&&a>d/2&&(b+=2*d),b-a},interpolateAngles:function(a,b,c,d,e){return"undefined"==typeof d&&(d=!0),"undefined"==typeof e&&(e=null),a=this.normalizeAngle(a,d),b=this.normalizeAngleToAnother(b,a,d),"function"==typeof e?e(c,a,b-a,1):this.interpolateFloat(a,b,c)},chanceRoll:function(a){return"undefined"==typeof a&&(a=50),0>=a?!1:a>=100?!0:100*Math.random()>=a?!1:!0},numberArray:function(a,b){for(var c=[],d=a;b>=d;d++)c.push(d);return c},maxAdd:function(a,b,c){return a+=b,a>c&&(a=c),a},minSub:function(a,b,c){return a-=b,c>a&&(a=c),a},wrap:function(a,b,c){var d=c-b;if(0>=d)return 0;var e=(a-b)%d;return 0>e&&(e+=d),e+b},wrapValue:function(a,b,c){var d;return a=Math.abs(a),b=Math.abs(b),c=Math.abs(c),d=(a+b)%c},randomSign:function(){return Math.random()>.5?1:-1},isOdd:function(a){return 1&a},isEven:function(a){return 1&a?!1:!0},max:function(){for(var a=1,b=0,c=arguments.length;c>a;a++)arguments[b]a;a++)arguments[a]c?d=c:b>a&&(d=b),d},linearInterpolation:function(a,b){var c=a.length-1,d=c*b,e=Math.floor(d);return 0>b?this.linear(a[0],a[1],d):b>1?this.linear(a[c],a[c-1],c-d):this.linear(a[e],a[e+1>c?c:e+1],d-e)},bezierInterpolation:function(a,b){for(var c=0,d=a.length-1,e=0;d>=e;e++)c+=Math.pow(1-b,d-e)*Math.pow(b,e)*a[e]*this.bernstein(d,e);return c},catmullRomInterpolation:function(a,b){var c=a.length-1,d=c*b,e=Math.floor(d);return a[0]===a[c]?(0>b&&(e=Math.floor(d=c*(1+b))),this.catmullRom(a[(e-1+c)%c],a[e],a[(e+1)%c],a[(e+2)%c],d-e)):0>b?a[0]-(this.catmullRom(a[0],a[0],a[1],a[1],-d)-a[0]):b>1?a[c]-(this.catmullRom(a[c],a[c],a[c-1],a[c-1],d-c)-a[c]):this.catmullRom(a[e?e-1:0],a[e],a[e+1>c?c:e+1],a[e+2>c?c:e+2],d-e)},linear:function(a,b,c){return(b-a)*c+a},bernstein:function(a,b){return this.factorial(a)/this.factorial(b)/this.factorial(a-b)},catmullRom:function(a,b,c,d,e){var f=.5*(c-a),g=.5*(d-b),h=e*e,i=e*h;return(2*b-2*c+f+g)*i+(-3*b+3*c-2*f-g)*h+f*e+b},difference:function(a,b){return Math.abs(a-b)},getRandom:function(a,b,c){if("undefined"==typeof b&&(b=0),"undefined"==typeof c&&(c=0),null!=a){var d=c;if((0===d||d>a.length-b)&&(d=a.length-b),d>0)return a[b+Math.floor(Math.random()*d)]}return null},floor:function(a){var b=0|a;return a>0?b:b!=a?b-1:b},ceil:function(a){var b=0|a;return a>0?b!=a?b+1:b:b},sinCosGenerator:function(a,b,c,d){"undefined"==typeof b&&(b=1),"undefined"==typeof c&&(c=1),"undefined"==typeof d&&(d=1);for(var e=b,f=c,g=d*Math.PI/a,h=[],i=[],j=0;a>j;j++)f-=e*g,e+=f*g,h[j]=f,i[j]=e;return{sin:i,cos:h,length:a}},shift:function(a){var b=a.shift();return a.push(b),b},shuffleArray:function(a){for(var b=a.length-1;b>0;b--){var c=Math.floor(Math.random()*(b+1)),d=a[b];a[b]=a[c],a[c]=d}return a},distance:function(a,b,c,d){var e=a-c,f=b-d;return Math.sqrt(e*e+f*f)},distanceRounded:function(a,b,c,e){return Math.round(d.Math.distance(a,b,c,e))},clamp:function(a,b,c){return b>a?b:a>c?c:a},clampBottom:function(a,b){return b>a?b:a},within:function(a,b,c){return Math.abs(a-b)<=c},mapLinear:function(a,b,c,d,e){return d+(a-b)*(e-d)/(c-b)},smoothstep:function(a,b,c){return b>=a?0:a>=c?1:(a=(a-b)/(c-b),a*a*(3-2*a))},smootherstep:function(a,b,c){return b>=a?0:a>=c?1:(a=(a-b)/(c-b),a*a*a*(a*(6*a-15)+10))},sign:function(a){return 0>a?-1:a>0?1:0},degToRad:function(){var a=Math.PI/180;return function(b){return b*a}}(),radToDeg:function(){var a=180/Math.PI;return function(b){return b*a}}()},d.QuadTree=function(a,b,c,d,e,f,g,h){this.physicsManager=a,this.ID=a.quadTreeID,a.quadTreeID++,this.maxObjects=f||10,this.maxLevels=g||4,this.level=h||0,this.bounds={x:Math.round(b),y:Math.round(c),width:d,height:e,subWidth:Math.floor(d/2),subHeight:Math.floor(e/2),right:Math.round(b)+Math.floor(d/2),bottom:Math.round(c)+Math.floor(e/2)},this.objects=[],this.nodes=[]},d.QuadTree.prototype={split:function(){this.level++,this.nodes[0]=new d.QuadTree(this.physicsManager,this.bounds.right,this.bounds.y,this.bounds.subWidth,this.bounds.subHeight,this.maxObjects,this.maxLevels,this.level),this.nodes[1]=new d.QuadTree(this.physicsManager,this.bounds.x,this.bounds.y,this.bounds.subWidth,this.bounds.subHeight,this.maxObjects,this.maxLevels,this.level),this.nodes[2]=new d.QuadTree(this.physicsManager,this.bounds.x,this.bounds.bottom,this.bounds.subWidth,this.bounds.subHeight,this.maxObjects,this.maxLevels,this.level),this.nodes[3]=new d.QuadTree(this.physicsManager,this.bounds.right,this.bounds.bottom,this.bounds.subWidth,this.bounds.subHeight,this.maxObjects,this.maxLevels,this.level)},insert:function(a){var b,c=0;if(null!=this.nodes[0]&&(b=this.getIndex(a),-1!==b))return this.nodes[b].insert(a),void 0;if(this.objects.push(a),this.objects.length>this.maxObjects&&this.levelthis.bounds.bottom&&(b=2):a.x>this.bounds.right&&(a.ythis.bounds.bottom&&(b=3)),b},retrieve:function(a){var b=this.objects;return a.body.quadTreeIndex=this.getIndex(a.body),a.body.quadTreeIDs.push(this.ID),this.nodes[0]&&(-1!==a.body.quadTreeIndex?b=b.concat(this.nodes[a.body.quadTreeIndex].retrieve(a)):(b=b.concat(this.nodes[0].retrieve(a)),b=b.concat(this.nodes[1].retrieve(a)),b=b.concat(this.nodes[2].retrieve(a)),b=b.concat(this.nodes[3].retrieve(a)))),b},clear:function(){this.objects=[];for(var a=0,b=this.nodes.length;b>a;a++)this.nodes[a]&&(this.nodes[a].clear(),delete this.nodes[a])}},d.Circle=function(a,b,c){a=a||0,b=b||0,c=c||0,this.x=a,this.y=b,this._diameter=c,this._radius=c>0?.5*c:0},d.Circle.prototype={circumference:function(){return 2*Math.PI*this._radius},setTo:function(a,b,c){return this.x=a,this.y=b,this._diameter=c,this._radius=.5*c,this},copyFrom:function(a){return this.setTo(a.x,a.y,a.diameter)},copyTo:function(a){return a.x=this.x,a.y=this.y,a.diameter=this._diameter,a},distance:function(a,b){return"undefined"==typeof b&&(b=!1),b?d.Math.distanceRound(this.x,this.y,a.x,a.y):d.Math.distance(this.x,this.y,a.x,a.y)},clone:function(a){return"undefined"==typeof a&&(a=new d.Circle),a.setTo(this.x,this.y,this.diameter)},contains:function(a,b){return d.Circle.contains(this,a,b)},circumferencePoint:function(a,b,c){return d.Circle.circumferencePoint(this,a,b,c)},offset:function(a,b){return this.x+=a,this.y+=b,this},offsetPoint:function(a){return this.offset(a.x,a.y)},toString:function(){return"[{Phaser.Circle (x="+this.x+" y="+this.y+" diameter="+this.diameter+" radius="+this.radius+")}]"}},Object.defineProperty(d.Circle.prototype,"diameter",{get:function(){return this._diameter},set:function(a){a>0&&(this._diameter=a,this._radius=.5*a)}}),Object.defineProperty(d.Circle.prototype,"radius",{get:function(){return this._radius},set:function(a){a>0&&(this._radius=a,this._diameter=2*a)}}),Object.defineProperty(d.Circle.prototype,"left",{get:function(){return this.x-this._radius},set:function(a){a>this.x?(this._radius=0,this._diameter=0):this.radius=this.x-a}}),Object.defineProperty(d.Circle.prototype,"right",{get:function(){return this.x+this._radius},set:function(a){athis.y?(this._radius=0,this._diameter=0):this.radius=this.y-a}}),Object.defineProperty(d.Circle.prototype,"bottom",{get:function(){return this.y+this._radius},set:function(a){a0?Math.PI*this._radius*this._radius:0}}),Object.defineProperty(d.Circle.prototype,"empty",{get:function(){return 0===this._diameter},set:function(a){a===!0&&this.setTo(0,0,0)}}),d.Circle.contains=function(a,b,c){if(b>=a.left&&b<=a.right&&c>=a.top&&c<=a.bottom){var d=(a.x-b)*(a.x-b),e=(a.y-c)*(a.y-c);return d+e<=a.radius*a.radius}return!1},d.Circle.equals=function(a,b){return a.x==b.x&&a.y==b.y&&a.diameter==b.diameter},d.Circle.intersects=function(a,b){return d.Math.distance(a.x,a.y,b.x,b.y)<=a.radius+b.radius},d.Circle.circumferencePoint=function(a,b,c,e){return"undefined"==typeof c&&(c=!1),"undefined"==typeof e&&(e=new d.Point),c===!0&&(b=d.Math.radToDeg(b)),e.x=a.x+a.radius*Math.cos(b),e.y=a.y+a.radius*Math.sin(b),e},d.Circle.intersectsRectangle=function(a,b){var c=Math.abs(a.x-b.x-b.halfWidth),d=b.halfWidth+a.radius;if(c>d)return!1;var e=Math.abs(a.y-b.y-b.halfHeight),f=b.halfHeight+a.radius;if(e>f)return!1;if(c<=b.halfWidth||e<=b.halfHeight)return!0;var g=c-b.halfWidth,h=e-b.halfHeight,i=g*g,j=h*h,k=a.radius*a.radius;return k>=i+j},d.Point=function(a,b){a=a||0,b=b||0,this.x=a,this.y=b},d.Point.prototype={copyFrom:function(a){return this.setTo(a.x,a.y)},invert:function(){return this.setTo(this.y,this.x)},setTo:function(a,b){return this.x=a,this.y=b,this},add:function(a,b){return this.x+=a,this.y+=b,this},subtract:function(a,b){return this.x-=a,this.y-=b,this},multiply:function(a,b){return this.x*=a,this.y*=b,this},divide:function(a,b){return this.x/=a,this.y/=b,this},clampX:function(a,b){return this.x=d.Math.clamp(this.x,a,b),this},clampY:function(a,b){return this.y=d.Math.clamp(this.y,a,b),this},clamp:function(a,b){return this.x=d.Math.clamp(this.x,a,b),this.y=d.Math.clamp(this.y,a,b),this},clone:function(a){return"undefined"==typeof a&&(a=new d.Point),a.setTo(this.x,this.y)},copyTo:function(a){return a.x=this.x,a.y=this.y,a},distance:function(a,b){return d.Point.distance(this,a,b)},equals:function(a){return a.x==this.x&&a.y==this.y},rotate:function(a,b,c,e,f){return d.Point.rotate(this,a,b,c,e,f)},getMagnitude:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},setMagnitude:function(a){return this.normalize().multiply(a,a)},normalize:function(){if(!this.isZero()){var a=this.getMagnitude();this.x/=a,this.y/=a}return this},isZero:function(){return 0===this.x&&0===this.y},toString:function(){return"[{Point (x="+this.x+" y="+this.y+")}]"}},d.Point.add=function(a,b,c){return"undefined"==typeof c&&(c=new d.Point),c.x=a.x+b.x,c.y=a.y+b.y,c},d.Point.subtract=function(a,b,c){return"undefined"==typeof c&&(c=new d.Point),c.x=a.x-b.x,c.y=a.y-b.y,c},d.Point.multiply=function(a,b,c){return"undefined"==typeof c&&(c=new d.Point),c.x=a.x*b.x,c.y=a.y*b.y,c},d.Point.divide=function(a,b,c){return"undefined"==typeof c&&(c=new d.Point),c.x=a.x/b.x,c.y=a.y/b.y,c},d.Point.equals=function(a,b){return a.x==b.x&&a.y==b.y},d.Point.distance=function(a,b,c){return"undefined"==typeof c&&(c=!1),c?d.Math.distanceRound(a.x,a.y,b.x,b.y):d.Math.distance(a.x,a.y,b.x,b.y)},d.Point.rotate=function(a,b,c,e,f,g){return f=f||!1,g=g||null,f&&(e=d.Math.degToRad(e)),null===g&&(g=Math.sqrt((b-a.x)*(b-a.x)+(c-a.y)*(c-a.y))),a.setTo(b+g*Math.cos(e),c+g*Math.sin(e))},d.Rectangle=function(a,b,c,d){a=a||0,b=b||0,c=c||0,d=d||0,this.x=a,this.y=b,this.width=c,this.height=d},d.Rectangle.prototype={offset:function(a,b){return this.x+=a,this.y+=b,this},offsetPoint:function(a){return this.offset(a.x,a.y)},setTo:function(a,b,c,d){return this.x=a,this.y=b,this.width=c,this.height=d,this},floor:function(){this.x=Math.floor(this.x),this.y=Math.floor(this.y)},floorAll:function(){this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.width=Math.floor(this.width),this.height=Math.floor(this.height)},copyFrom:function(a){return this.setTo(a.x,a.y,a.width,a.height)},copyTo:function(a){return a.x=this.x,a.y=this.y,a.width=this.width,a.height=this.height,a},inflate:function(a,b){return d.Rectangle.inflate(this,a,b)},size:function(a){return d.Rectangle.size(this,a)},clone:function(a){return d.Rectangle.clone(this,a)},contains:function(a,b){return d.Rectangle.contains(this,a,b)},containsRect:function(a){return d.Rectangle.containsRect(this,a)},equals:function(a){return d.Rectangle.equals(this,a)},intersection:function(a,b){return d.Rectangle.intersection(this,a,b)},intersects:function(a,b){return d.Rectangle.intersects(this,a,b)},intersectsRaw:function(a,b,c,e,f){return d.Rectangle.intersectsRaw(this,a,b,c,e,f)},union:function(a,b){return d.Rectangle.union(this,a,b)},toString:function(){return"[{Rectangle (x="+this.x+" y="+this.y+" width="+this.width+" height="+this.height+" empty="+this.empty+")}]"}},Object.defineProperty(d.Rectangle.prototype,"halfWidth",{get:function(){return Math.round(this.width/2)}}),Object.defineProperty(d.Rectangle.prototype,"halfHeight",{get:function(){return Math.round(this.height/2)}}),Object.defineProperty(d.Rectangle.prototype,"bottom",{get:function(){return this.y+this.height},set:function(a){this.height=a<=this.y?0:this.y-a}}),Object.defineProperty(d.Rectangle.prototype,"bottomRight",{get:function(){return new d.Point(this.right,this.bottom)},set:function(a){this.right=a.x,this.bottom=a.y}}),Object.defineProperty(d.Rectangle.prototype,"left",{get:function(){return this.x},set:function(a){this.width=a>=this.right?0:this.right-a,this.x=a}}),Object.defineProperty(d.Rectangle.prototype,"right",{get:function(){return this.x+this.width},set:function(a){this.width=a<=this.x?0:this.x+a}}),Object.defineProperty(d.Rectangle.prototype,"volume",{get:function(){return this.width*this.height}}),Object.defineProperty(d.Rectangle.prototype,"perimeter",{get:function(){return 2*this.width+2*this.height}}),Object.defineProperty(d.Rectangle.prototype,"centerX",{get:function(){return this.x+this.halfWidth},set:function(a){this.x=a-this.halfWidth}}),Object.defineProperty(d.Rectangle.prototype,"centerY",{get:function(){return this.y+this.halfHeight},set:function(a){this.y=a-this.halfHeight}}),Object.defineProperty(d.Rectangle.prototype,"top",{get:function(){return this.y},set:function(a){a>=this.bottom?(this.height=0,this.y=a):this.height=this.bottom-a}}),Object.defineProperty(d.Rectangle.prototype,"topLeft",{get:function(){return new d.Point(this.x,this.y)},set:function(a){this.x=a.x,this.y=a.y}}),Object.defineProperty(d.Rectangle.prototype,"empty",{get:function(){return!this.width||!this.height},set:function(a){a===!0&&this.setTo(0,0,0,0)}}),d.Rectangle.inflate=function(a,b,c){return a.x-=b,a.width+=2*b,a.y-=c,a.height+=2*c,a},d.Rectangle.inflatePoint=function(a,b){return d.Rectangle.inflate(a,b.x,b.y)},d.Rectangle.size=function(a,b){return"undefined"==typeof b&&(b=new d.Point),b.setTo(a.width,a.height)},d.Rectangle.clone=function(a,b){return"undefined"==typeof b&&(b=new d.Rectangle),b.setTo(a.x,a.y,a.width,a.height)},d.Rectangle.contains=function(a,b,c){return b>=a.x&&b<=a.right&&c>=a.y&&c<=a.bottom},d.Rectangle.containsRaw=function(a,b,c,d,e,f){return e>=a&&a+c>=e&&f>=b&&b+d>=f},d.Rectangle.containsPoint=function(a,b){return d.Rectangle.contains(a,b.x,b.y)},d.Rectangle.containsRect=function(a,b){return a.volume>b.volume?!1:a.x>=b.x&&a.y>=b.y&&a.right<=b.right&&a.bottom<=b.bottom},d.Rectangle.equals=function(a,b){return a.x==b.x&&a.y==b.y&&a.width==b.width&&a.height==b.height},d.Rectangle.intersection=function(a,b,c){return c=c||new d.Rectangle,d.Rectangle.intersects(a,b)&&(c.x=Math.max(a.x,b.x),c.y=Math.max(a.y,b.y),c.width=Math.min(a.right,b.right)-c.x,c.height=Math.min(a.bottom,b.bottom)-c.y),c},d.Rectangle.intersects=function(a,b){return a.xa.right+f||ca.bottom+f||e1){if(a&&a==this.decodeURI(e[0]))return this.decodeURI(e[1]);b[this.decodeURI(e[0])]=this.decodeURI(e[1])}}return b},decodeURI:function(a){return decodeURIComponent(a.replace(/\+/g," "))}},d.TweenManager=function(a){this.game=a,this._tweens=[],this._add=[],this.game.onPause.add(this.pauseAll,this),this.game.onResume.add(this.resumeAll,this)},d.TweenManager.prototype={REVISION:"11dev",getAll:function(){return this._tweens},removeAll:function(){this._tweens=[]},add:function(a){this._add.push(a)},create:function(a){return new d.Tween(a,this.game)},remove:function(a){var b=this._tweens.indexOf(a);-1!==b&&(this._tweens[b].pendingDelete=!0)},update:function(){if(0===this._tweens.length&&0===this._add.length)return!1;for(var a=0,b=this._tweens.length;b>a;)this._tweens[a].update(this.game.time.now)?a++:(this._tweens.splice(a,1),b--);return this._add.length>0&&(this._tweens=this._tweens.concat(this._add),this._add.length=0),!0},isTweening:function(a){return this._tweens.some(function(b){return b._object===a})},pauseAll:function(){for(var a=this._tweens.length-1;a>=0;a--)this._tweens[a].pause()},resumeAll:function(){for(var a=this._tweens.length-1;a>=0;a--)this._tweens[a].resume()}},d.Tween=function(a,b){this._object=a,this.game=b,this._manager=this.game.tweens,this._valuesStart={},this._valuesEnd={},this._valuesStartRepeat={},this._duration=1e3,this._repeat=0,this._yoyo=!1,this._reversed=!1,this._delayTime=0,this._startTime=null,this._easingFunction=d.Easing.Linear.None,this._interpolationFunction=d.Math.linearInterpolation,this._chainedTweens=[],this._onStartCallback=null,this._onStartCallbackFired=!1,this._onUpdateCallback=null,this._onCompleteCallback=null,this._pausedTime=0,this.pendingDelete=!1;for(var c in a)this._valuesStart[c]=parseFloat(a[c],10);this.onStart=new d.Signal,this.onComplete=new d.Signal,this.isRunning=!1},d.Tween.prototype={to:function(a,b,c,d,e,f,g){b=b||1e3,c=c||null,d=d||!1,e=e||0,f=f||0,g=g||!1;var h;return this._parent?(h=this._manager.create(this._object),this._lastChild.chain(h),this._lastChild=h):(h=this,this._parent=this,this._lastChild=this),h._repeat=f,h._duration=b,h._valuesEnd=a,null!==c&&(h._easingFunction=c),e>0&&(h._delayTime=e),h._yoyo=g,d?this.start():this},start:function(){if(null!==this.game&&null!==this._object){this._manager.add(this),this.onStart.dispatch(this._object),this.isRunning=!0,this._onStartCallbackFired=!1,this._startTime=this.game.time.now+this._delayTime;for(var a in this._valuesEnd){if(this._valuesEnd[a]instanceof Array){if(0===this._valuesEnd[a].length)continue;this._valuesEnd[a]=[this._object[a]].concat(this._valuesEnd[a])}this._valuesStart[a]=this._object[a],this._valuesStart[a]instanceof Array==!1&&(this._valuesStart[a]*=1),this._valuesStartRepeat[a]=this._valuesStart[a]||0}return this}},stop:function(){return this.isRunning=!1,this._manager.remove(this),this},delay:function(a){return this._delayTime=a,this},repeat:function(a){return this._repeat=a,this},yoyo:function(a){return this._yoyo=a,this},easing:function(a){return this._easingFunction=a,this},interpolation:function(a){return this._interpolationFunction=a,this},chain:function(){return this._chainedTweens=arguments,this},loop:function(){return this._lastChild.chain(this),this},onStartCallback:function(a){return this._onStartCallback=a,this},onUpdateCallback:function(a){return this._onUpdateCallback=a,this},onCompleteCallback:function(a){return this._onCompleteCallback=a,this},pause:function(){this._paused=!0,this._pausedTime=this.game.time.now},resume:function(){this._paused=!1,this._startTime+=this.game.time.now-this._pausedTime},update:function(a){if(this.pendingDelete)return!1;if(this._paused||a1?1:c;var d=this._easingFunction(c);for(b in this._valuesEnd){var e=this._valuesStart[b]||0,f=this._valuesEnd[b];f instanceof Array?this._object[b]=this._interpolationFunction(f,d):("string"==typeof f&&(f=e+parseFloat(f,10)),"number"==typeof f&&(this._object[b]=e+(f-e)*d))}if(null!==this._onUpdateCallback&&this._onUpdateCallback.call(this._object,d),1==c){if(this._repeat>0){isFinite(this._repeat)&&this._repeat--;for(b in this._valuesStartRepeat){if("string"==typeof this._valuesEnd[b]&&(this._valuesStartRepeat[b]=this._valuesStartRepeat[b]+parseFloat(this._valuesEnd[b],10)),this._yoyo){var g=this._valuesStartRepeat[b];this._valuesStartRepeat[b]=this._valuesEnd[b],this._valuesEnd[b]=g,this._reversed=!this._reversed}this._valuesStart[b]=this._valuesStartRepeat[b]}return this._startTime=a+this._delayTime,this.onComplete.dispatch(this._object),null!==this._onCompleteCallback&&this._onCompleteCallback.call(this._object),!0}this.isRunning=!1,this.onComplete.dispatch(this._object),null!==this._onCompleteCallback&&this._onCompleteCallback.call(this._object);for(var h=0,i=this._chainedTweens.length;i>h;h++)this._chainedTweens[h].start(a);return!1}return!0}},d.Easing={Linear:{None:function(a){return a}},Quadratic:{In:function(a){return a*a},Out:function(a){return a*(2-a)},InOut:function(a){return(a*=2)<1?.5*a*a:-.5*(--a*(a-2)-1)}},Cubic:{In:function(a){return a*a*a},Out:function(a){return--a*a*a+1},InOut:function(a){return(a*=2)<1?.5*a*a*a:.5*((a-=2)*a*a+2)}},Quartic:{In:function(a){return a*a*a*a},Out:function(a){return 1- --a*a*a*a},InOut:function(a){return(a*=2)<1?.5*a*a*a*a:-.5*((a-=2)*a*a*a-2)}},Quintic:{In:function(a){return a*a*a*a*a},Out:function(a){return--a*a*a*a*a+1},InOut:function(a){return(a*=2)<1?.5*a*a*a*a*a:.5*((a-=2)*a*a*a*a+2)}},Sinusoidal:{In:function(a){return 1-Math.cos(a*Math.PI/2)},Out:function(a){return Math.sin(a*Math.PI/2)},InOut:function(a){return.5*(1-Math.cos(Math.PI*a))}},Exponential:{In:function(a){return 0===a?0:Math.pow(1024,a-1)},Out:function(a){return 1===a?1:1-Math.pow(2,-10*a)},InOut:function(a){return 0===a?0:1===a?1:(a*=2)<1?.5*Math.pow(1024,a-1):.5*(-Math.pow(2,-10*(a-1))+2)}},Circular:{In:function(a){return 1-Math.sqrt(1-a*a)},Out:function(a){return Math.sqrt(1- --a*a)},InOut:function(a){return(a*=2)<1?-.5*(Math.sqrt(1-a*a)-1):.5*(Math.sqrt(1-(a-=2)*a)+1)}},Elastic:{In:function(a){var b,c=.1,d=.4;return 0===a?0:1===a?1:(!c||1>c?(c=1,b=d/4):b=d*Math.asin(1/c)/(2*Math.PI),-(c*Math.pow(2,10*(a-=1))*Math.sin((a-b)*2*Math.PI/d)))},Out:function(a){var b,c=.1,d=.4;return 0===a?0:1===a?1:(!c||1>c?(c=1,b=d/4):b=d*Math.asin(1/c)/(2*Math.PI),c*Math.pow(2,-10*a)*Math.sin((a-b)*2*Math.PI/d)+1)},InOut:function(a){var b,c=.1,d=.4;return 0===a?0:1===a?1:(!c||1>c?(c=1,b=d/4):b=d*Math.asin(1/c)/(2*Math.PI),(a*=2)<1?-.5*c*Math.pow(2,10*(a-=1))*Math.sin((a-b)*2*Math.PI/d):.5*c*Math.pow(2,-10*(a-=1))*Math.sin((a-b)*2*Math.PI/d)+1)}},Back:{In:function(a){var b=1.70158;return a*a*((b+1)*a-b) -},Out:function(a){var b=1.70158;return--a*a*((b+1)*a+b)+1},InOut:function(a){var b=2.5949095;return(a*=2)<1?.5*a*a*((b+1)*a-b):.5*((a-=2)*a*((b+1)*a+b)+2)}},Bounce:{In:function(a){return 1-d.Easing.Bounce.Out(1-a)},Out:function(a){return 1/2.75>a?7.5625*a*a:2/2.75>a?7.5625*(a-=1.5/2.75)*a+.75:2.5/2.75>a?7.5625*(a-=2.25/2.75)*a+.9375:7.5625*(a-=2.625/2.75)*a+.984375},InOut:function(a){return.5>a?.5*d.Easing.Bounce.In(2*a):.5*d.Easing.Bounce.Out(2*a-1)+.5}}},d.Time=function(a){this.game=a,this._started=0,this._timeLastSecond=0,this._pauseStarted=0,this.physicsElapsed=0,this.time=0,this.pausedTime=0,this.now=0,this.elapsed=0,this.fps=0,this.fpsMin=1e3,this.fpsMax=0,this.msMin=1e3,this.msMax=0,this.frames=0,this.pauseDuration=0,this.timeToCall=0,this.lastTime=0,this.game.onPause.add(this.gamePaused,this),this.game.onResume.add(this.gameResumed,this),this._justResumed=!1},d.Time.prototype={update:function(a){this.now=a,this._justResumed&&(this.time=this.now,this._justResumed=!1),this.timeToCall=this.game.math.max(0,16-(a-this.lastTime)),this.elapsed=this.now-this.time,this.msMin=this.game.math.min(this.msMin,this.elapsed),this.msMax=this.game.math.max(this.msMax,this.elapsed),this.frames++,this.now>this._timeLastSecond+1e3&&(this.fps=Math.round(1e3*this.frames/(this.now-this._timeLastSecond)),this.fpsMin=this.game.math.min(this.fpsMin,this.fps),this.fpsMax=this.game.math.max(this.fpsMax,this.fps),this._timeLastSecond=this.now,this.frames=0),this.time=this.now,this.lastTime=a+this.timeToCall,this.physicsElapsed=1*(this.elapsed/1e3),this.physicsElapsed>1&&(this.physicsElapsed=1),this.game.paused&&(this.pausedTime=this.now-this._pauseStarted)},gamePaused:function(){this._pauseStarted=this.now},gameResumed:function(){this.time=Date.now(),this.pauseDuration=this.pausedTime,this._justResumed=!0},totalElapsedSeconds:function(){return.001*(this.now-this._started)},elapsedSince:function(a){return this.now-a},elapsedSecondsSince:function(a){return.001*(this.now-a)},reset:function(){this._started=this.now}},d.Timer=function(a){this.game=a,this._started=0,this._timeLastSecond=0,this.running=!1,this.events=[],this.onEvent=new d.Signal},d.Timer.prototype={add:function(a){this.events.push({delay:a,dispatched:!1,args:Array.prototype.splice.call(arguments,1)})},start:function(){this._started=this.game.time.now,this.running=!0},stop:function(){this.running=!1,this.events.length=0},update:function(){if(this.running)for(var a=this.seconds(),b=0,c=this.events.length;c>b;b++)this.events[b].dispatched===!1&&a>=this.events[b].delay&&(this.events[b].dispatched=!0,this.onEvent.dispatch.apply(this,this.events[b].args))},seconds:function(){return.001*(this.game.time.now-this._started)}},d.AnimationManager=function(a){this.sprite=a,this.game=a.game,this.currentFrame=null,this.updateIfVisible=!0,this.isLoaded=!1,this._frameData=null,this._anims={},this._outputFrames=[]},d.AnimationManager.prototype={loadFrameData:function(a){this._frameData=a,this.frame=0,this.isLoaded=!0},add:function(a,b,e,f,g){return null==this._frameData?(console.warn("No FrameData available for Phaser.Animation "+a),void 0):(e=e||60,"undefined"==typeof f&&(f=!1),"undefined"==typeof g&&(g=b&&"number"==typeof b[0]?!0:!1),null==this.sprite.events.onAnimationStart&&(this.sprite.events.onAnimationStart=new d.Signal,this.sprite.events.onAnimationComplete=new d.Signal,this.sprite.events.onAnimationLoop=new d.Signal),this._outputFrames.length=0,this._frameData.getFrameIndexes(b,g,this._outputFrames),this._anims[a]=new d.Animation(this.game,this.sprite,a,this._frameData,this._outputFrames,e,f),this.currentAnim=this._anims[a],this.currentFrame=this.currentAnim.currentFrame,this.sprite.setTexture(c.TextureCache[this.currentFrame.uuid]),this._anims[a])},validateFrames:function(a,b){"undefined"==typeof b&&(b=!0);for(var c=0;cthis._frameData.total)return!1}else if(this._frameData.checkFrameName(a[c])===!1)return!1;return!0},play:function(a,b,c,d){if(this._anims[a]){if(this.currentAnim!=this._anims[a])return this.currentAnim=this._anims[a],this.currentAnim.paused=!1,this.currentAnim.play(b,c,d);if(this.currentAnim.isPlaying===!1)return this.currentAnim.paused=!1,this.currentAnim.play(b,c,d)}},stop:function(a,b){"undefined"==typeof b&&(b=!1),"string"==typeof a?this._anims[a]&&(this.currentAnim=this._anims[a],this.currentAnim.stop(b)):this.currentAnim&&this.currentAnim.stop(b)},update:function(){return this.updateIfVisible&&this.sprite.visible===!1?!1:this.currentAnim&&this.currentAnim.update()===!0?(this.currentFrame=this.currentAnim.currentFrame,this.sprite.currentFrame=this.currentFrame,!0):!1},getAnimation:function(a){return"string"==typeof a&&this._anims[a]?this._anims[a]:!1},refreshFrame:function(){this.sprite.currentFrame=this.currentFrame,this.sprite.setTexture(c.TextureCache[this.currentFrame.uuid])},destroy:function(){this._anims={},this._frameData=null,this._frameIndex=0,this.currentAnim=null,this.currentFrame=null}},Object.defineProperty(d.AnimationManager.prototype,"frameData",{get:function(){return this._frameData}}),Object.defineProperty(d.AnimationManager.prototype,"frameTotal",{get:function(){return this._frameData?this._frameData.total:-1}}),Object.defineProperty(d.AnimationManager.prototype,"paused",{get:function(){return this.currentAnim.isPaused},set:function(a){this.currentAnim.paused=a}}),Object.defineProperty(d.AnimationManager.prototype,"frame",{get:function(){return this.currentFrame?this._frameIndex:void 0},set:function(a){"number"==typeof a&&this._frameData&&null!==this._frameData.getFrame(a)&&(this.currentFrame=this._frameData.getFrame(a),this._frameIndex=a,this.sprite.currentFrame=this.currentFrame,this.sprite.setTexture(c.TextureCache[this.currentFrame.uuid]))}}),Object.defineProperty(d.AnimationManager.prototype,"frameName",{get:function(){return this.currentFrame?this.currentFrame.name:void 0},set:function(a){"string"==typeof a&&this._frameData&&null!==this._frameData.getFrameByName(a)?(this.currentFrame=this._frameData.getFrameByName(a),this._frameIndex=this.currentFrame.index,this.sprite.currentFrame=this.currentFrame,this.sprite.setTexture(c.TextureCache[this.currentFrame.uuid])):console.warn("Cannot set frameName: "+a)}}),d.Animation=function(a,b,c,d,e,f,g){this.game=a,this._parent=b,this._frameData=d,this.name=c,this._frames=[],this._frames=this._frames.concat(e),this.delay=1e3/f,this.looped=g,this.killOnComplete=!1,this.isFinished=!1,this.isPlaying=!1,this.isPaused=!1,this._pauseStartTime=0,this._frameIndex=0,this._frameDiff=0,this._frameSkip=1,this.currentFrame=this._frameData.getFrame(this._frames[this._frameIndex])},d.Animation.prototype={play:function(a,b,d){return"number"==typeof a&&(this.delay=1e3/a),"boolean"==typeof b&&(this.looped=b),"undefined"!=typeof d&&(this.killOnComplete=d),this.isPlaying=!0,this.isFinished=!1,this.paused=!1,this._timeLastFrame=this.game.time.now,this._timeNextFrame=this.game.time.now+this.delay,this._frameIndex=0,this.currentFrame=this._frameData.getFrame(this._frames[this._frameIndex]),this._parent.setTexture(c.TextureCache[this.currentFrame.uuid]),this._parent.events&&this._parent.events.onAnimationStart.dispatch(this._parent,this),this},restart:function(){this.isPlaying=!0,this.isFinished=!1,this.paused=!1,this._timeLastFrame=this.game.time.now,this._timeNextFrame=this.game.time.now+this.delay,this._frameIndex=0,this.currentFrame=this._frameData.getFrame(this._frames[this._frameIndex])},stop:function(a){"undefined"==typeof a&&(a=!1),this.isPlaying=!1,this.isFinished=!0,this.paused=!1,a&&(this.currentFrame=this._frameData.getFrame(this._frames[0]))},update:function(){return this.isPaused?!1:this.isPlaying===!0&&this.game.time.now>=this._timeNextFrame?(this._frameSkip=1,this._frameDiff=this.game.time.now-this._timeNextFrame,this._timeLastFrame=this.game.time.now,this._frameDiff>this.delay&&(this._frameSkip=Math.floor(this._frameDiff/this.delay),this._frameDiff-=this._frameSkip*this.delay),this._timeNextFrame=this.game.time.now+(this.delay-this._frameDiff),this._frameIndex+=this._frameSkip,this._frameIndex>=this._frames.length?this.looped?(this._frameIndex%=this._frames.length,this.currentFrame=this._frameData.getFrame(this._frames[this._frameIndex]),this.currentFrame&&this._parent.setTexture(c.TextureCache[this.currentFrame.uuid]),this._parent.events.onAnimationLoop.dispatch(this._parent,this)):this.onComplete():(this.currentFrame=this._frameData.getFrame(this._frames[this._frameIndex]),this.currentFrame&&this._parent.setTexture(c.TextureCache[this.currentFrame.uuid])),!0):!1},destroy:function(){this.game=null,this._parent=null,this._frames=null,this._frameData=null,this.currentFrame=null,this.isPlaying=!1},onComplete:function(){this.isPlaying=!1,this.isFinished=!0,this.paused=!1,this._parent.events&&this._parent.events.onAnimationComplete.dispatch(this._parent,this),this.killOnComplete&&this._parent.kill()}},Object.defineProperty(d.Animation.prototype,"paused",{get:function(){return this.isPaused},set:function(a){this.isPaused=a,a?this._pauseStartTime=this.game.time.now:this.isPlaying&&(this._timeNextFrame=this.game.time.now+this.delay)}}),Object.defineProperty(d.Animation.prototype,"frameTotal",{get:function(){return this._frames.length}}),Object.defineProperty(d.Animation.prototype,"frame",{get:function(){return null!==this.currentFrame?this.currentFrame.index:this._frameIndex},set:function(a){this.currentFrame=this._frameData.getFrame(a),null!==this.currentFrame&&(this._frameIndex=a,this._parent.setTexture(c.TextureCache[this.currentFrame.uuid]))}}),d.Animation.generateFrameNames=function(a,b,c,e,f){"undefined"==typeof e&&(e="");var g=[],h="";if(c>b)for(var i=b;c>=i;i++)h="number"==typeof f?d.Utils.pad(i.toString(),f,"0",1):i.toString(),h=a+h+e,g.push(h);else for(var i=b;i>=c;i--)h="number"==typeof f?d.Utils.pad(i.toString(),f,"0",1):i.toString(),h=a+h+e,g.push(h);return g},d.Frame=function(a,b,c,e,f,g,h){this.index=a,this.x=b,this.y=c,this.width=e,this.height=f,this.name=g,this.uuid=h,this.centerX=Math.floor(e/2),this.centerY=Math.floor(f/2),this.distance=d.Math.distance(0,0,e,f),this.rotated=!1,this.rotationDirection="cw",this.trimmed=!1,this.sourceSizeW=e,this.sourceSizeH=f,this.spriteSourceSizeX=0,this.spriteSourceSizeY=0,this.spriteSourceSizeW=0,this.spriteSourceSizeH=0},d.Frame.prototype={setTrim:function(a,b,c,d,e,f,g){this.trimmed=a,a&&(this.width=b,this.height=c,this.sourceSizeW=b,this.sourceSizeH=c,this.centerX=Math.floor(b/2),this.centerY=Math.floor(c/2),this.spriteSourceSizeX=d,this.spriteSourceSizeY=e,this.spriteSourceSizeW=f,this.spriteSourceSizeH=g)}},d.FrameData=function(){this._frames=[],this._frameNames=[]},d.FrameData.prototype={addFrame:function(a){return a.index=this._frames.length,this._frames.push(a),""!==a.name&&(this._frameNames[a.name]=a.index),a},getFrame:function(a){return this._frames.length>a?this._frames[a]:null},getFrameByName:function(a){return"number"==typeof this._frameNames[a]?this._frames[this._frameNames[a]]:null},checkFrameName:function(a){return null==this._frameNames[a]?!1:!0},getFrameRange:function(a,b,c){"undefined"==typeof c&&(c=[]);for(var d=a;b>=d;d++)c.push(this._frames[d]);return c},getFrames:function(a,b,c){if("undefined"==typeof b&&(b=!0),"undefined"==typeof c&&(c=[]),"undefined"==typeof a||0===a.length)for(var d=0;dd;d++)b?c.push(this.getFrame(a[d])):c.push(this.getFrameByName(a[d]));return c},getFrameIndexes:function(a,b,c){if("undefined"==typeof b&&(b=!0),"undefined"==typeof c&&(c=[]),"undefined"==typeof a||0===a.length)for(var d=0,e=this._frames.length;e>d;d++)c.push(this._frames[d].index);else for(var d=0,e=a.length;e>d;d++)b?c.push(a[d]):this.getFrameByName(a[d])&&c.push(this.getFrameByName(a[d]).index);return c}},Object.defineProperty(d.FrameData.prototype,"total",{get:function(){return this._frames.length}}),d.AnimationParser={spriteSheet:function(a,b,e,f,g){var h=a.cache.getImage(b);if(null==h)return null;var i=h.width,j=h.height;0>=e&&(e=Math.floor(-i/Math.min(-1,e))),0>=f&&(f=Math.floor(-j/Math.min(-1,f)));var k=Math.round(i/e),l=Math.round(j/f),m=k*l;if(-1!==g&&(m=g),0===i||0===j||e>i||f>j||0===m)return console.warn("Phaser.AnimationParser.spriteSheet: width/height zero or width/height < given frameWidth/frameHeight"),null;for(var n=new d.FrameData,o=0,p=0,q=0;m>q;q++){var r=a.rnd.uuid();n.addFrame(new d.Frame(q,o,p,e,f,"",r)),c.TextureCache[r]=new c.Texture(c.BaseTextureCache[b],{x:o,y:p,width:e,height:f}),o+=e,o===i&&(o=0,p+=f)}return n},JSONData:function(a,b,e){if(!b.frames)return console.warn("Phaser.AnimationParser.JSONData: Invalid Texture Atlas JSON given, missing 'frames' array"),console.log(b),void 0;for(var f,g=new d.FrameData,h=b.frames,i=0;i tag"),void 0;for(var f,g,h,i,j,k,l,m,n,o,p,q,r=new d.FrameData,s=b.getElementsByTagName("SubTexture"),t=0;t0)for(var c=0;c0)for(var c=0;c0?(this._fileIndex=0,this._progressChunk=100/this._fileList.length,this.loadFile()):(this.progress=100,this.hasLoaded=!0,this.onLoadComplete.dispatch()))},loadFile:function(){if(!this._fileList[this._fileIndex])return console.warn("Phaser.Loader loadFile invalid index "+this._fileIndex),void 0;var a=this._fileList[this._fileIndex],b=this;switch(a.type){case"image":case"spritesheet":case"textureatlas":case"bitmapfont":case"tileset":a.data=new Image,a.data.name=a.key,a.data.onload=function(){return b.fileComplete(b._fileIndex)},a.data.onerror=function(){return b.fileError(b._fileIndex)},a.data.crossOrigin=this.crossOrigin,a.data.src=this.baseURL+a.url;break;case"audio":a.url=this.getAudioURL(a.url),null!==a.url?this.game.sound.usingWebAudio?(this._xhr.open("GET",this.baseURL+a.url,!0),this._xhr.responseType="arraybuffer",this._xhr.onload=function(){return b.fileComplete(b._fileIndex)},this._xhr.onerror=function(){return b.fileError(b._fileIndex)},this._xhr.send()):this.game.sound.usingAudioTag&&(this.game.sound.touchLocked?(a.data=new Audio,a.data.name=a.key,a.data.preload="auto",a.data.src=this.baseURL+a.url,this.fileComplete(this._fileIndex)):(a.data=new Audio,a.data.name=a.key,a.data.onerror=function(){return b.fileError(b._fileIndex)},a.data.preload="auto",a.data.src=this.baseURL+a.url,a.data.addEventListener("canplaythrough",d.GAMES[this.game.id].load.fileComplete(this._fileIndex),!1),a.data.load())):this.fileError(this._fileIndex);break;case"tilemap":if(this._xhr.open("GET",this.baseURL+a.url,!0),this._xhr.responseType="text",a.format===d.Tilemap.TILED_JSON)this._xhr.onload=function(){return b.jsonLoadComplete(b._fileIndex)};else{if(a.format!==d.Tilemap.CSV)throw new Error("Phaser.Loader. Invalid Tilemap format: "+a.format);this._xhr.onload=function(){return b.csvLoadComplete(b._fileIndex)}}this._xhr.onerror=function(){return b.dataLoadError(b._fileIndex)},this._xhr.send();break;case"text":this._xhr.open("GET",this.baseURL+a.url,!0),this._xhr.responseType="text",this._xhr.onload=function(){return b.fileComplete(b._fileIndex)},this._xhr.onerror=function(){return b.fileError(b._fileIndex)},this._xhr.send();break;case"script":this._xhr.open("GET",this.baseURL+a.url,!0),this._xhr.responseType="text",this._xhr.onload=function(){return b.fileComplete(b._fileIndex)},this._xhr.onerror=function(){return b.fileError(b._fileIndex)},this._xhr.send()}},getAudioURL:function(a){var b;"string"==typeof a&&(a=[a]);for(var c=0;c100&&(this.progress=100),null!==this.preloadSprite&&(0===this.preloadSprite.direction?this.preloadSprite.crop.width=Math.floor(this.preloadSprite.width/100*this.progress):this.preloadSprite.crop.height=Math.floor(this.preloadSprite.height/100*this.progress),this.preloadSprite.sprite.crop=this.preloadSprite.crop),this.onFileComplete.dispatch(this.progress,this._fileList[a].key,b,this.totalLoadedFiles(),this._fileList.length),this.totalQueuedFiles()>0?(this._fileIndex++,this.loadFile()):(this.hasLoaded=!0,this.isLoading=!1,this.removeAll(),this.onLoadComplete.dispatch())},totalLoadedFiles:function(){for(var a=0,b=0;b tag"),void 0;var e=c.TextureCache[d],f={},g=b.getElementsByTagName("info")[0],h=b.getElementsByTagName("common")[0];f.font=g.attributes.getNamedItem("face").nodeValue,f.size=parseInt(g.attributes.getNamedItem("size").nodeValue,10),f.lineHeight=parseInt(h.attributes.getNamedItem("lineHeight").nodeValue,10),f.chars={};for(var i=b.getElementsByTagName("char"),j=0;j=this.durationMS&&(this.usingWebAudio?this.loop?(this.onLoop.dispatch(this),""===this.currentMarker?(this.currentTime=0,this.startTime=this.game.time.now):this.play(this.currentMarker,0,this.volume,!0,!0)):this.stop():this.loop?(this.onLoop.dispatch(this),this.play(this.currentMarker,0,this.volume,!0,!0)):this.stop()))},play:function(a,b,c,d,e){if(a=a||"",b=b||0,"undefined"==typeof c&&(c=this._volume),"undefined"==typeof d&&(d=!1),"undefined"==typeof e&&(e=!0),this.isPlaying!==!0||e!==!1||this.override!==!1){if(this.isPlaying&&this.override&&(this.usingWebAudio?"undefined"==typeof this._sound.stop?this._sound.noteOff(0):this._sound.stop(0):this.usingAudioTag&&(this._sound.pause(),this._sound.currentTime=0)),this.currentMarker=a,""!==a){if(!this.markers[a])return console.warn("Phaser.Sound.play: audio marker "+a+" doesn't exist"),void 0;this.position=this.markers[a].start,this.volume=this.markers[a].volume,this.loop=this.markers[a].loop,this.duration=this.markers[a].duration,this.durationMS=this.markers[a].durationMS,this._tempMarker=a,this._tempPosition=this.position,this._tempVolume=this.volume,this._tempLoop=this.loop}else this.position=b,this.volume=c,this.loop=d,this.duration=0,this.durationMS=0,this._tempMarker=a,this._tempPosition=b,this._tempVolume=c,this._tempLoop=d;this.usingWebAudio?this.game.cache.isSoundDecoded(this.key)?(null==this._buffer&&(this._buffer=this.game.cache.getSoundData(this.key)),this._sound=this.context.createBufferSource(),this._sound.buffer=this._buffer,this.externalNode?this._sound.connect(this.externalNode.input):this._sound.connect(this.gainNode),this.totalDuration=this._sound.buffer.duration,0===this.duration&&(this.duration=this.totalDuration,this.durationMS=1e3*this.totalDuration),this.loop&&""===a&&(this._sound.loop=!0),"undefined"==typeof this._sound.start?this._sound.noteGrainOn(0,this.position,this.duration):this._sound.start(0,this.position,this.duration),this.isPlaying=!0,this.startTime=this.game.time.now,this.currentTime=0,this.stopTime=this.startTime+this.durationMS,this.onPlay.dispatch(this)):(this.pendingPlayback=!0,this.game.cache.getSound(this.key)&&this.game.cache.getSound(this.key).isDecoding===!1&&this.game.sound.decode(this.key,this)):this.game.cache.getSound(this.key)&&this.game.cache.getSound(this.key).locked?(this.game.cache.reloadSound(this.key),this.pendingPlayback=!0):this._sound&&4==this._sound.readyState?(this._sound.play(),this.totalDuration=this._sound.duration,0===this.duration&&(this.duration=this.totalDuration,this.durationMS=1e3*this.totalDuration),this._sound.currentTime=this.position,this._sound.muted=this._muted,this._sound.volume=this._muted?0:this._volume,this.isPlaying=!0,this.startTime=this.game.time.now,this.currentTime=0,this.stopTime=this.startTime+this.durationMS,this.onPlay.dispatch(this)):this.pendingPlayback=!0}},restart:function(a,b,c,d){a=a||"",b=b||0,c=c||1,"undefined"==typeof d&&(d=!1),this.play(a,b,c,d,!0)},pause:function(){this.isPlaying&&this._sound&&(this.stop(),this.isPlaying=!1,this.paused=!0,this.pausedPosition=this.currentTime,this.pausedTime=this.game.time.now,this.onPause.dispatch(this))},resume:function(){if(this.paused&&this._sound){if(this.usingWebAudio){var a=this.position+this.pausedPosition/1e3;this._sound=this.context.createBufferSource(),this._sound.buffer=this._buffer,this._sound.connect(this.gainNode),"undefined"==typeof this._sound.start?this._sound.noteGrainOn(0,a,this.duration):this._sound.start(0,a,this.duration)}else this._sound.play();this.isPlaying=!0,this.paused=!1,this.startTime+=this.game.time.now-this.pausedTime,this.onResume.dispatch(this)}},stop:function(){this.isPlaying&&this._sound&&(this.usingWebAudio?"undefined"==typeof this._sound.stop?this._sound.noteOff(0):this._sound.stop(0):this.usingAudioTag&&(this._sound.pause(),this._sound.currentTime=0)),this.isPlaying=!1;var a=this.currentMarker;this.currentMarker="",this.onStop.dispatch(this,a)}},Object.defineProperty(d.Sound.prototype,"isDecoding",{get:function(){return this.game.cache.getSound(this.key).isDecoding}}),Object.defineProperty(d.Sound.prototype,"isDecoded",{get:function(){return this.game.cache.isSoundDecoded(this.key)}}),Object.defineProperty(d.Sound.prototype,"mute",{get:function(){return this._muted},set:function(a){a=a||null,a?(this._muted=!0,this.usingWebAudio?(this._muteVolume=this.gainNode.gain.value,this.gainNode.gain.value=0):this.usingAudioTag&&this._sound&&(this._muteVolume=this._sound.volume,this._sound.volume=0)):(this._muted=!1,this.usingWebAudio?this.gainNode.gain.value=this._muteVolume:this.usingAudioTag&&this._sound&&(this._sound.volume=this._muteVolume)),this.onMute.dispatch(this)}}),Object.defineProperty(d.Sound.prototype,"volume",{get:function(){return this._volume},set:function(a){this.usingWebAudio?(this._volume=a,this.gainNode.gain.value=a):this.usingAudioTag&&this._sound&&a>=0&&1>=a&&(this._volume=a,this._sound.volume=a)}}),d.SoundManager=function(a){this.game=a,this.onSoundDecode=new d.Signal,this._muted=!1,this._unlockSource=null,this._volume=1,this._sounds=[],this.context=null,this.usingWebAudio=!0,this.usingAudioTag=!1,this.noAudio=!1,this.connectToMaster=!0,this.touchLocked=!1,this.channels=32},d.SoundManager.prototype={boot:function(){if(this.game.device.iOS&&this.game.device.webAudio===!1&&(this.channels=1),this.game.device.iOS||window.PhaserGlobal&&window.PhaserGlobal.fakeiOSTouchLock?(this.game.input.touch.callbackContext=this,this.game.input.touch.touchStartCallback=this.unlock,this.game.input.mouse.callbackContext=this,this.game.input.mouse.mouseDownCallback=this.unlock,this.touchLocked=!0):this.touchLocked=!1,window.PhaserGlobal){if(window.PhaserGlobal.disableAudio===!0)return this.usingWebAudio=!1,this.noAudio=!0,void 0;if(window.PhaserGlobal.disableWebAudio===!0)return this.usingWebAudio=!1,this.usingAudioTag=!0,this.noAudio=!1,void 0}window.AudioContext?this.context=new window.AudioContext:window.webkitAudioContext?this.context=new window.webkitAudioContext:window.Audio?(this.usingWebAudio=!1,this.usingAudioTag=!0):(this.usingWebAudio=!1,this.noAudio=!0),null!==this.context&&(this.masterGain="undefined"==typeof this.context.createGain?this.context.createGainNode():this.context.createGain(),this.masterGain.gain.value=1,this.masterGain.connect(this.context.destination))},unlock:function(){if(this.touchLocked!==!1)if(this.game.device.webAudio===!1||window.PhaserGlobal&&window.PhaserGlobal.disableWebAudio===!0)this.touchLocked=!1,this._unlockSource=null,this.game.input.touch.callbackContext=null,this.game.input.touch.touchStartCallback=null,this.game.input.mouse.callbackContext=null,this.game.input.mouse.mouseDownCallback=null;else{var a=this.context.createBuffer(1,1,22050);this._unlockSource=this.context.createBufferSource(),this._unlockSource.buffer=a,this._unlockSource.connect(this.context.destination),this._unlockSource.noteOn(0)}},stopAll:function(){for(var a=0;a255)return d.Color.getColor(255,255,255);if(a>b)return d.Color.getColor(255,255,255);var e=a+Math.round(Math.random()*(b-a)),f=a+Math.round(Math.random()*(b-a)),g=a+Math.round(Math.random()*(b-a));return d.Color.getColor32(c,e,f,g)},getRGB:function(a){return{alpha:a>>>24,red:255&a>>16,green:255&a>>8,blue:255&a}},getWebRGB:function(a){var b=(a>>>24)/255,c=255&a>>16,d=255&a>>8,e=255&a;return"rgba("+c.toString()+","+d.toString()+","+e.toString()+","+b.toString()+")"},getAlpha:function(a){return a>>>24},getAlphaFloat:function(a){return(a>>>24)/255},getRed:function(a){return 255&a>>16},getGreen:function(a){return 255&a>>8},getBlue:function(a){return 255&a}},d.Physics={},d.Physics.Arcade=function(a){this.game=a,this.gravity=new d.Point,this.bounds=new d.Rectangle(0,0,a.world.width,a.world.height),this.maxObjects=10,this.maxLevels=4,this.OVERLAP_BIAS=4,this.quadTree=new d.QuadTree(this,this.game.world.bounds.x,this.game.world.bounds.y,this.game.world.bounds.width,this.game.world.bounds.height,this.maxObjects,this.maxLevels),this.quadTreeID=0,this._bounds1=new d.Rectangle,this._bounds2=new d.Rectangle,this._overlap=0,this._maxOverlap=0,this._velocity1=0,this._velocity2=0,this._newVelocity1=0,this._newVelocity2=0,this._average=0,this._mapData=[],this._mapTiles=0,this._result=!1,this._total=0,this._angle=0,this._dx=0,this._dy=0},d.Physics.Arcade.prototype={updateMotion:function(a){this._velocityDelta=60*.5*(this.computeVelocity(0,a,a.angularVelocity,a.angularAcceleration,a.angularDrag,a.maxAngular)-a.angularVelocity)*this.game.time.physicsElapsed,a.angularVelocity+=this._velocityDelta,a.rotation+=a.angularVelocity*this.game.time.physicsElapsed,a.angularVelocity+=this._velocityDelta,this._velocityDelta=60*.5*(this.computeVelocity(1,a,a.velocity.x,a.acceleration.x,a.drag.x,a.maxVelocity.x)-a.velocity.x)*this.game.time.physicsElapsed,a.velocity.x+=this._velocityDelta,a.x+=a.velocity.x*this.game.time.physicsElapsed,a.velocity.x+=this._velocityDelta,this._velocityDelta=60*.5*(this.computeVelocity(2,a,a.velocity.y,a.acceleration.y,a.drag.y,a.maxVelocity.y)-a.velocity.y)*this.game.time.physicsElapsed,a.velocity.y+=this._velocityDelta,a.y+=a.velocity.y*this.game.time.physicsElapsed,a.velocity.y+=this._velocityDelta},computeVelocity:function(a,b,c,d,e,f){return f=f||1e4,1==a&&b.allowGravity?c+=this.gravity.x+b.gravity.x:2==a&&b.allowGravity&&(c+=this.gravity.y+b.gravity.y),0!==d?c+=d*this.game.time.physicsElapsed:0!==e&&(this._drag=e*this.game.time.physicsElapsed,c-this._drag>0?c-=this._drag:c+this._drag<0?c+=this._drag:c=0),c>f?c=f:-f>c&&(c=-f),c},preUpdate:function(){this.quadTree.clear(),this.quadTreeID=0,this.quadTree=new d.QuadTree(this,this.game.world.bounds.x,this.game.world.bounds.y,this.game.world.bounds.width,this.game.world.bounds.height,this.maxObjects,this.maxLevels)},postUpdate:function(){this.quadTree.clear()},overlap:function(a,b,c,e,f){return c=c||null,e=e||null,f=f||c,this._result=!1,this._total=0,a&&b&&a.exists&&b.exists&&(a.type==d.SPRITE?b.type==d.SPRITE?this.overlapSpriteVsSprite(a,b,c,e,f):(b.type==d.GROUP||b.type==d.EMITTER)&&this.overlapSpriteVsGroup(a,b,c,e,f):a.type==d.GROUP?b.type==d.SPRITE?this.overlapSpriteVsGroup(b,a,c,e,f):(b.type==d.GROUP||b.type==d.EMITTER)&&this.overlapGroupVsGroup(a,b,c,e,f):a.type==d.EMITTER&&(b.type==d.SPRITE?this.overlapSpriteVsGroup(b,a,c,e,f):(b.type==d.GROUP||b.type==d.EMITTER)&&this.overlapGroupVsGroup(a,b,c,e,f))),this._total>0},overlapSpriteVsSprite:function(a,b,c,e,f){this._result=d.Rectangle.intersects(a.body,b.body),this._result&&(e?e.call(f,a,b)&&(this._total++,c&&c.call(f,a,b)):(this._total++,c&&c.call(f,a,b)))},overlapSpriteVsGroup:function(a,b,c,e,f){if(0!==b.length){this._potentials=this.quadTree.retrieve(a);for(var g=0,h=this._potentials.length;h>g;g++)this._potentials[g].sprite.group==b&&(this._result=d.Rectangle.intersects(a.body,this._potentials[g]),this._result&&e&&(this._result=e.call(f,a,this._potentials[g].sprite)),this._result&&(this._total++,c&&c.call(f,a,this._potentials[g].sprite)))}},overlapGroupVsGroup:function(a,b,c,d,e){if(0!==a.length&&0!==b.length&&a._container.first._iNext){var f=a._container.first._iNext;do f.exists&&this.overlapSpriteVsGroup(f,b,c,d,e),f=f._iNext;while(f!=a._container.last._iNext)}},collide:function(a,b,c,e,f){return c=c||null,e=e||null,f=f||c,this._result=!1,this._total=0,a&&b&&a.exists&&b.exists&&(a.type==d.SPRITE?b.type==d.SPRITE?this.collideSpriteVsSprite(a,b,c,e,f):b.type==d.GROUP||b.type==d.EMITTER?this.collideSpriteVsGroup(a,b,c,e,f):b.type==d.TILEMAPLAYER&&this.collideSpriteVsTilemapLayer(a,b,c,e,f):a.type==d.GROUP?b.type==d.SPRITE?this.collideSpriteVsGroup(b,a,c,e,f):b.type==d.GROUP||b.type==d.EMITTER?this.collideGroupVsGroup(a,b,c,e,f):b.type==d.TILEMAPLAYER&&this.collideGroupVsTilemapLayer(a,b,c,e,f):a.type==d.TILEMAPLAYER?b.type==d.SPRITE?this.collideSpriteVsTilemapLayer(b,a,c,e,f):(b.type==d.GROUP||b.type==d.EMITTER)&&this.collideGroupVsTilemapLayer(b,a,c,e,f):a.type==d.EMITTER&&(b.type==d.SPRITE?this.collideSpriteVsGroup(b,a,c,e,f):b.type==d.GROUP||b.type==d.EMITTER?this.collideGroupVsGroup(a,b,c,e,f):b.type==d.TILEMAPLAYER&&this.collideGroupVsTilemapLayer(a,b,c,e,f))),this._total>0},collideSpriteVsTilemapLayer:function(a,b,c,d,e){if(this._mapData=b.getTiles(a.body.x,a.body.y,a.body.width,a.body.height,!0),0!==this._mapData.length)for(var f=0;ff;f++)this._potentials[f].sprite.group==b&&(this.separate(a.body,this._potentials[f]),this._result&&d&&(this._result=d.call(e,a,this._potentials[f].sprite)),this._result&&(this._total++,c&&c.call(e,a,this._potentials[f].sprite)))}},collideGroupVsGroup:function(a,b,c,d,e){if(0!==a.length&&0!==b.length&&a._container.first._iNext){var f=a._container.first._iNext;do f.exists&&this.collideSpriteVsGroup(f,b,c,d,e),f=f._iNext;while(f!=a._container.last._iNext)}},separate:function(a,b){this._result=this.separateX(a,b)||this.separateY(a,b)},separateX:function(a,b){return a.immovable&&b.immovable?!1:(this._overlap=0,d.Rectangle.intersects(a,b)&&(this._maxOverlap=a.deltaAbsX()+b.deltaAbsX()+this.OVERLAP_BIAS,0===a.deltaX()&&0===b.deltaX()?(a.embedded=!0,b.embedded=!0):a.deltaX()>b.deltaX()?(this._overlap=a.x+a.width-b.x,this._overlap>this._maxOverlap||a.allowCollision.right===!1||b.allowCollision.left===!1?this._overlap=0:(a.touching.right=!0,b.touching.left=!0)):a.deltaX()this._maxOverlap||a.allowCollision.left===!1||b.allowCollision.right===!1?this._overlap=0:(a.touching.left=!0,b.touching.right=!0)),0!==this._overlap)?(a.overlapX=this._overlap,b.overlapX=this._overlap,a.customSeparateX||b.customSeparateX?!0:(this._velocity1=a.velocity.x,this._velocity2=b.velocity.x,a.immovable||b.immovable?a.immovable?b.immovable||(b.x+=this._overlap,b.velocity.x=this._velocity1-this._velocity2*b.bounce.x):(a.x=a.x-this._overlap,a.velocity.x=this._velocity2-this._velocity1*a.bounce.x):(this._overlap*=.5,a.x=a.x-this._overlap,b.x+=this._overlap,this._newVelocity1=Math.sqrt(this._velocity2*this._velocity2*b.mass/a.mass)*(this._velocity2>0?1:-1),this._newVelocity2=Math.sqrt(this._velocity1*this._velocity1*a.mass/b.mass)*(this._velocity1>0?1:-1),this._average=.5*(this._newVelocity1+this._newVelocity2),this._newVelocity1-=this._average,this._newVelocity2-=this._average,a.velocity.x=this._average+this._newVelocity1*a.bounce.x,b.velocity.x=this._average+this._newVelocity2*b.bounce.x),a.updateHulls(),b.updateHulls(),!0)):!1)},separateY:function(a,b){return a.immovable&&b.immovable?!1:(this._overlap=0,d.Rectangle.intersects(a,b)&&(this._maxOverlap=a.deltaAbsY()+b.deltaAbsY()+this.OVERLAP_BIAS,0===a.deltaY()&&0===b.deltaY()?(a.embedded=!0,b.embedded=!0):a.deltaY()>b.deltaY()?(this._overlap=a.y+a.height-b.y,this._overlap>this._maxOverlap||a.allowCollision.down===!1||b.allowCollision.up===!1?this._overlap=0:(a.touching.down=!0,b.touching.up=!0)):a.deltaY()this._maxOverlap||a.allowCollision.up===!1||b.allowCollision.down===!1?this._overlap=0:(a.touching.up=!0,b.touching.down=!0)),0!==this._overlap)?(a.overlapY=this._overlap,b.overlapY=this._overlap,a.customSeparateY||b.customSeparateY?!0:(this._velocity1=a.velocity.y,this._velocity2=b.velocity.y,a.immovable||b.immovable?a.immovable?b.immovable||(b.y+=this._overlap,b.velocity.y=this._velocity1-this._velocity2*b.bounce.y,a.sprite.active&&a.moves&&a.deltaY()b.deltaY()&&(a.x+=b.x-b.lastX)):(this._overlap*=.5,a.y=a.y-this._overlap,b.y+=this._overlap,this._newVelocity1=Math.sqrt(this._velocity2*this._velocity2*b.mass/a.mass)*(this._velocity2>0?1:-1),this._newVelocity2=Math.sqrt(this._velocity1*this._velocity1*a.mass/b.mass)*(this._velocity1>0?1:-1),this._average=.5*(this._newVelocity1+this._newVelocity2),this._newVelocity1-=this._average,this._newVelocity2-=this._average,a.velocity.y=this._average+this._newVelocity1*a.bounce.y,b.velocity.y=this._average+this._newVelocity2*b.bounce.y),a.updateHulls(),b.updateHulls(),!0)):!1)},separateTile:function(a,b){return this._result=this.separateTileX(a,b,!0)||this.separateTileY(a,b,!0),this._result},separateTileX:function(a,b,c){return a.immovable||0===a.deltaX()||d.Rectangle.intersects(a.hullX,b)===!1?!1:(this._overlap=0,a.deltaX()<0?(this._overlap=b.right-a.hullX.x,a.allowCollision.left===!1||b.tile.collideRight===!1?this._overlap=0:a.touching.left=!0):(this._overlap=a.hullX.right-b.x,a.allowCollision.right===!1||b.tile.collideLeft===!1?this._overlap=0:a.touching.right=!0),0!==this._overlap?(c&&(a.x=a.deltaX()<0?a.x+this._overlap:a.x-this._overlap,a.velocity.x=0===a.bounce.x?0:-a.velocity.x*a.bounce.x,a.updateHulls()),!0):!1)},separateTileY:function(a,b,c){return a.immovable||0===a.deltaY()||d.Rectangle.intersects(a.hullY,b)===!1?!1:(this._overlap=0,a.deltaY()<0?(this._overlap=b.bottom-a.hullY.y,a.allowCollision.up===!1||b.tile.collideDown===!1?this._overlap=0:a.touching.up=!0):(this._overlap=a.hullY.bottom-b.y,a.allowCollision.down===!1||b.tile.collideUp===!1?this._overlap=0:a.touching.down=!0),0!==this._overlap?(c&&(a.y=a.deltaY()<0?a.y+this._overlap:a.y-this._overlap,a.velocity.y=0===a.bounce.y?0:-a.velocity.y*a.bounce.y,a.updateHulls()),!0):!1)},moveToObject:function(a,b,c,d){return"undefined"==typeof c&&(c=60),"undefined"==typeof d&&(d=0),this._angle=Math.atan2(b.y-a.y,b.x-a.x),d>0&&(c=this.distanceBetween(a,b)/(d/1e3)),a.body.velocity.x=Math.cos(this._angle)*c,a.body.velocity.y=Math.sin(this._angle)*c,this._angle},moveToPointer:function(a,b,c,d){return"undefined"==typeof b&&(b=60),c=c||this.game.input.activePointer,"undefined"==typeof d&&(d=0),this._angle=this.angleToPointer(a,c),d>0&&(b=this.distanceToPointer(a,c)/(d/1e3)),a.body.velocity.x=Math.cos(this._angle)*b,a.body.velocity.y=Math.sin(this._angle)*b,this._angle},moveToXY:function(a,b,c,d,e){return"undefined"==typeof d&&(d=60),"undefined"==typeof e&&(e=0),this._angle=Math.atan2(c-a.y,b-a.x),e>0&&(d=this.distanceToXY(a,b,c)/(e/1e3)),a.body.velocity.x=Math.cos(this._angle)*d,a.body.velocity.y=Math.sin(this._angle)*d,this._angle},velocityFromAngle:function(a,b,c){return"undefined"==typeof b&&(b=60),c=c||new d.Point,c.setTo(Math.cos(this.game.math.degToRad(a))*b,Math.sin(this.game.math.degToRad(a))*b)},velocityFromRotation:function(a,b,c){return"undefined"==typeof b&&(b=60),c=c||new d.Point,c.setTo(Math.cos(a)*b,Math.sin(a)*b)},accelerationFromRotation:function(a,b,c){return"undefined"==typeof b&&(b=60),c=c||new d.Point,c.setTo(Math.cos(a)*b,Math.sin(a)*b)},accelerateToObject:function(a,b,c,d,e){return"undefined"==typeof c&&(c=60),"undefined"==typeof d&&(d=1e3),"undefined"==typeof e&&(e=1e3),this._angle=this.angleBetween(a,b),a.body.acceleration.setTo(Math.cos(this._angle)*c,Math.sin(this._angle)*c),a.body.maxVelocity.setTo(d,e),this._angle},accelerateToPointer:function(a,b,c,d,e){return"undefined"==typeof c&&(c=60),"undefined"==typeof b&&(b=this.game.input.activePointer),"undefined"==typeof d&&(d=1e3),"undefined"==typeof e&&(e=1e3),this._angle=this.angleToPointer(a,b),a.body.acceleration.setTo(Math.cos(this._angle)*c,Math.sin(this._angle)*c),a.body.maxVelocity.setTo(d,e),this._angle},accelerateToXY:function(a,b,c,d,e,f){return"undefined"==typeof d&&(d=60),"undefined"==typeof e&&(e=1e3),"undefined"==typeof f&&(f=1e3),this._angle=this.angleToXY(a,b,c),a.body.acceleration.setTo(Math.cos(this._angle)*d,Math.sin(this._angle)*d),a.body.maxVelocity.setTo(e,f),this._angle},distanceBetween:function(a,b){return this._dx=a.x-b.x,this._dy=a.y-b.y,Math.sqrt(this._dx*this._dx+this._dy*this._dy)},distanceToXY:function(a,b,c){return this._dx=a.x-b,this._dy=a.y-c,Math.sqrt(this._dx*this._dx+this._dy*this._dy)},distanceToPointer:function(a,b){return b=b||this.game.input.activePointer,this._dx=a.x-b.x,this._dy=a.y-b.y,Math.sqrt(this._dx*this._dx+this._dy*this._dy)},angleBetween:function(a,b){return this._dx=b.x-a.x,this._dy=b.y-a.y,Math.atan2(this._dy,this._dx)},angleToXY:function(a,b,c){return this._dx=b-a.x,this._dy=c-a.y,Math.atan2(this._dy,this._dx)},angleToPointer:function(a,b){return b=b||this.game.input.activePointer,this._dx=b.worldX-a.x,this._dy=b.worldY-a.y,Math.atan2(this._dy,this._dx)}},d.Physics.Arcade.Body=function(a){this.sprite=a,this.game=a.game,this.offset=new d.Point,this.x=a.x,this.y=a.y,this.preX=a.x,this.preY=a.y,this.preRotation=a.angle,this.screenX=a.x,this.screenY=a.y,this.sourceWidth=a.currentFrame.sourceSizeW,this.sourceHeight=a.currentFrame.sourceSizeH,this.width=a.currentFrame.sourceSizeW,this.height=a.currentFrame.sourceSizeH,this.halfWidth=Math.floor(a.currentFrame.sourceSizeW/2),this.halfHeight=Math.floor(a.currentFrame.sourceSizeH/2),this.center=new d.Point(this.x+this.halfWidth,this.y+this.halfHeight),this._sx=a.scale.x,this._sy=a.scale.y,this.velocity=new d.Point,this.acceleration=new d.Point,this.drag=new d.Point,this.gravity=new d.Point,this.bounce=new d.Point,this.maxVelocity=new d.Point(1e4,1e4),this.angularVelocity=0,this.angularAcceleration=0,this.angularDrag=0,this.maxAngular=1e3,this.mass=1,this.skipQuadTree=!1,this.quadTreeIDs=[],this.quadTreeIndex=-1,this.allowCollision={none:!1,any:!0,up:!0,down:!0,left:!0,right:!0},this.touching={none:!0,up:!1,down:!1,left:!1,right:!1},this.wasTouching={none:!0,up:!1,down:!1,left:!1,right:!1},this.facing=d.NONE,this.immovable=!1,this.moves=!0,this.rotation=0,this.allowRotation=!0,this.allowGravity=!0,this.customSeparateX=!1,this.customSeparateY=!1,this.overlapX=0,this.overlapY=0,this.hullX=new d.Rectangle,this.hullY=new d.Rectangle,this.embedded=!1,this.collideWorldBounds=!1},d.Physics.Arcade.Body.prototype={updateBounds:function(a,b,c,d){(c!=this._sx||d!=this._sy)&&(this.width=this.sourceWidth*c,this.height=this.sourceHeight*d,this.halfWidth=Math.floor(this.width/2),this.halfHeight=Math.floor(this.height/2),this._sx=c,this._sy=d,this.center.setTo(this.x+this.halfWidth,this.y+this.halfHeight))},preUpdate:function(){this.wasTouching.none=this.touching.none,this.wasTouching.up=this.touching.up,this.wasTouching.down=this.touching.down,this.wasTouching.left=this.touching.left,this.wasTouching.right=this.touching.right,this.touching.none=!0,this.touching.up=!1,this.touching.down=!1,this.touching.left=!1,this.touching.right=!1,this.embedded=!1,this.screenX=this.sprite.worldTransform[2]-this.sprite.anchor.x*this.width+this.offset.x,this.screenY=this.sprite.worldTransform[5]-this.sprite.anchor.y*this.height+this.offset.y,this.preX=this.sprite.world.x-this.sprite.anchor.x*this.width+this.offset.x,this.preY=this.sprite.world.y-this.sprite.anchor.y*this.height+this.offset.y,this.preRotation=this.sprite.angle,this.x=this.preX,this.y=this.preY,this.rotation=this.preRotation,this.moves&&(this.game.physics.updateMotion(this),this.collideWorldBounds&&this.checkWorldBounds(),this.updateHulls()),this.skipQuadTree===!1&&this.allowCollision.none===!1&&this.sprite.visible&&this.sprite.alive&&(this.quadTreeIDs=[],this.quadTreeIndex=-1,this.game.physics.quadTree.insert(this))},postUpdate:function(){this.deltaX()<0?this.facing=d.LEFT:this.deltaX()>0&&(this.facing=d.RIGHT),this.deltaY()<0?this.facing=d.UP:this.deltaY()>0&&(this.facing=d.DOWN),(0!==this.deltaX()||0!==this.deltaY())&&(this.sprite.x+=this.deltaX(),this.sprite.y+=this.deltaY(),this.center.setTo(this.x+this.halfWidth,this.y+this.halfHeight)),this.allowRotation&&(this.sprite.angle+=this.deltaZ())},updateHulls:function(){this.hullX.setTo(this.x,this.preY,this.width,this.height),this.hullY.setTo(this.preX,this.y,this.width,this.height)},checkWorldBounds:function(){this.xthis.game.world.bounds.right&&(this.x=this.game.world.bounds.right-this.width,this.velocity.x*=-this.bounce.x),this.ythis.game.world.bounds.bottom&&(this.y=this.game.world.bounds.bottom-this.height,this.velocity.y*=-this.bounce.y)},setSize:function(a,b,c,d){c=c||this.offset.x,d=d||this.offset.y,this.sourceWidth=a,this.sourceHeight=b,this.width=this.sourceWidth*this._sx,this.height=this.sourceHeight*this._sy,this.halfWidth=Math.floor(this.width/2),this.halfHeight=Math.floor(this.height/2),this.offset.setTo(c,d),this.center.setTo(this.x+this.halfWidth,this.y+this.halfHeight)},reset:function(){this.velocity.setTo(0,0),this.acceleration.setTo(0,0),this.angularVelocity=0,this.angularAcceleration=0,this.preX=this.sprite.world.x-this.sprite.anchor.x*this.width+this.offset.x,this.preY=this.sprite.world.y-this.sprite.anchor.y*this.height+this.offset.y,this.preRotation=this.sprite.angle,this.x=this.preX,this.y=this.preY,this.rotation=this.preRotation,this.center.setTo(this.x+this.halfWidth,this.y+this.halfHeight)},deltaAbsX:function(){return this.deltaX()>0?this.deltaX():-this.deltaX()},deltaAbsY:function(){return this.deltaY()>0?this.deltaY():-this.deltaY()},deltaX:function(){return this.x-this.preX},deltaY:function(){return this.y-this.preY},deltaZ:function(){return this.rotation-this.preRotation}},Object.defineProperty(d.Physics.Arcade.Body.prototype,"bottom",{get:function(){return this.y+this.height},set:function(a){this.height=a<=this.y?0:this.y-a}}),Object.defineProperty(d.Physics.Arcade.Body.prototype,"right",{get:function(){return this.x+this.width},set:function(a){this.width=a<=this.x?0:this.x+a}}),d.Particles=function(a){this.game=a,this.emitters={},this.ID=0},d.Particles.prototype={add:function(a){return this.emitters[a.name]=a,a},remove:function(a){delete this.emitters[a.name]},update:function(){for(var a in this.emitters)this.emitters[a].exists&&this.emitters[a].update()}},d.Particles.Arcade={},d.Particles.Arcade.Emitter=function(a,b,c,e){this.maxParticles=e||50,d.Group.call(this,a),this.name="emitter"+this.game.particles.ID++,this.type=d.EMITTER,this.x=0,this.y=0,this.width=1,this.height=1,this.minParticleSpeed=new d.Point(-100,-100),this.maxParticleSpeed=new d.Point(100,100),this.minParticleScale=1,this.maxParticleScale=1,this.minRotation=-360,this.maxRotation=360,this.gravity=2,this.particleClass=null,this.particleDrag=new d.Point,this.angularDrag=0,this.frequency=100,this.lifespan=2e3,this.bounce=new d.Point,this._quantity=0,this._timer=0,this._counter=0,this._explode=!0,this.on=!1,this.exists=!0,this.emitX=b,this.emitY=c},d.Particles.Arcade.Emitter.prototype=Object.create(d.Group.prototype),d.Particles.Arcade.Emitter.prototype.constructor=d.Particles.Arcade.Emitter,d.Particles.Arcade.Emitter.prototype.update=function(){if(this.on)if(this._explode){this._counter=0;do this.emitParticle(),this._counter++;while(this._counter=this._timer&&(this.emitParticle(),this._counter++,this._quantity>0&&this._counter>=this._quantity&&(this.on=!1),this._timer=this.game.time.now+this.frequency)},d.Particles.Arcade.Emitter.prototype.makeParticles=function(a,b,c,e,f){"undefined"==typeof b&&(b=0),c=c||this.maxParticles,e=e||0,"undefined"==typeof f&&(f=!1);for(var g,h=0,i=a,j=0;c>h;)null==this.particleClass&&("object"==typeof a&&(i=this.game.rnd.pick(a)),"object"==typeof b&&(j=this.game.rnd.pick(b)),g=new d.Sprite(this.game,0,0,i,j)),e>0?(g.body.allowCollision.any=!0,g.body.allowCollision.none=!1):g.body.allowCollision.none=!0,g.body.collideWorldBounds=f,g.exists=!1,g.visible=!1,g.anchor.setTo(.5,.5),this.add(g),h++;return this},d.Particles.Arcade.Emitter.prototype.kill=function(){this.on=!1,this.alive=!1,this.exists=!1},d.Particles.Arcade.Emitter.prototype.revive=function(){this.alive=!0,this.exists=!0},d.Particles.Arcade.Emitter.prototype.start=function(a,b,c,d){"boolean"!=typeof a&&(a=!0),b=b||0,c=c||250,d=d||0,this.revive(),this.visible=!0,this.on=!0,this._explode=a,this.lifespan=b,this.frequency=c,a?this._quantity=d:this._quantity+=d,this._counter=0,this._timer=this.game.time.now+c},d.Particles.Arcade.Emitter.prototype.emitParticle=function(){var a=this.getFirstExists(!1);if(null!=a){if(this.width>1||this.height>1?a.reset(this.game.rnd.integerInRange(this.left,this.right),this.game.rnd.integerInRange(this.top,this.bottom)):a.reset(this.emitX,this.emitY),a.lifespan=this.lifespan,a.body.bounce.setTo(this.bounce.x,this.bounce.y),a.body.velocity.x=this.minParticleSpeed.x!=this.maxParticleSpeed.x?this.game.rnd.integerInRange(this.minParticleSpeed.x,this.maxParticleSpeed.x):this.minParticleSpeed.x,a.body.velocity.y=this.minParticleSpeed.y!=this.maxParticleSpeed.y?this.game.rnd.integerInRange(this.minParticleSpeed.y,this.maxParticleSpeed.y):this.minParticleSpeed.y,a.body.gravity.y=this.gravity,a.body.angularVelocity=this.minRotation!=this.maxRotation?this.game.rnd.integerInRange(this.minRotation,this.maxRotation):this.minRotation,1!==this.minParticleScale||1!==this.maxParticleScale){var b=this.game.rnd.realInRange(this.minParticleScale,this.maxParticleScale);a.scale.setTo(b,b)}a.body.drag.x=this.particleDrag.x,a.body.drag.y=this.particleDrag.y,a.body.angularDrag=this.angularDrag}},d.Particles.Arcade.Emitter.prototype.setSize=function(a,b){this.width=a,this.height=b},d.Particles.Arcade.Emitter.prototype.setXSpeed=function(a,b){a=a||0,b=b||0,this.minParticleSpeed.x=a,this.maxParticleSpeed.x=b},d.Particles.Arcade.Emitter.prototype.setYSpeed=function(a,b){a=a||0,b=b||0,this.minParticleSpeed.y=a,this.maxParticleSpeed.y=b},d.Particles.Arcade.Emitter.prototype.setRotation=function(a,b){a=a||0,b=b||0,this.minRotation=a,this.maxRotation=b},d.Particles.Arcade.Emitter.prototype.at=function(a){this.emitX=a.center.x,this.emitY=a.center.y},Object.defineProperty(d.Particles.Arcade.Emitter.prototype,"alpha",{get:function(){return this._container.alpha},set:function(a){this._container.alpha=a}}),Object.defineProperty(d.Particles.Arcade.Emitter.prototype,"visible",{get:function(){return this._container.visible},set:function(a){this._container.visible=a}}),Object.defineProperty(d.Particles.Arcade.Emitter.prototype,"x",{get:function(){return this.emitX},set:function(a){this.emitX=a}}),Object.defineProperty(d.Particles.Arcade.Emitter.prototype,"y",{get:function(){return this.emitY},set:function(a){this.emitY=a}}),Object.defineProperty(d.Particles.Arcade.Emitter.prototype,"left",{get:function(){return Math.floor(this.x-this.width/2)}}),Object.defineProperty(d.Particles.Arcade.Emitter.prototype,"right",{get:function(){return Math.floor(this.x+this.width/2)}}),Object.defineProperty(d.Particles.Arcade.Emitter.prototype,"top",{get:function(){return Math.floor(this.y-this.height/2)}}),Object.defineProperty(d.Particles.Arcade.Emitter.prototype,"bottom",{get:function(){return Math.floor(this.y+this.height/2)}}),d.Tile=function(a,b,c,d,e,f){this.tileset=a,this.index=b,this.width=e,this.height=f,this.x=c,this.y=d,this.mass=1,this.collideNone=!0,this.collideLeft=!1,this.collideRight=!1,this.collideUp=!1,this.collideDown=!1,this.separateX=!0,this.separateY=!0,this.collisionCallback=null,this.collisionCallbackContext=this},d.Tile.prototype={setCollisionCallback:function(a,b){this.collisionCallbackContext=b,this.collisionCallback=a},destroy:function(){this.tileset=null},setCollision:function(a,b,c,d){this.collideLeft=a,this.collideRight=b,this.collideUp=c,this.collideDown=d,this.collideNone=a||b||c||d?!1:!0},resetCollision:function(){this.collideNone=!0,this.collideLeft=!1,this.collideRight=!1,this.collideUp=!1,this.collideDown=!1}},Object.defineProperty(d.Tile.prototype,"bottom",{get:function(){return this.y+this.height}}),Object.defineProperty(d.Tile.prototype,"right",{get:function(){return this.x+this.width}}),d.Tilemap=function(a,b){this.game=a,this.layers=null,"string"==typeof b?(this.key=b,this.layers=a.cache.getTilemapData(b).layers,this.calculateIndexes()):this.layers=[],this.currentLayer=0,this.debugMap=[],this.dirty=!1,this._results=[],this._tempA=0,this._tempB=0},d.Tilemap.CSV=0,d.Tilemap.TILED_JSON=1,d.Tilemap.prototype={create:function(a,b,c){for(var e=[],f=0;c>f;f++){e[f]=[];for(var g=0;b>g;g++)e[f][g]=0}this.layers.push({name:a,width:b,height:c,alpha:1,visible:!0,tileMargin:0,tileSpacing:0,format:d.Tilemap.CSV,data:e,indexes:[]}),this.currentLayer=this.layers.length-1,this.dirty=!0},calculateIndexes:function(){for(var a=0;a=0&&b=0&&c=0&&a=0&&b=0&&a=0&&b=0&&b=0&&ca&&(a=0),0>b&&(b=0),c>this.layers[e].width&&(c=this.layers[e].width),d>this.layers[e].height&&(d=this.layers[e].height),this._results.length=0,this._results.push({x:a,y:b,width:c,height:d,layer:e});for(var f=b;b+d>f;f++)for(var g=a;a+c>g;g++)this._results.push({x:g,y:f,index:this.layers[e].data[f][g]});return this._results},paste:function(a,b,c,d){if("undefined"==typeof a&&(a=0),"undefined"==typeof b&&(b=0),"undefined"==typeof d&&(d=this.currentLayer),c&&!(c.length<2)){for(var e=c[1].x-a,f=c[1].y-b,g=1;g1?this.debugMap[this.layers[this.currentLayer].data[c][d]]?b.push("background: "+this.debugMap[this.layers[this.currentLayer].data[c][d]]):b.push("background: #ffffff"):b.push("background: rgb(0, 0, 0)");a+="\n"}b[0]=a,console.log.apply(console,b)},destroy:function(){this.removeAllLayers(),this.game=null}},d.TilemapLayer=function(a,b,e,f,g,h,i,j){this.game=a,this.canvas=d.Canvas.create(f,g),this.context=this.canvas.getContext("2d"),this.baseTexture=new c.BaseTexture(this.canvas),this.texture=new c.Texture(this.baseTexture),this.textureFrame=new d.Frame(0,0,0,f,g,"tilemaplayer",a.rnd.uuid()),d.Sprite.call(this,this.game,b,e,this.texture,this.textureFrame),this.type=d.TILEMAPLAYER,this.fixedToCamera=!0,this.tileset=null,this.tileWidth=0,this.tileHeight=0,this.tileMargin=0,this.tileSpacing=0,this.widthInPixels=0,this.heightInPixels=0,this.renderWidth=f,this.renderHeight=g,this._ga=1,this._dx=0,this._dy=0,this._dw=0,this._dh=0,this._tx=0,this._ty=0,this._tw=0,this._th=0,this._tl=0,this._maxX=0,this._maxY=0,this._startX=0,this._startY=0,this._results=[],this._x=0,this._y=0,this._prevX=0,this._prevY=0,this.scrollFactorX=1,this.scrollFactorY=1,this.tilemap=null,this.layer=null,this.index=0,this.dirty=!0,(h instanceof d.Tileset||"string"==typeof h)&&this.updateTileset(h),i instanceof d.Tilemap&&this.updateMapData(i,j)},d.TilemapLayer.prototype=Object.create(d.Sprite.prototype),d.TilemapLayer.prototype=d.Utils.extend(!0,d.TilemapLayer.prototype,d.Sprite.prototype,c.Sprite.prototype),d.TilemapLayer.prototype.constructor=d.TilemapLayer,d.TilemapLayer.prototype.update=function(){this.scrollX=this.game.camera.x*this.scrollFactorX,this.scrollY=this.game.camera.y*this.scrollFactorY,this.render()},d.TilemapLayer.prototype.resizeWorld=function(){this.game.world.setBounds(0,0,this.widthInPixels,this.heightInPixels)},d.TilemapLayer.prototype.updateTileset=function(a){if(a instanceof d.Tileset)this.tileset=a;else{if("string"!=typeof a)return;this.tileset=this.game.cache.getTileset("tiles")}this.tileWidth=this.tileset.tileWidth,this.tileHeight=this.tileset.tileHeight,this.tileMargin=this.tileset.tileMargin,this.tileSpacing=this.tileset.tileSpacing,this.updateMax()},d.TilemapLayer.prototype.updateMapData=function(a,b){"undefined"==typeof b&&(b=0),a instanceof d.Tilemap&&(this.tilemap=a,this.layer=this.tilemap.layers[b],this.index=b,this.updateMax(),this.tilemap.dirty=!0)},d.TilemapLayer.prototype._fixX=function(a){if(1===this.scrollFactorX)return a;var b=a-this._x/this.scrollFactorX;return this._x+b},d.TilemapLayer.prototype._unfixX=function(a){if(1===this.scrollFactorX)return a;var b=a-this._x;return this._x/this.scrollFactorX+b},d.TilemapLayer.prototype._fixY=function(a){if(1===this.scrollFactorY)return a;var b=a-this._y/this.scrollFactorY;return this._y+b},d.TilemapLayer.prototype._unfixY=function(a){if(1===this.scrollFactorY)return a;var b=a-this._y;return this._y/this.scrollFactorY+b},d.TilemapLayer.prototype.getTileX=function(a){var b=this.tileWidth*this.scale.x;return this.game.math.snapToFloor(this._fixX(a),b)/b},d.TilemapLayer.prototype.getTileY=function(a){var b=this.tileHeight*this.scale.y;return this.game.math.snapToFloor(this._fixY(a),b)/b},d.TilemapLayer.prototype.getTileXY=function(a,b,c){return c.x=this.getTileX(a),c.y=this.getTileY(b),c},d.TilemapLayer.prototype.getTiles=function(a,b,c,d,e){if(null!==this.tilemap){"undefined"==typeof e&&(e=!1),0>a&&(a=0),0>b&&(b=0),a=this._fixX(a),b=this._fixY(b),c>this.widthInPixels&&(c=this.widthInPixels),d>this.heightInPixels&&(d=this.heightInPixels);var f=this.tileWidth*this.scale.x,g=this.tileHeight*this.scale.y;this._tx=this.game.math.snapToFloor(a,f)/f,this._ty=this.game.math.snapToFloor(b,g)/g,this._tw=(this.game.math.snapToCeil(c,f)+f)/f,this._th=(this.game.math.snapToCeil(d,g)+g)/g,this._results=[];for(var h=0,i=null,j=0,k=0,l=this._ty;lthis.layer.width&&(this._maxX=this.layer.width),this._maxY>this.layer.height&&(this._maxY=this.layer.height),this.widthInPixels=this.layer.width*this.tileWidth,this.heightInPixels=this.layer.height*this.tileHeight),this.dirty=!0},d.TilemapLayer.prototype.render=function(){if(this.tilemap&&this.tilemap.dirty&&(this.dirty=!0),this.dirty&&this.tileset&&this.tilemap&&this.visible){this._prevX=this._dx,this._prevY=this._dy,this._dx=-(this._x-this._startX*this.tileWidth),this._dy=-(this._y-this._startY*this.tileHeight),this._tx=this._dx,this._ty=this._dy,this.context.clearRect(0,0,this.canvas.width,this.canvas.height);for(var a=this._startY;a0?this.deltaX():-this.deltaX()},d.TilemapLayer.prototype.deltaAbsY=function(){return this.deltaY()>0?this.deltaY():-this.deltaY()},d.TilemapLayer.prototype.deltaX=function(){return this._dx-this._prevX},d.TilemapLayer.prototype.deltaY=function(){return this._dy-this._prevY},Object.defineProperty(d.TilemapLayer.prototype,"scrollX",{get:function(){return this._x},set:function(a){a!==this._x&&a>=0&&this.layer&&(this._x=a,this._x>this.widthInPixels-this.renderWidth&&(this._x=this.widthInPixels-this.renderWidth),this._startX=this.game.math.floor(this._x/this.tileWidth),this._startX<0&&(this._startX=0),this._startX+this._maxX>this.layer.width&&(this._startX=this.layer.width-this._maxX),this.dirty=!0)}}),Object.defineProperty(d.TilemapLayer.prototype,"scrollY",{get:function(){return this._y},set:function(a){a!==this._y&&a>=0&&this.layer&&(this._y=a,this._y>this.heightInPixels-this.renderHeight&&(this._y=this.heightInPixels-this.renderHeight),this._startY=this.game.math.floor(this._y/this.tileHeight),this._startY<0&&(this._startY=0),this._startY+this._maxY>this.layer.height&&(this._startY=this.layer.height-this._maxY),this.dirty=!0)}}),d.TilemapParser={tileset:function(a,b,c,e,f,g,h){var i=a.cache.getTilesetImage(b);if(null==i)return null;var j=i.width,k=i.height;0>=c&&(c=Math.floor(-j/Math.min(-1,c))),0>=e&&(e=Math.floor(-k/Math.min(-1,e)));var l=Math.round(j/c),m=Math.round(k/e),n=l*m;if(-1!==f&&(n=f),0===j||0===k||c>j||e>k||0===n)return console.warn("Phaser.TilemapParser.tileSet: width/height zero or width/height < given tileWidth/tileHeight"),null;for(var o=g,p=g,q=new d.Tileset(i,b,c,e,g,h),r=0;n>r;r++)q.addTile(new d.Tile(q,r,o,p,c,e)),o+=c+h,o===j&&(o=g,p+=e+h);return q},parse:function(a,b,c){return c===d.Tilemap.CSV?this.parseCSV(b):c===d.Tilemap.TILED_JSON?this.parseTiledJSON(b):void 0},parseCSV:function(a){a=a.trim();for(var b=[],c=a.split("\n"),d=c.length,e=0,f=0;fa)for(var g=a;b>=g;g++)this.tiles[g].setCollision(c,d,e,f)},setCollision:function(a,b,c,d,e){this.tiles[a]&&this.tiles[a].setCollision(b,c,d,e)}},Object.defineProperty(d.Tileset.prototype,"total",{get:function(){return this.tiles.length}}),c.CanvasRenderer.prototype.render=function(a){c.texturesToUpdate.length=0,c.texturesToDestroy.length=0,c.visibleCount++,a.updateTransform(),this.context.setTransform(1,0,0,1,0,0),this.context.clearRect(0,0,this.width,this.height),this.renderDisplayObject(a),c.Texture.frameUpdates.length>0&&(c.Texture.frameUpdates.length=0)},c.CanvasRenderer.prototype.renderDisplayObject=function(a){var b=a.last._iNext;a=a.first;do if(a.visible)if(a.renderable&&0!==a.alpha){if(a instanceof c.Sprite)a.texture.frame&&(this.context.globalAlpha=a.worldAlpha,a.texture.trimmed?this.context.setTransform(a.worldTransform[0],a.worldTransform[3],a.worldTransform[1],a.worldTransform[4],a.worldTransform[2]+a.texture.trim.x,a.worldTransform[5]+a.texture.trim.y):this.context.setTransform(a.worldTransform[0],a.worldTransform[3],a.worldTransform[1],a.worldTransform[4],a.worldTransform[2],a.worldTransform[5]),this.context.drawImage(a.texture.baseTexture.source,a.texture.frame.x,a.texture.frame.y,a.texture.frame.width,a.texture.frame.height,a.anchor.x*-a.texture.frame.width,a.anchor.y*-a.texture.frame.height,a.texture.frame.width,a.texture.frame.height));else if(a instanceof c.Strip)this.context.setTransform(a.worldTransform[0],a.worldTransform[3],a.worldTransform[1],a.worldTransform[4],a.worldTransform[2],a.worldTransform[5]),this.renderStrip(a);else if(a instanceof c.TilingSprite)this.context.setTransform(a.worldTransform[0],a.worldTransform[3],a.worldTransform[1],a.worldTransform[4],a.worldTransform[2],a.worldTransform[5]),this.renderTilingSprite(a);else if(a instanceof c.CustomRenderable)a.renderCanvas(this);else if(a instanceof c.Graphics)this.context.setTransform(a.worldTransform[0],a.worldTransform[3],a.worldTransform[1],a.worldTransform[4],a.worldTransform[2],a.worldTransform[5]),c.CanvasGraphics.renderGraphics(a,this.context);else if(a instanceof c.FilterBlock)if(a.open){this.context.save();var d=a.mask.alpha,e=a.mask.worldTransform;this.context.setTransform(e[0],e[3],e[1],e[4],e[2],e[5]),a.mask.worldAlpha=.5,this.context.worldAlpha=0,c.CanvasGraphics.renderGraphicsMask(a.mask,this.context),this.context.clip(),a.mask.worldAlpha=d}else this.context.restore();a=a._iNext}else a=a._iNext;else a=a.last._iNext;while(a!=b)},c.WebGLBatch.prototype.update=function(){for(var a,b,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r=0,s=this.head;s;){if(s.vcount===c.visibleCount){if(b=s.texture.frame.width,d=s.texture.frame.height,e=s.anchor.x,f=s.anchor.y,g=b*(1-e),h=b*-e,i=d*(1-f),j=d*-f,k=8*r,a=s.worldTransform,l=a[0],m=a[3],n=a[1],o=a[4],p=a[2],q=a[5],s.texture.trimmed&&(p+=s.texture.trim.x,q+=s.texture.trim.y),this.verticies[k+0]=l*h+n*j+p,this.verticies[k+1]=o*j+m*h+q,this.verticies[k+2]=l*g+n*j+p,this.verticies[k+3]=o*j+m*g+q,this.verticies[k+4]=l*g+n*i+p,this.verticies[k+5]=o*i+m*g+q,this.verticies[k+6]=l*h+n*i+p,this.verticies[k+7]=o*i+m*h+q,s.updateFrame||s.texture.updateFrame){this.dirtyUVS=!0;var t=s.texture,u=t.frame,v=t.baseTexture.width,w=t.baseTexture.height;this.uvs[k+0]=u.x/v,this.uvs[k+1]=u.y/w,this.uvs[k+2]=(u.x+u.width)/v,this.uvs[k+3]=u.y/w,this.uvs[k+4]=(u.x+u.width)/v,this.uvs[k+5]=(u.y+u.height)/w,this.uvs[k+6]=u.x/v,this.uvs[k+7]=(u.y+u.height)/w,s.updateFrame=!1}if(s.cacheAlpha!=s.worldAlpha){s.cacheAlpha=s.worldAlpha;var x=4*r;this.colors[x]=this.colors[x+1]=this.colors[x+2]=this.colors[x+3]=s.worldAlpha,this.dirtyColors=!0}}else k=8*r,this.verticies[k+0]=0,this.verticies[k+1]=0,this.verticies[k+2]=0,this.verticies[k+3]=0,this.verticies[k+4]=0,this.verticies[k+5]=0,this.verticies[k+6]=0,this.verticies[k+7]=0;r++,s=s.__next}},d}); \ No newline at end of file +/*! Phaser v1.1.4 | (c) 2013 Photon Storm Ltd. */ +!function(a,b){"function"==typeof define&&define.amd?define(b):"object"==typeof exports?module.exports=b():a.Phaser=b()}(this,function(){function a(){return b.Matrix="undefined"!=typeof Float32Array?Float32Array:Array,b.Matrix}var b=b||{},c=c||{VERSION:"1.1.4",DEV_VERSION:"1.1.4",GAMES:[],AUTO:0,CANVAS:1,WEBGL:2,HEADLESS:3,SPRITE:0,BUTTON:1,BULLET:2,GRAPHICS:3,TEXT:4,TILESPRITE:5,BITMAPTEXT:6,GROUP:7,RENDERTEXTURE:8,TILEMAP:9,TILEMAPLAYER:10,EMITTER:11,POLYGON:12,BITMAPDATA:13,CANVAS_FILTER:14,WEBGL_FILTER:15,NONE:0,LEFT:1,RIGHT:2,UP:3,DOWN:4};b.InteractionManager=function(){},c.Utils={shuffle:function(a){for(var b=a.length-1;b>0;b--){var c=Math.floor(Math.random()*(b+1)),d=a[b];a[b]=a[c],a[c]=d}return a},pad:function(a,b,c,d){if("undefined"==typeof b)var b=0;if("undefined"==typeof c)var c=" ";if("undefined"==typeof d)var d=3;var e=0;if(b+1>=a.length)switch(d){case 1:a=Array(b+1-a.length).join(c)+a;break;case 3:var f=Math.ceil((e=b-a.length)/2),g=e-f;a=Array(g+1).join(c)+a+Array(f+1).join(c);break;default:a+=Array(b+1-a.length).join(c)}return a},isPlainObject:function(a){if("object"!=typeof a||a.nodeType||a===a.window)return!1;try{if(a.constructor&&!hasOwn.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(b){return!1}return!0},extend:function(){var a,b,d,e,f,g,h=arguments[0]||{},i=1,j=arguments.length,k=!1;for("boolean"==typeof h&&(k=h,h=arguments[1]||{},i=2),j===i&&(h=this,--i);j>i;i++)if(null!=(a=arguments[i]))for(b in a)d=h[b],e=a[b],h!==e&&(k&&e&&(c.Utils.isPlainObject(e)||(f=Array.isArray(e)))?(f?(f=!1,g=d&&Array.isArray(d)?d:[]):g=d&&c.Utils.isPlainObject(d)?d:{},h[b]=c.Utils.extend(k,g,e)):void 0!==e&&(h[b]=e));return h}},function(){var a=!1;a&&(window.console=void 0),void 0===window.console&&(window.console={debug:function(){return!0},info:function(){return!1},warn:function(){return!1},log:function(){return!1}}),debug=function(a){window.console.debug(a)},info=function(a){window.console.info(a)},warn=function(a){window.console.warn(a)},log=function(a){window.console.log(a)}}(),b.hex2rgb=function(a){return[(255&a>>16)/255,(255&a>>8)/255,(255&a)/255]},"function"!=typeof Function.prototype.bind&&(Function.prototype.bind=function(){var a=Array.prototype.slice;return function(b){function c(){var f=e.concat(a.call(arguments));d.apply(this instanceof c?this:b,f)}var d=this,e=a.call(arguments,1);if("function"!=typeof d)throw new TypeError;return c.prototype=function f(a){return a&&(f.prototype=a),this instanceof f?void 0:new f}(d.prototype),c}}()),a(),b.mat3={},b.mat3.create=function(){var a=new b.Matrix(9);return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=1,a[5]=0,a[6]=0,a[7]=0,a[8]=1,a},b.mat3.identity=function(a){return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=1,a[5]=0,a[6]=0,a[7]=0,a[8]=1,a},b.mat4={},b.mat4.create=function(){var a=new b.Matrix(16);return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=1,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=1,a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1,a},b.mat3.multiply=function(a,b,c){c||(c=a);var d=a[0],e=a[1],f=a[2],g=a[3],h=a[4],i=a[5],j=a[6],k=a[7],l=a[8],m=b[0],n=b[1],o=b[2],p=b[3],q=b[4],r=b[5],s=b[6],t=b[7],u=b[8];return c[0]=m*d+n*g+o*j,c[1]=m*e+n*h+o*k,c[2]=m*f+n*i+o*l,c[3]=p*d+q*g+r*j,c[4]=p*e+q*h+r*k,c[5]=p*f+q*i+r*l,c[6]=s*d+t*g+u*j,c[7]=s*e+t*h+u*k,c[8]=s*f+t*i+u*l,c},b.mat3.clone=function(a){var c=new b.Matrix(9);return c[0]=a[0],c[1]=a[1],c[2]=a[2],c[3]=a[3],c[4]=a[4],c[5]=a[5],c[6]=a[6],c[7]=a[7],c[8]=a[8],c},b.mat3.transpose=function(a,b){if(!b||a===b){var c=a[1],d=a[2],e=a[5];return a[1]=a[3],a[2]=a[6],a[3]=c,a[5]=a[7],a[6]=d,a[7]=e,a}return b[0]=a[0],b[1]=a[3],b[2]=a[6],b[3]=a[1],b[4]=a[4],b[5]=a[7],b[6]=a[2],b[7]=a[5],b[8]=a[8],b},b.mat3.toMat4=function(a,c){return c||(c=b.mat4.create()),c[15]=1,c[14]=0,c[13]=0,c[12]=0,c[11]=0,c[10]=a[8],c[9]=a[7],c[8]=a[6],c[7]=0,c[6]=a[5],c[5]=a[4],c[4]=a[3],c[3]=0,c[2]=a[2],c[1]=a[1],c[0]=a[0],c},b.mat4.create=function(){var a=new b.Matrix(16);return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=1,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=1,a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1,a},b.mat4.transpose=function(a,b){if(!b||a===b){var c=a[1],d=a[2],e=a[3],f=a[6],g=a[7],h=a[11];return a[1]=a[4],a[2]=a[8],a[3]=a[12],a[4]=c,a[6]=a[9],a[7]=a[13],a[8]=d,a[9]=f,a[11]=a[14],a[12]=e,a[13]=g,a[14]=h,a}return b[0]=a[0],b[1]=a[4],b[2]=a[8],b[3]=a[12],b[4]=a[1],b[5]=a[5],b[6]=a[9],b[7]=a[13],b[8]=a[2],b[9]=a[6],b[10]=a[10],b[11]=a[14],b[12]=a[3],b[13]=a[7],b[14]=a[11],b[15]=a[15],b},b.mat4.multiply=function(a,b,c){c||(c=a);var d=a[0],e=a[1],f=a[2],g=a[3],h=a[4],i=a[5],j=a[6],k=a[7],l=a[8],m=a[9],n=a[10],o=a[11],p=a[12],q=a[13],r=a[14],s=a[15],t=b[0],u=b[1],v=b[2],w=b[3];return c[0]=t*d+u*h+v*l+w*p,c[1]=t*e+u*i+v*m+w*q,c[2]=t*f+u*j+v*n+w*r,c[3]=t*g+u*k+v*o+w*s,t=b[4],u=b[5],v=b[6],w=b[7],c[4]=t*d+u*h+v*l+w*p,c[5]=t*e+u*i+v*m+w*q,c[6]=t*f+u*j+v*n+w*r,c[7]=t*g+u*k+v*o+w*s,t=b[8],u=b[9],v=b[10],w=b[11],c[8]=t*d+u*h+v*l+w*p,c[9]=t*e+u*i+v*m+w*q,c[10]=t*f+u*j+v*n+w*r,c[11]=t*g+u*k+v*o+w*s,t=b[12],u=b[13],v=b[14],w=b[15],c[12]=t*d+u*h+v*l+w*p,c[13]=t*e+u*i+v*m+w*q,c[14]=t*f+u*j+v*n+w*r,c[15]=t*g+u*k+v*o+w*s,c},b.Point=function(a,b){this.x=a||0,this.y=b||0},b.Point.prototype.clone=function(){return new b.Point(this.x,this.y)},b.Point.prototype.constructor=b.Point,b.Rectangle=function(a,b,c,d){this.x=a||0,this.y=b||0,this.width=c||0,this.height=d||0},b.Rectangle.prototype.clone=function(){return new b.Rectangle(this.x,this.y,this.width,this.height)},b.Rectangle.prototype.contains=function(a,b){if(this.width<=0||this.height<=0)return!1;var c=this.x;if(a>=c&&a<=c+this.width){var d=this.y;if(b>=d&&b<=d+this.height)return!0}return!1},b.Rectangle.prototype.constructor=b.Rectangle,b.Polygon=function(a){if(a instanceof Array||(a=Array.prototype.slice.call(arguments)),"number"==typeof a[0]){for(var c=[],d=0,e=a.length;e>d;d+=2)c.push(new b.Point(a[d],a[d+1]));a=c}this.points=a},b.Polygon.prototype.clone=function(){for(var a=[],c=0;cb!=i>b&&(h-f)*(b-g)/(i-g)+f>a;j&&(c=!c)}return c},b.Polygon.prototype.constructor=b.Polygon,b.DisplayObject=function(){this.last=this,this.first=this,this.position=new b.Point,this.scale=new b.Point(1,1),this.pivot=new b.Point(0,0),this.rotation=0,this.alpha=1,this.visible=!0,this.hitArea=null,this.buttonMode=!1,this.renderable=!1,this.parent=null,this.stage=null,this.worldAlpha=1,this._interactive=!1,this.defaultCursor="pointer",this.worldTransform=b.mat3.create(),this.localTransform=b.mat3.create(),this.color=[],this.dynamic=!0,this._sr=0,this._cr=1,this.filterArea=new b.Rectangle(0,0,1,1)},b.DisplayObject.prototype.constructor=b.DisplayObject,b.DisplayObject.prototype.setInteractive=function(a){this.interactive=a},Object.defineProperty(b.DisplayObject.prototype,"interactive",{get:function(){return this._interactive},set:function(a){this._interactive=a,this.stage&&(this.stage.dirty=!0)}}),Object.defineProperty(b.DisplayObject.prototype,"mask",{get:function(){return this._mask},set:function(a){a?this._mask?(a.start=this._mask.start,a.end=this._mask.end):(this.addFilter(a),a.renderable=!1):(this.removeFilter(this._mask),this._mask.renderable=!0),this._mask=a}}),Object.defineProperty(b.DisplayObject.prototype,"filters",{get:function(){return this._filters},set:function(a){if(a){this._filters&&this.removeFilter(this._filters),this.addFilter(a);for(var b=[],c=0;c=0&&b<=this.children.length))throw new Error(a+" The index "+b+" supplied is out of bounds "+this.children.length);if(void 0!==a.parent&&a.parent.removeChild(a),a.parent=this,this.stage){var c=a;do c.interactive&&(this.stage.dirty=!0),c.stage=this.stage,c=c._iNext;while(c)}var d,e,f=a.first,g=a.last;if(b===this.children.length){e=this.last;for(var h=this,i=this.last;h;)h.last===i&&(h.last=a.last),h=h.parent}else e=0===b?this:this.children[b-1].last;d=e._iNext,d&&(d._iPrev=g,g._iNext=d),f._iPrev=e,e._iNext=f,this.children.splice(b,0,a),this.__renderGroup&&(a.__renderGroup&&a.__renderGroup.removeDisplayObjectAndChildren(a),this.__renderGroup.addDisplayObjectAndChildren(a))},b.DisplayObjectContainer.prototype.swapChildren=function(a,b){if(a!==b){var c=this.children.indexOf(a),d=this.children.indexOf(b);if(0>c||0>d)throw new Error("swapChildren: Both the supplied DisplayObjects must be a child of the caller.");this.removeChild(a),this.removeChild(b),d>c?(this.addChildAt(b,c),this.addChildAt(a,d)):(this.addChildAt(a,d),this.addChildAt(b,c))}},b.DisplayObjectContainer.prototype.getChildAt=function(a){if(a>=0&&aa;a++)this.children[a].updateTransform()}},b.blendModes={},b.blendModes.NORMAL=0,b.blendModes.SCREEN=1,b.Sprite=function(a){b.DisplayObjectContainer.call(this),this.anchor=new b.Point,this.texture=a,this.blendMode=b.blendModes.NORMAL,this._width=0,this._height=0,a.baseTexture.hasLoaded?this.updateFrame=!0:(this.onTextureUpdateBind=this.onTextureUpdate.bind(this),this.texture.addEventListener("update",this.onTextureUpdateBind)),this.renderable=!0},b.Sprite.prototype=Object.create(b.DisplayObjectContainer.prototype),b.Sprite.prototype.constructor=b.Sprite,Object.defineProperty(b.Sprite.prototype,"width",{get:function(){return this.scale.x*this.texture.frame.width},set:function(a){this.scale.x=a/this.texture.frame.width,this._width=a}}),Object.defineProperty(b.Sprite.prototype,"height",{get:function(){return this.scale.y*this.texture.frame.height},set:function(a){this.scale.y=a/this.texture.frame.height,this._height=a}}),b.Sprite.prototype.setTexture=function(a){this.texture.baseTexture!==a.baseTexture?(this.textureChange=!0,this.texture=a,this.__renderGroup&&this.__renderGroup.updateTexture(this)):this.texture=a,this.updateFrame=!0},b.Sprite.prototype.onTextureUpdate=function(){this._width&&(this.scale.x=this._width/this.texture.frame.width),this._height&&(this.scale.y=this._height/this.texture.frame.height),this.updateFrame=!0},b.Sprite.fromFrame=function(a){var c=b.TextureCache[a];if(!c)throw new Error('The frameId "'+a+'" does not exist in the texture cache'+this);return new b.Sprite(c)},b.Sprite.fromImage=function(a){var c=b.Texture.fromImage(a);return new b.Sprite(c)},b.Stage=function(a){b.DisplayObjectContainer.call(this),this.worldTransform=b.mat3.create(),this.interactive=!0,this.interactionManager=new b.InteractionManager(this),this.dirty=!0,this.__childrenAdded=[],this.__childrenRemoved=[],this.stage=this,this.stage.hitArea=new b.Rectangle(0,0,1e5,1e5),this.setBackgroundColor(a),this.worldVisible=!0},b.Stage.prototype=Object.create(b.DisplayObjectContainer.prototype),b.Stage.prototype.constructor=b.Stage,b.Stage.prototype.setInteractionDelegate=function(a){this.interactionManager.setTargetDomElement(a)},b.Stage.prototype.updateTransform=function(){this.worldAlpha=1,this.vcount=b.visibleCount;for(var a=0,c=this.children.length;c>a;a++)this.children[a].updateTransform();this.dirty&&(this.dirty=!1,this.interactionManager.dirty=!0),this.interactive&&this.interactionManager.update()},b.Stage.prototype.setBackgroundColor=function(a){this.backgroundColor=a||0,this.backgroundColorSplit=b.hex2rgb(this.backgroundColor);var c=this.backgroundColor.toString(16);c="000000".substr(0,6-c.length)+c,this.backgroundColorString="#"+c},b.Stage.prototype.getMousePosition=function(){return this.interactionManager.mouse.global},b.CustomRenderable=function(){b.DisplayObject.call(this),this.renderable=!0},b.CustomRenderable.prototype=Object.create(b.DisplayObject.prototype),b.CustomRenderable.prototype.constructor=b.CustomRenderable,b.CustomRenderable.prototype.renderCanvas=function(){},b.CustomRenderable.prototype.initWebGL=function(){},b.CustomRenderable.prototype.renderWebGL=function(){},b.Strip=function(a,c,d){b.DisplayObjectContainer.call(this),this.texture=a,this.blendMode=b.blendModes.NORMAL;try{this.uvs=new Float32Array([0,1,1,1,1,0,0,1]),this.verticies=new Float32Array([0,0,0,0,0,0,0,0,0]),this.colors=new Float32Array([1,1,1,1]),this.indices=new Uint16Array([0,1,2,3])}catch(e){this.uvs=[0,1,1,1,1,0,0,1],this.verticies=[0,0,0,0,0,0,0,0,0],this.colors=[1,1,1,1],this.indices=[0,1,2,3]}this.width=c,this.height=d,a.baseTexture.hasLoaded?(this.width=this.texture.frame.width,this.height=this.texture.frame.height,this.updateFrame=!0):(this.onTextureUpdateBind=this.onTextureUpdate.bind(this),this.texture.addEventListener("update",this.onTextureUpdateBind)),this.renderable=!0},b.Strip.prototype=Object.create(b.DisplayObjectContainer.prototype),b.Strip.prototype.constructor=b.Strip,b.Strip.prototype.setTexture=function(a){this.texture=a,this.width=a.frame.width,this.height=a.frame.height,this.updateFrame=!0},b.Strip.prototype.onTextureUpdate=function(){this.updateFrame=!0},b.Rope=function(a,c){b.Strip.call(this,a),this.points=c;try{this.verticies=new Float32Array(4*c.length),this.uvs=new Float32Array(4*c.length),this.colors=new Float32Array(2*c.length),this.indices=new Uint16Array(2*c.length)}catch(d){this.verticies=new Array(4*c.length),this.uvs=new Array(4*c.length),this.colors=new Array(2*c.length),this.indices=new Array(2*c.length)}this.refresh()},b.Rope.prototype=Object.create(b.Strip.prototype),b.Rope.prototype.constructor=b.Rope,b.Rope.prototype.refresh=function(){var a=this.points;if(!(a.length<1)){var b=this.uvs,c=a[0],d=this.indices,e=this.colors;this.count-=.2,b[0]=0,b[1]=1,b[2]=0,b[3]=1,e[0]=1,e[1]=1,d[0]=0,d[1]=1;for(var f,g,h,i=a.length,j=1;i>j;j++)f=a[j],g=4*j,h=j/(i-1),j%2?(b[g]=h,b[g+1]=0,b[g+2]=h,b[g+3]=1):(b[g]=h,b[g+1]=0,b[g+2]=h,b[g+3]=1),g=2*j,e[g]=1,e[g+1]=1,g=2*j,d[g]=g,d[g+1]=g+1,c=f}},b.Rope.prototype.updateTransform=function(){var a=this.points;if(!(a.length<1)){var c,d=a[0],e={x:0,y:0};this.count-=.2;var f=this.verticies;f[0]=d.x+e.x,f[1]=d.y+e.y,f[2]=d.x-e.x,f[3]=d.y-e.y;for(var g,h,i,j,k,l=a.length,m=1;l>m;m++)g=a[m],h=4*m,c=m1&&(i=1),j=Math.sqrt(e.x*e.x+e.y*e.y),k=this.texture.height/2,e.x/=j,e.y/=j,e.x*=k,e.y*=k,f[h]=g.x+e.x,f[h+1]=g.y+e.y,f[h+2]=g.x-e.x,f[h+3]=g.y-e.y,d=g;b.DisplayObjectContainer.prototype.updateTransform.call(this)}},b.Rope.prototype.setTexture=function(a){this.texture=a,this.updateFrame=!0},b.TilingSprite=function(a,c,d){b.DisplayObjectContainer.call(this),this.texture=a,this.width=c,this.height=d,this.tileScale=new b.Point(1,1),this.tilePosition=new b.Point(0,0),this.renderable=!0,this.blendMode=b.blendModes.NORMAL},b.TilingSprite.prototype=Object.create(b.DisplayObjectContainer.prototype),b.TilingSprite.prototype.constructor=b.TilingSprite,b.TilingSprite.prototype.setTexture=function(a){this.texture=a,this.updateFrame=!0},b.TilingSprite.prototype.onTextureUpdate=function(){this.updateFrame=!0},b.AbstractFilter=function(a,b){this.passes=[this],this.dirty=!0,this.padding=0,this.uniforms=b||{},this.fragmentSrc=a||[]},b.FilterBlock=function(){this.visible=!0,this.renderable=!0},b.Graphics=function(){b.DisplayObjectContainer.call(this),this.renderable=!0,this.fillAlpha=1,this.lineWidth=0,this.lineColor="black",this.graphicsData=[],this.currentPath={points:[]}},b.Graphics.prototype=Object.create(b.DisplayObjectContainer.prototype),b.Graphics.prototype.constructor=b.Graphics,b.Graphics.prototype.lineStyle=function(a,c,d){this.currentPath.points.length||this.graphicsData.pop(),this.lineWidth=a||0,this.lineColor=c||0,this.lineAlpha=arguments.length<3?1:d,this.currentPath={lineWidth:this.lineWidth,lineColor:this.lineColor,lineAlpha:this.lineAlpha,fillColor:this.fillColor,fillAlpha:this.fillAlpha,fill:this.filling,points:[],type:b.Graphics.POLY},this.graphicsData.push(this.currentPath)},b.Graphics.prototype.moveTo=function(a,c){this.currentPath.points.length||this.graphicsData.pop(),this.currentPath=this.currentPath={lineWidth:this.lineWidth,lineColor:this.lineColor,lineAlpha:this.lineAlpha,fillColor:this.fillColor,fillAlpha:this.fillAlpha,fill:this.filling,points:[],type:b.Graphics.POLY},this.currentPath.points.push(a,c),this.graphicsData.push(this.currentPath)},b.Graphics.prototype.lineTo=function(a,b){this.currentPath.points.push(a,b),this.dirty=!0},b.Graphics.prototype.beginFill=function(a,b){this.filling=!0,this.fillColor=a||0,this.fillAlpha=arguments.length<2?1:b},b.Graphics.prototype.endFill=function(){this.filling=!1,this.fillColor=null,this.fillAlpha=1},b.Graphics.prototype.drawRect=function(a,c,d,e){this.currentPath.points.length||this.graphicsData.pop(),this.currentPath={lineWidth:this.lineWidth,lineColor:this.lineColor,lineAlpha:this.lineAlpha,fillColor:this.fillColor,fillAlpha:this.fillAlpha,fill:this.filling,points:[a,c,d,e],type:b.Graphics.RECT},this.graphicsData.push(this.currentPath),this.dirty=!0},b.Graphics.prototype.drawCircle=function(a,c,d){this.currentPath.points.length||this.graphicsData.pop(),this.currentPath={lineWidth:this.lineWidth,lineColor:this.lineColor,lineAlpha:this.lineAlpha,fillColor:this.fillColor,fillAlpha:this.fillAlpha,fill:this.filling,points:[a,c,d,d],type:b.Graphics.CIRC},this.graphicsData.push(this.currentPath),this.dirty=!0},b.Graphics.prototype.drawEllipse=function(a,c,d,e){this.currentPath.points.length||this.graphicsData.pop(),this.currentPath={lineWidth:this.lineWidth,lineColor:this.lineColor,lineAlpha:this.lineAlpha,fillColor:this.fillColor,fillAlpha:this.fillAlpha,fill:this.filling,points:[a,c,d,e],type:b.Graphics.ELIP},this.graphicsData.push(this.currentPath),this.dirty=!0},b.Graphics.prototype.clear=function(){this.lineWidth=0,this.filling=!1,this.dirty=!0,this.clearDirty=!0,this.graphicsData=[],this.bounds=null},b.Graphics.prototype.updateFilterBounds=function(){if(!this.bounds){for(var a,c,d,e=1/0,f=-1/0,g=1/0,h=-1/0,i=0;ic?c:e,f=c+m>f?c+m:f,g=g>d?c:g,h=d+n>h?d+n:h}else if(k===b.Graphics.CIRC||k===b.Graphics.ELIP){c=a.x,d=a.y;var o=a.radius+l/2;e=e>c-o?c-o:e,f=c+o>f?c+o:f,g=g>d-o?d-o:g,h=d+o>h?d+o:h}else for(var p=0;pc-l?c-l:e,f=c+l>f?c+l:f,g=g>d-l?d-l:g,h=d+l>h?d+l:h}this.bounds=new b.Rectangle(e,g,f-e,h-g)}},b.Graphics.POLY=0,b.Graphics.RECT=1,b.Graphics.CIRC=2,b.Graphics.ELIP=3,b.CanvasGraphics=function(){},b.CanvasGraphics.renderGraphics=function(a,c){for(var d=a.worldAlpha,e="",f=0;f1&&(d=1,window.console.log("Pixi.js warning: masks in canvas can only mask using the first path in the graphics object"));for(var e=0;1>e;e++){var f=a.graphicsData[e],g=f.points;if(f.type===b.Graphics.POLY){c.beginPath(),c.moveTo(g[0],g[1]);for(var h=1;h0&&(b.Texture.frameUpdates=[])},b.CanvasRenderer.prototype.resize=function(a,b){this.width=a,this.height=b,this.view.width=a,this.view.height=b},b.CanvasRenderer.prototype.renderDisplayObject=function(a){var c,d=this.context;d.globalCompositeOperation="source-over";var e=a.last._iNext;a=a.first;do if(c=a.worldTransform,a.visible)if(a.renderable){if(a instanceof b.Sprite){var f=a.texture.frame;f&&f.width&&f.height&&a.texture.baseTexture.source&&(d.globalAlpha=a.worldAlpha,d.setTransform(c[0],c[3],c[1],c[4],c[2],c[5]),this.smoothProperty&&this.scaleMode!==a.texture.baseTexture.scaleMode&&(this.scaleMode=a.texture.baseTexture.scaleMode,d[this.smoothProperty]=this.scaleMode===b.BaseTexture.SCALE_MODE.LINEAR),d.drawImage(a.texture.baseTexture.source,f.x,f.y,f.width,f.height,a.anchor.x*-f.width,a.anchor.y*-f.height,f.width,f.height))}else if(a instanceof b.Strip)d.setTransform(c[0],c[3],c[1],c[4],c[2],c[5]),this.renderStrip(a);else if(a instanceof b.TilingSprite)d.setTransform(c[0],c[3],c[1],c[4],c[2],c[5]),this.renderTilingSprite(a);else if(a instanceof b.CustomRenderable)d.setTransform(c[0],c[3],c[1],c[4],c[2],c[5]),a.renderCanvas(this);else if(a instanceof b.Graphics)d.setTransform(c[0],c[3],c[1],c[4],c[2],c[5]),b.CanvasGraphics.renderGraphics(a,d);else if(a instanceof b.FilterBlock&&a.data instanceof b.Graphics){var g=a.data;if(a.open){d.save();var h=g.alpha,i=g.worldTransform;d.setTransform(i[0],i[3],i[1],i[4],i[2],i[5]),g.worldAlpha=.5,d.worldAlpha=0,b.CanvasGraphics.renderGraphicsMask(g,d),d.clip(),g.worldAlpha=h}else d.restore()}a=a._iNext}else a=a._iNext;else a=a.last._iNext;while(a!==e)},b.CanvasRenderer.prototype.renderStripFlat=function(a){var b=this.context,c=a.verticies,d=c.length/2;this.count++,b.beginPath();for(var e=1;d-2>e;e++){var f=2*e,g=c[f],h=c[f+2],i=c[f+4],j=c[f+1],k=c[f+3],l=c[f+5];b.moveTo(g,j),b.lineTo(h,k),b.lineTo(i,l)}b.fillStyle="#FF0000",b.fill(),b.closePath()},b.CanvasRenderer.prototype.renderTilingSprite=function(a){var b=this.context;b.globalAlpha=a.worldAlpha,a.__tilePattern||(a.__tilePattern=b.createPattern(a.texture.baseTexture.source,"repeat")),b.beginPath();var c=a.tilePosition,d=a.tileScale;b.scale(d.x,d.y),b.translate(c.x,c.y),b.fillStyle=a.__tilePattern,b.fillRect(-c.x,-c.y,a.width/d.x,a.height/d.y),b.scale(1/d.x,1/d.y),b.translate(-c.x,-c.y),b.closePath()},b.CanvasRenderer.prototype.renderStrip=function(a){var b=this.context,c=a.verticies,d=a.uvs,e=c.length/2;this.count++;for(var f=1;e-2>f;f++){var g=2*f,h=c[g],i=c[g+2],j=c[g+4],k=c[g+1],l=c[g+3],m=c[g+5],n=d[g]*a.texture.width,o=d[g+2]*a.texture.width,p=d[g+4]*a.texture.width,q=d[g+1]*a.texture.height,r=d[g+3]*a.texture.height,s=d[g+5]*a.texture.height;b.save(),b.beginPath(),b.moveTo(h,k),b.lineTo(i,l),b.lineTo(j,m),b.closePath(),b.clip();var t=n*r+q*p+o*s-r*p-q*o-n*s,u=h*r+q*j+i*s-r*j-q*i-h*s,v=n*i+h*p+o*j-i*p-h*o-n*j,w=n*r*j+q*i*p+h*o*s-h*r*p-q*o*j-n*i*s,x=k*r+q*m+l*s-r*m-q*l-k*s,y=n*l+k*p+o*m-l*p-k*o-n*m,z=n*r*m+q*l*p+k*o*s-k*r*p-q*o*m-n*l*s;b.transform(u/t,x/t,v/t,y/t,w/t,z/t),b.drawImage(a.texture.baseTexture.source,0,0),b.restore()}},b.PixiShader=function(){this.program=null,this.fragmentSrc=["precision lowp float;","varying vec2 vTextureCoord;","varying float vColor;","uniform sampler2D uSampler;","void main(void) {"," gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor;","}"],this.textureCount=0},b.PixiShader.prototype.init=function(){var a=b.compileProgram(this.vertexSrc||b.PixiShader.defaultVertexSrc,this.fragmentSrc),c=b.gl;c.useProgram(a),this.uSampler=c.getUniformLocation(a,"uSampler"),this.projectionVector=c.getUniformLocation(a,"projectionVector"),this.offsetVector=c.getUniformLocation(a,"offsetVector"),this.dimensions=c.getUniformLocation(a,"dimensions"),this.aVertexPosition=c.getAttribLocation(a,"aVertexPosition"),this.colorAttribute=c.getAttribLocation(a,"aColor"),this.aTextureCoord=c.getAttribLocation(a,"aTextureCoord");for(var d in this.uniforms)this.uniforms[d].uniformLocation=c.getUniformLocation(a,d);this.initUniforms(),this.program=a},b.PixiShader.prototype.initUniforms=function(){this.textureCount=1;var a;for(var c in this.uniforms){a=this.uniforms[c];var d=a.type;"sampler2D"===d?(a._init=!1,null!==a.value&&this.initSampler2D(a)):"mat2"===d||"mat3"===d||"mat4"===d?(a.glMatrix=!0,a.glValueLength=1,"mat2"===d?a.glFunc=b.gl.uniformMatrix2fv:"mat3"===d?a.glFunc=b.gl.uniformMatrix3fv:"mat4"===d&&(a.glFunc=b.gl.uniformMatrix4fv)):(a.glFunc=b.gl["uniform"+d],a.glValueLength="2f"===d||"2i"===d?2:"3f"===d||"3i"===d?3:"4f"===d||"4i"===d?4:1)}},b.PixiShader.prototype.initSampler2D=function(a){if(a.value&&a.value.baseTexture&&a.value.baseTexture.hasLoaded){if(b.gl.activeTexture(b.gl["TEXTURE"+this.textureCount]),b.gl.bindTexture(b.gl.TEXTURE_2D,a.value.baseTexture._glTexture),a.textureData){var c=a.textureData,d=c.magFilter?c.magFilter:b.gl.LINEAR,e=c.minFilter?c.minFilter:b.gl.LINEAR,f=c.wrapS?c.wrapS:b.gl.CLAMP_TO_EDGE,g=c.wrapT?c.wrapT:b.gl.CLAMP_TO_EDGE,h=c.luminance?b.gl.LUMINANCE:b.gl.RGBA;if(c.repeat&&(f=b.gl.REPEAT,g=b.gl.REPEAT),b.gl.pixelStorei(b.gl.UNPACK_FLIP_Y_WEBGL,!1),c.width){var i=c.width?c.width:512,j=c.height?c.height:2,k=c.border?c.border:0;b.gl.texImage2D(b.gl.TEXTURE_2D,0,h,i,j,k,h,b.gl.UNSIGNED_BYTE,null)}else b.gl.texImage2D(b.gl.TEXTURE_2D,0,h,b.gl.RGBA,b.gl.UNSIGNED_BYTE,a.value.baseTexture.source);b.gl.texParameteri(b.gl.TEXTURE_2D,b.gl.TEXTURE_MAG_FILTER,d),b.gl.texParameteri(b.gl.TEXTURE_2D,b.gl.TEXTURE_MIN_FILTER,e),b.gl.texParameteri(b.gl.TEXTURE_2D,b.gl.TEXTURE_WRAP_S,f),b.gl.texParameteri(b.gl.TEXTURE_2D,b.gl.TEXTURE_WRAP_T,g)}b.gl.uniform1i(a.uniformLocation,this.textureCount),a._init=!0,this.textureCount++}},b.PixiShader.prototype.syncUniforms=function(){this.textureCount=1;var a;for(var c in this.uniforms)a=this.uniforms[c],1===a.glValueLength?a.glMatrix===!0?a.glFunc.call(b.gl,a.uniformLocation,a.transpose,a.value):a.glFunc.call(b.gl,a.uniformLocation,a.value):2===a.glValueLength?a.glFunc.call(b.gl,a.uniformLocation,a.value.x,a.value.y):3===a.glValueLength?a.glFunc.call(b.gl,a.uniformLocation,a.value.x,a.value.y,a.value.z):4===a.glValueLength?a.glFunc.call(b.gl,a.uniformLocation,a.value.x,a.value.y,a.value.z,a.value.w):"sampler2D"===a.type&&(a._init?(b.gl.activeTexture(b.gl["TEXTURE"+this.textureCount]),b.gl.bindTexture(b.gl.TEXTURE_2D,a.value.baseTexture._glTexture),b.gl.uniform1i(a.uniformLocation,this.textureCount),this.textureCount++):this.initSampler2D(a)) +},b.PixiShader.defaultVertexSrc=["attribute vec2 aVertexPosition;","attribute vec2 aTextureCoord;","attribute float aColor;","uniform vec2 projectionVector;","uniform vec2 offsetVector;","varying vec2 vTextureCoord;","varying float vColor;","const vec2 center = vec2(-1.0, 1.0);","void main(void) {"," gl_Position = vec4( ((aVertexPosition + offsetVector) / projectionVector) + center , 0.0, 1.0);"," vTextureCoord = aTextureCoord;"," vColor = aColor;","}"],b.PrimitiveShader=function(){this.program=null,this.fragmentSrc=["precision mediump float;","varying vec4 vColor;","void main(void) {"," gl_FragColor = vColor;","}"],this.vertexSrc=["attribute vec2 aVertexPosition;","attribute vec4 aColor;","uniform mat3 translationMatrix;","uniform vec2 projectionVector;","uniform vec2 offsetVector;","uniform float alpha;","varying vec4 vColor;","void main(void) {"," vec3 v = translationMatrix * vec3(aVertexPosition , 1.0);"," v -= offsetVector.xyx;"," gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / -projectionVector.y + 1.0 , 0.0, 1.0);"," vColor = aColor * alpha;","}"]},b.PrimitiveShader.prototype.init=function(){var a=b.compileProgram(this.vertexSrc,this.fragmentSrc),c=b.gl;c.useProgram(a),this.projectionVector=c.getUniformLocation(a,"projectionVector"),this.offsetVector=c.getUniformLocation(a,"offsetVector"),this.aVertexPosition=c.getAttribLocation(a,"aVertexPosition"),this.colorAttribute=c.getAttribLocation(a,"aColor"),this.translationMatrix=c.getUniformLocation(a,"translationMatrix"),this.alpha=c.getUniformLocation(a,"alpha"),this.program=a},b.StripShader=function(){this.program=null,this.fragmentSrc=["precision mediump float;","varying vec2 vTextureCoord;","varying float vColor;","uniform float alpha;","uniform sampler2D uSampler;","void main(void) {"," gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));"," gl_FragColor = gl_FragColor * alpha;","}"],this.vertexSrc=["attribute vec2 aVertexPosition;","attribute vec2 aTextureCoord;","attribute float aColor;","uniform mat3 translationMatrix;","uniform vec2 projectionVector;","uniform vec2 offsetVector;","varying vec2 vTextureCoord;","varying float vColor;","void main(void) {"," vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);"," v -= offsetVector.xyx;"," gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / projectionVector.y + 1.0 , 0.0, 1.0);"," vTextureCoord = aTextureCoord;"," vColor = aColor;","}"]},b.StripShader.prototype.init=function(){var a=b.compileProgram(this.vertexSrc,this.fragmentSrc),c=b.gl;c.useProgram(a),this.uSampler=c.getUniformLocation(a,"uSampler"),this.projectionVector=c.getUniformLocation(a,"projectionVector"),this.offsetVector=c.getUniformLocation(a,"offsetVector"),this.colorAttribute=c.getAttribLocation(a,"aColor"),this.aVertexPosition=c.getAttribLocation(a,"aVertexPosition"),this.aTextureCoord=c.getAttribLocation(a,"aTextureCoord"),this.translationMatrix=c.getUniformLocation(a,"translationMatrix"),this.alpha=c.getUniformLocation(a,"alpha"),this.program=a},b._batchs=[],b._getBatch=function(a){return 0===b._batchs.length?new b.WebGLBatch(a):b._batchs.pop()},b._returnBatch=function(a){a.clean(),b._batchs.push(a)},b._restoreBatchs=function(a){for(var c=0;cc;c++){var d=6*c,e=4*c;this.indices[d+0]=e+0,this.indices[d+1]=e+1,this.indices[d+2]=e+2,this.indices[d+3]=e+0,this.indices[d+4]=e+2,this.indices[d+5]=e+3}a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this.indexBuffer),a.bufferData(a.ELEMENT_ARRAY_BUFFER,this.indices,a.STATIC_DRAW)},b.WebGLBatch.prototype.refresh=function(){this.dynamicSizethis.width&&(f.width=this.width),f.y<0&&(f.y=0),f.height>this.height&&(f.height=this.height),c.bindFramebuffer(c.FRAMEBUFFER,e.frameBuffer),c.viewport(0,0,f.width,f.height),b.projection.x=f.width/2,b.projection.y=-f.height/2,b.offset.x=-f.x,b.offset.y=-f.y,c.uniform2f(b.defaultShader.projectionVector,f.width/2,-f.height/2),c.uniform2f(b.defaultShader.offsetVector,-f.x,-f.y),c.colorMask(!0,!0,!0,!0),c.clearColor(0,0,0,0),c.clear(c.COLOR_BUFFER_BIT),a._glFilterTexture=e},b.WebGLFilterManager.prototype.popFilter=function(){var a=b.gl,c=this.filterStack.pop(),d=c.target.filterArea,e=c._glFilterTexture;if(c.filterPasses.length>1){a.viewport(0,0,d.width,d.height),a.bindBuffer(a.ARRAY_BUFFER,this.vertexBuffer),this.vertexArray[0]=0,this.vertexArray[1]=d.height,this.vertexArray[2]=d.width,this.vertexArray[3]=d.height,this.vertexArray[4]=0,this.vertexArray[5]=0,this.vertexArray[6]=d.width,this.vertexArray[7]=0,a.bufferSubData(a.ARRAY_BUFFER,0,this.vertexArray),a.bindBuffer(a.ARRAY_BUFFER,this.uvBuffer),this.uvArray[2]=d.width/this.width,this.uvArray[5]=d.height/this.height,this.uvArray[6]=d.width/this.width,this.uvArray[7]=d.height/this.height,a.bufferSubData(a.ARRAY_BUFFER,0,this.uvArray);var f=e,g=this.texturePool.pop();g||(g=new b.FilterTexture(this.width,this.height)),a.bindFramebuffer(a.FRAMEBUFFER,g.frameBuffer),a.clear(a.COLOR_BUFFER_BIT),a.disable(a.BLEND);for(var h=0;hs?s:E,E=E>t?t:E,E=E>u?u:E,E=E>v?v:E,F=F>w?w:F,F=F>x?x:F,F=F>y?y:F,F=F>z?z:F,C=s>C?s:C,C=t>C?t:C,C=u>C?u:C,C=v>C?v:C,D=w>D?w:D,D=x>D?x:D,D=y>D?y:D,D=z>D?z:D),l=!1,A=A._iNext}while(A!==B);a.filterArea.x=E,a.filterArea.y=F,a.filterArea.width=C-E,a.filterArea.height=D-F},b.FilterTexture=function(a,c){var d=b.gl;this.frameBuffer=d.createFramebuffer(),this.texture=d.createTexture(),d.bindTexture(d.TEXTURE_2D,this.texture),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MAG_FILTER,d.LINEAR),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MIN_FILTER,d.LINEAR),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_S,d.CLAMP_TO_EDGE),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_T,d.CLAMP_TO_EDGE),d.bindFramebuffer(d.FRAMEBUFFER,this.framebuffer),d.bindFramebuffer(d.FRAMEBUFFER,this.frameBuffer),d.framebufferTexture2D(d.FRAMEBUFFER,d.COLOR_ATTACHMENT0,d.TEXTURE_2D,this.texture,0),this.resize(a,c)},b.FilterTexture.prototype.resize=function(a,c){if(this.width!==a||this.height!==c){this.width=a,this.height=c;var d=b.gl;d.bindTexture(d.TEXTURE_2D,this.texture),d.texImage2D(d.TEXTURE_2D,0,d.RGBA,a,c,0,d.RGBA,d.UNSIGNED_BYTE,null)}},b.WebGLGraphics=function(){},b.WebGLGraphics.renderGraphics=function(a,c){var d=b.gl;a._webGL||(a._webGL={points:[],indices:[],lastIndex:0,buffer:d.createBuffer(),indexBuffer:d.createBuffer()}),a.dirty&&(a.dirty=!1,a.clearDirty&&(a.clearDirty=!1,a._webGL.lastIndex=0,a._webGL.points=[],a._webGL.indices=[]),b.WebGLGraphics.updateGraphics(a)),b.activatePrimitiveShader();var e=b.mat3.clone(a.worldTransform);b.mat3.transpose(e),d.blendFunc(d.ONE,d.ONE_MINUS_SRC_ALPHA),d.uniformMatrix3fv(b.primitiveShader.translationMatrix,!1,e),d.uniform2f(b.primitiveShader.projectionVector,c.x,-c.y),d.uniform2f(b.primitiveShader.offsetVector,-b.offset.x,-b.offset.y),d.uniform1f(b.primitiveShader.alpha,a.worldAlpha),d.bindBuffer(d.ARRAY_BUFFER,a._webGL.buffer),d.vertexAttribPointer(b.primitiveShader.aVertexPosition,2,d.FLOAT,!1,24,0),d.vertexAttribPointer(b.primitiveShader.colorAttribute,4,d.FLOAT,!1,24,8),d.bindBuffer(d.ELEMENT_ARRAY_BUFFER,a._webGL.indexBuffer),d.drawElements(d.TRIANGLE_STRIP,a._webGL.indices.length,d.UNSIGNED_SHORT,0),b.deactivatePrimitiveShader()},b.WebGLGraphics.updateGraphics=function(a){for(var c=a._webGL.lastIndex;c3&&b.WebGLGraphics.buildPoly(d,a._webGL),d.lineWidth>0&&b.WebGLGraphics.buildLine(d,a._webGL)):d.type===b.Graphics.RECT?b.WebGLGraphics.buildRectangle(d,a._webGL):d.type===b.Graphics.CIRC||d.type===b.Graphics.ELIP,b.WebGLGraphics.buildCircle(d,a._webGL)}a._webGL.lastIndex=a.graphicsData.length;var e=b.gl;a._webGL.glPoints=new Float32Array(a._webGL.points),e.bindBuffer(e.ARRAY_BUFFER,a._webGL.buffer),e.bufferData(e.ARRAY_BUFFER,a._webGL.glPoints,e.STATIC_DRAW),a._webGL.glIndicies=new Uint16Array(a._webGL.indices),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,a._webGL.indexBuffer),e.bufferData(e.ELEMENT_ARRAY_BUFFER,a._webGL.glIndicies,e.STATIC_DRAW)},b.WebGLGraphics.buildRectangle=function(a,c){var d=a.points,e=d[0],f=d[1],g=d[2],h=d[3];if(a.fill){var i=b.hex2rgb(a.fillColor),j=a.fillAlpha,k=i[0]*j,l=i[1]*j,m=i[2]*j,n=c.points,o=c.indices,p=n.length/6;n.push(e,f),n.push(k,l,m,j),n.push(e+g,f),n.push(k,l,m,j),n.push(e,f+h),n.push(k,l,m,j),n.push(e+g,f+h),n.push(k,l,m,j),o.push(p,p,p+1,p+2,p+3,p+3)}a.lineWidth&&(a.points=[e,f,e+g,f,e+g,f+h,e,f+h,e,f],b.WebGLGraphics.buildLine(a,c))},b.WebGLGraphics.buildCircle=function(a,c){var d=a.points,e=d[0],f=d[1],g=d[2],h=d[3],i=40,j=2*Math.PI/i,k=0;if(a.fill){var l=b.hex2rgb(a.fillColor),m=a.fillAlpha,n=l[0]*m,o=l[1]*m,p=l[2]*m,q=c.points,r=c.indices,s=q.length/6;for(r.push(s),k=0;i+1>k;k++)q.push(e,f,n,o,p,m),q.push(e+Math.sin(j*k)*g,f+Math.cos(j*k)*h,n,o,p,m),r.push(s++,s++);r.push(s-1)}if(a.lineWidth){for(a.points=[],k=0;i+1>k;k++)a.points.push(e+Math.sin(j*k)*g,f+Math.cos(j*k)*h);b.WebGLGraphics.buildLine(a,c)}},b.WebGLGraphics.buildLine=function(a,c){var d=0,e=a.points;if(0!==e.length){if(a.lineWidth%2)for(d=0;dd;d++)l=e[2*(d-1)],m=e[2*(d-1)+1],n=e[2*d],o=e[2*d+1],p=e[2*(d+1)],q=e[2*(d+1)+1],r=-(m-o),s=l-n,F=Math.sqrt(r*r+s*s),r/=F,s/=F,r*=L,s*=L,t=-(o-q),u=n-p,F=Math.sqrt(t*t+u*u),t/=F,u/=F,t*=L,u*=L,x=-s+m-(-s+o),y=-r+n-(-r+l),z=(-r+l)*(-s+o)-(-r+n)*(-s+m),A=-u+q-(-u+o),B=-t+n-(-t+p),C=(-t+p)*(-u+o)-(-t+n)*(-u+q),D=x*B-A*y,Math.abs(D)<.1?(D+=10.1,G.push(n-r,o-s,O,P,Q,N),G.push(n+r,o+s,O,P,Q,N)):(j=(y*C-B*z)/D,k=(A*z-x*C)/D,E=(j-n)*(j-n)+(k-o)+(k-o),E>19600?(v=r-t,w=s-u,F=Math.sqrt(v*v+w*w),v/=F,w/=F,v*=L,w*=L,G.push(n-v,o-w),G.push(O,P,Q,N),G.push(n+v,o+w),G.push(O,P,Q,N),G.push(n-v,o-w),G.push(O,P,Q,N),J++):(G.push(j,k),G.push(O,P,Q,N),G.push(n-(j-n),o-(k-o)),G.push(O,P,Q,N)));for(l=e[2*(I-2)],m=e[2*(I-2)+1],n=e[2*(I-1)],o=e[2*(I-1)+1],r=-(m-o),s=l-n,F=Math.sqrt(r*r+s*s),r/=F,s/=F,r*=L,s*=L,G.push(n-r,o-s),G.push(O,P,Q,N),G.push(n+r,o+s),G.push(O,P,Q,N),H.push(K),d=0;J>d;d++)H.push(K++);H.push(K-1)}},b.WebGLGraphics.buildPoly=function(a,c){var d=a.points;if(!(d.length<6)){var e=c.points,f=c.indices,g=d.length/2,h=b.hex2rgb(a.fillColor),i=a.fillAlpha,j=h[0]*i,k=h[1]*i,l=h[2]*i,m=b.PolyK.Triangulate(d),n=e.length/6,o=0;for(o=0;oo;o++)e.push(d[2*o],d[2*o+1],j,k,l,i)}},b._defaultFrame=new b.Rectangle(0,0,1,1),b.gl=null,b.WebGLRenderer=function(a,c,d,e,f){this.transparent=!!e,this.width=a||800,this.height=c||600,this.view=d||document.createElement("canvas"),this.view.width=this.width,this.view.height=this.height;var g=this;this.view.addEventListener("webglcontextlost",function(a){g.handleContextLost(a)},!1),this.view.addEventListener("webglcontextrestored",function(a){g.handleContextRestored(a)},!1),this.batchs=[];var h={alpha:this.transparent,antialias:!!f,premultipliedAlpha:!1,stencil:!0};try{b.gl=this.gl=this.view.getContext("experimental-webgl",h)}catch(i){try{b.gl=this.gl=this.view.getContext("webgl",h)}catch(j){throw new Error(" This browser does not support webGL. Try using the canvas renderer"+this)}}b.initDefaultShaders();var k=this.gl;k.useProgram(b.defaultShader.program),b.WebGLRenderer.gl=k,this.batch=new b.WebGLBatch(k),k.disable(k.DEPTH_TEST),k.disable(k.CULL_FACE),k.enable(k.BLEND),k.colorMask(!0,!0,!0,this.transparent),b.projection=new b.Point(400,300),b.offset=new b.Point(0,0),this.resize(this.width,this.height),this.contextLost=!1,this.stageRenderGroup=new b.WebGLRenderGroup(this.gl,this.transparent)},b.WebGLRenderer.prototype.constructor=b.WebGLRenderer,b.WebGLRenderer.getBatch=function(){return 0===b._batchs.length?new b.WebGLBatch(b.WebGLRenderer.gl):b._batchs.pop()},b.WebGLRenderer.returnBatch=function(a){a.clean(),b._batchs.push(a)},b.WebGLRenderer.prototype.render=function(a){if(!this.contextLost){this.__stage!==a&&(this.__stage=a,this.stageRenderGroup.setRenderable(a)),b.WebGLRenderer.updateTextures(),b.visibleCount++,a.updateTransform();var c=this.gl;if(c.colorMask(!0,!0,!0,this.transparent),c.viewport(0,0,this.width,this.height),c.bindFramebuffer(c.FRAMEBUFFER,null),c.clearColor(a.backgroundColorSplit[0],a.backgroundColorSplit[1],a.backgroundColorSplit[2],!this.transparent),c.clear(c.COLOR_BUFFER_BIT),this.stageRenderGroup.backgroundColor=a.backgroundColorSplit,b.projection.x=this.width/2,b.projection.y=-this.height/2,this.stageRenderGroup.render(b.projection),a.interactive&&(a._interactiveEventsAdded||(a._interactiveEventsAdded=!0,a.interactionManager.setTarget(this))),b.Texture.frameUpdates.length>0){for(var d=0;dn;n++)renderable=this.batchs[n],renderable instanceof b.WebGLBatch?this.batchs[n].render():this.renderSpecial(renderable,c);endBatch instanceof b.WebGLBatch?endBatch.render(0,h+1):this.renderSpecial(endBatch,c)},b.WebGLRenderGroup.prototype.renderSpecial=function(a,c){var d=a.vcount===b.visibleCount;a instanceof b.TilingSprite?d&&this.renderTilingSprite(a,c):a instanceof b.Strip?d&&this.renderStrip(a,c):a instanceof b.CustomRenderable?d&&a.renderWebGL(this,c):a instanceof b.Graphics?d&&a.renderable&&b.WebGLGraphics.renderGraphics(a,c):a instanceof b.FilterBlock&&this.handleFilterBlock(a,c)},flip=!1;var d=[],e=0;return b.WebGLRenderGroup.prototype.handleFilterBlock=function(a,c){var f=b.gl;if(a.open)a.data instanceof Array?this.filterManager.pushFilter(a):(e++,d.push(a),f.enable(f.STENCIL_TEST),f.colorMask(!1,!1,!1,!1),f.stencilFunc(f.ALWAYS,1,1),f.stencilOp(f.KEEP,f.KEEP,f.INCR),b.WebGLGraphics.renderGraphics(a.data,c),f.colorMask(!0,!0,!0,!0),f.stencilFunc(f.NOTEQUAL,0,d.length),f.stencilOp(f.KEEP,f.KEEP,f.KEEP));else if(a.data instanceof Array)this.filterManager.popFilter();else{var g=d.pop(a);g&&(f.colorMask(!1,!1,!1,!1),f.stencilFunc(f.ALWAYS,1,1),f.stencilOp(f.KEEP,f.KEEP,f.DECR),b.WebGLGraphics.renderGraphics(g.data,c),f.colorMask(!0,!0,!0,!0),f.stencilFunc(f.NOTEQUAL,0,d.length),f.stencilOp(f.KEEP,f.KEEP,f.KEEP)),f.disable(f.STENCIL_TEST)}},b.WebGLRenderGroup.prototype.updateTexture=function(a){this.removeObject(a);for(var b=a.first;b!=this.root&&(b=b._iPrev,!b.renderable||!b.__renderGroup););for(var c=a.last;c._iNext&&(c=c._iNext,!c.renderable||!c.__renderGroup););this.insertObject(a,b,c)},b.WebGLRenderGroup.prototype.addFilterBlocks=function(a,b){a.__renderGroup=this,b.__renderGroup=this;for(var c=a;c!=this.root.first&&(c=c._iPrev,!c.renderable||!c.__renderGroup););this.insertAfter(a,c);for(var d=b;d!=this.root.first&&(d=d._iPrev,!d.renderable||!d.__renderGroup););this.insertAfter(b,d)},b.WebGLRenderGroup.prototype.removeFilterBlocks=function(a,b){this.removeObject(a),this.removeObject(b)},b.WebGLRenderGroup.prototype.addDisplayObjectAndChildren=function(a){a.__renderGroup&&a.__renderGroup.removeDisplayObjectAndChildren(a);for(var b=a.first;b!=this.root.first&&(b=b._iPrev,!b.renderable||!b.__renderGroup););for(var c=a.last;c._iNext&&(c=c._iNext,!c.renderable||!c.__renderGroup););var d=a.first,e=a.last._iNext;do d.__renderGroup=this,d.renderable&&(this.insertObject(d,b,c),b=d),d=d._iNext;while(d!=e)},b.WebGLRenderGroup.prototype.removeDisplayObjectAndChildren=function(a){if(a.__renderGroup==this){a.last;do a.__renderGroup=null,a.renderable&&this.removeObject(a),a=a._iNext;while(a)}},b.WebGLRenderGroup.prototype.insertObject=function(a,c,d){var e=c,f=d;if(a instanceof b.Sprite){var g,h;if(e instanceof b.Sprite){if(g=e.batch,g&&g.texture==a.texture.baseTexture&&g.blendMode==a.blendMode)return g.insertAfter(a,e),void 0}else g=e;if(f)if(f instanceof b.Sprite){if(h=f.batch){if(h.texture==a.texture.baseTexture&&h.blendMode==a.blendMode)return h.insertBefore(a,f),void 0;if(h==g){var i=g.split(f),j=b.WebGLRenderer.getBatch(),k=this.batchs.indexOf(g);return j.init(a),this.batchs.splice(k+1,0,j,i),void 0}}}else h=f;var j=b.WebGLRenderer.getBatch();if(j.init(a),g){var k=this.batchs.indexOf(g);this.batchs.splice(k+1,0,j)}else this.batchs.push(j)}else a instanceof b.TilingSprite?this.initTilingSprite(a):a instanceof b.Strip&&this.initStrip(a),this.insertAfter(a,e)},b.WebGLRenderGroup.prototype.insertAfter=function(a,c){if(c instanceof b.Sprite){var d=c.batch;if(d)if(d.tail==c){var e=this.batchs.indexOf(d);this.batchs.splice(e+1,0,a)}else{var f=d.split(c.__next),e=this.batchs.indexOf(d);this.batchs.splice(e+1,0,a,f)}else this.batchs.push(a)}else{var e=this.batchs.indexOf(c);this.batchs.splice(e+1,0,a)}},b.WebGLRenderGroup.prototype.removeObject=function(a){var c;if(a instanceof b.Sprite){var d=a.batch;if(!d)return;d.remove(a),0==d.size&&(c=d)}else c=a;if(c){var e=this.batchs.indexOf(c);if(-1==e)return;if(0==e||e==this.batchs.length-1)return this.batchs.splice(e,1),c instanceof b.WebGLBatch&&b.WebGLRenderer.returnBatch(c),void 0;if(this.batchs[e-1]instanceof b.WebGLBatch&&this.batchs[e+1]instanceof b.WebGLBatch&&this.batchs[e-1].texture==this.batchs[e+1].texture&&this.batchs[e-1].blendMode==this.batchs[e+1].blendMode)return this.batchs[e-1].merge(this.batchs[e+1]),c instanceof b.WebGLBatch&&b.WebGLRenderer.returnBatch(c),b.WebGLRenderer.returnBatch(this.batchs[e+1]),this.batchs.splice(e,2),void 0;this.batchs.splice(e,1),c instanceof b.WebGLBatch&&b.WebGLRenderer.returnBatch(c)}},b.WebGLRenderGroup.prototype.initTilingSprite=function(a){var b=this.gl;a.verticies=new Float32Array([0,0,a.width,0,a.width,a.height,0,a.height]),a.uvs=new Float32Array([0,0,1,0,1,1,0,1]),a.colors=new Float32Array([1,1,1,1]),a.indices=new Uint16Array([0,1,3,2]),a._vertexBuffer=b.createBuffer(),a._indexBuffer=b.createBuffer(),a._uvBuffer=b.createBuffer(),a._colorBuffer=b.createBuffer(),b.bindBuffer(b.ARRAY_BUFFER,a._vertexBuffer),b.bufferData(b.ARRAY_BUFFER,a.verticies,b.STATIC_DRAW),b.bindBuffer(b.ARRAY_BUFFER,a._uvBuffer),b.bufferData(b.ARRAY_BUFFER,a.uvs,b.DYNAMIC_DRAW),b.bindBuffer(b.ARRAY_BUFFER,a._colorBuffer),b.bufferData(b.ARRAY_BUFFER,a.colors,b.STATIC_DRAW),b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,a._indexBuffer),b.bufferData(b.ELEMENT_ARRAY_BUFFER,a.indices,b.STATIC_DRAW),a.texture.baseTexture._glTexture?(b.bindTexture(b.TEXTURE_2D,a.texture.baseTexture._glTexture),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,b.REPEAT),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,b.REPEAT),a.texture.baseTexture._powerOf2=!0):a.texture.baseTexture._powerOf2=!0},b.WebGLRenderGroup.prototype.renderStrip=function(a,c){var d=this.gl;b.activateStripShader();var e=b.stripShader;e.program;var f=b.mat3.clone(a.worldTransform); +b.mat3.transpose(f),d.uniformMatrix3fv(e.translationMatrix,!1,f),d.uniform2f(e.projectionVector,c.x,c.y),d.uniform2f(e.offsetVector,-b.offset.x,-b.offset.y),d.uniform1f(e.alpha,a.worldAlpha),a.dirty?(a.dirty=!1,d.bindBuffer(d.ARRAY_BUFFER,a._vertexBuffer),d.bufferData(d.ARRAY_BUFFER,a.verticies,d.STATIC_DRAW),d.vertexAttribPointer(e.aVertexPosition,2,d.FLOAT,!1,0,0),d.bindBuffer(d.ARRAY_BUFFER,a._uvBuffer),d.bufferData(d.ARRAY_BUFFER,a.uvs,d.STATIC_DRAW),d.vertexAttribPointer(e.aTextureCoord,2,d.FLOAT,!1,0,0),d.activeTexture(d.TEXTURE0),d.bindTexture(d.TEXTURE_2D,a.texture.baseTexture._glTexture),d.bindBuffer(d.ARRAY_BUFFER,a._colorBuffer),d.bufferData(d.ARRAY_BUFFER,a.colors,d.STATIC_DRAW),d.vertexAttribPointer(e.colorAttribute,1,d.FLOAT,!1,0,0),d.bindBuffer(d.ELEMENT_ARRAY_BUFFER,a._indexBuffer),d.bufferData(d.ELEMENT_ARRAY_BUFFER,a.indices,d.STATIC_DRAW)):(d.bindBuffer(d.ARRAY_BUFFER,a._vertexBuffer),d.bufferSubData(d.ARRAY_BUFFER,0,a.verticies),d.vertexAttribPointer(e.aVertexPosition,2,d.FLOAT,!1,0,0),d.bindBuffer(d.ARRAY_BUFFER,a._uvBuffer),d.vertexAttribPointer(e.aTextureCoord,2,d.FLOAT,!1,0,0),d.activeTexture(d.TEXTURE0),d.bindTexture(d.TEXTURE_2D,a.texture.baseTexture._glTexture),d.bindBuffer(d.ARRAY_BUFFER,a._colorBuffer),d.vertexAttribPointer(e.colorAttribute,1,d.FLOAT,!1,0,0),d.bindBuffer(d.ELEMENT_ARRAY_BUFFER,a._indexBuffer)),d.drawElements(d.TRIANGLE_STRIP,a.indices.length,d.UNSIGNED_SHORT,0),b.deactivateStripShader()},b.WebGLRenderGroup.prototype.renderTilingSprite=function(a,c){var d=this.gl;b.shaderProgram;var e=a.tilePosition,f=a.tileScale,g=e.x/a.texture.baseTexture.width,h=e.y/a.texture.baseTexture.height,i=a.width/a.texture.baseTexture.width/f.x,j=a.height/a.texture.baseTexture.height/f.y;a.uvs[0]=0-g,a.uvs[1]=0-h,a.uvs[2]=1*i-g,a.uvs[3]=0-h,a.uvs[4]=1*i-g,a.uvs[5]=1*j-h,a.uvs[6]=0-g,a.uvs[7]=1*j-h,d.bindBuffer(d.ARRAY_BUFFER,a._uvBuffer),d.bufferSubData(d.ARRAY_BUFFER,0,a.uvs),this.renderStrip(a,c)},b.WebGLRenderGroup.prototype.initStrip=function(a){var b=this.gl;this.shaderProgram,a._vertexBuffer=b.createBuffer(),a._indexBuffer=b.createBuffer(),a._uvBuffer=b.createBuffer(),a._colorBuffer=b.createBuffer(),b.bindBuffer(b.ARRAY_BUFFER,a._vertexBuffer),b.bufferData(b.ARRAY_BUFFER,a.verticies,b.DYNAMIC_DRAW),b.bindBuffer(b.ARRAY_BUFFER,a._uvBuffer),b.bufferData(b.ARRAY_BUFFER,a.uvs,b.STATIC_DRAW),b.bindBuffer(b.ARRAY_BUFFER,a._colorBuffer),b.bufferData(b.ARRAY_BUFFER,a.colors,b.STATIC_DRAW),b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,a._indexBuffer),b.bufferData(b.ELEMENT_ARRAY_BUFFER,a.indices,b.STATIC_DRAW)},b.initDefaultShaders=function(){b.primitiveShader=new b.PrimitiveShader,b.primitiveShader.init(),b.stripShader=new b.StripShader,b.stripShader.init(),b.defaultShader=new b.PixiShader,b.defaultShader.init();var a=b.gl,c=b.defaultShader.program;a.useProgram(c),a.enableVertexAttribArray(b.defaultShader.aVertexPosition),a.enableVertexAttribArray(b.defaultShader.colorAttribute),a.enableVertexAttribArray(b.defaultShader.aTextureCoord)},b.activatePrimitiveShader=function(){var a=b.gl;a.useProgram(b.primitiveShader.program),a.disableVertexAttribArray(b.defaultShader.aVertexPosition),a.disableVertexAttribArray(b.defaultShader.colorAttribute),a.disableVertexAttribArray(b.defaultShader.aTextureCoord),a.enableVertexAttribArray(b.primitiveShader.aVertexPosition),a.enableVertexAttribArray(b.primitiveShader.colorAttribute)},b.deactivatePrimitiveShader=function(){var a=b.gl;a.useProgram(b.defaultShader.program),a.disableVertexAttribArray(b.primitiveShader.aVertexPosition),a.disableVertexAttribArray(b.primitiveShader.colorAttribute),a.enableVertexAttribArray(b.defaultShader.aVertexPosition),a.enableVertexAttribArray(b.defaultShader.colorAttribute),a.enableVertexAttribArray(b.defaultShader.aTextureCoord)},b.activateStripShader=function(){var a=b.gl;a.useProgram(b.stripShader.program)},b.deactivateStripShader=function(){var a=b.gl;a.useProgram(b.defaultShader.program)},b.CompileVertexShader=function(a,c){return b._CompileShader(a,c,a.VERTEX_SHADER)},b.CompileFragmentShader=function(a,c){return b._CompileShader(a,c,a.FRAGMENT_SHADER)},b._CompileShader=function(a,b,c){var d=b.join("\n"),e=a.createShader(c);return a.shaderSource(e,d),a.compileShader(e),a.getShaderParameter(e,a.COMPILE_STATUS)?e:(window.console.log(a.getShaderInfoLog(e)),null)},b.compileProgram=function(a,c){var d=b.gl,e=b.CompileFragmentShader(d,c),f=b.CompileVertexShader(d,a),g=d.createProgram();return d.attachShader(g,f),d.attachShader(g,e),d.linkProgram(g),d.getProgramParameter(g,d.LINK_STATUS)||window.console.log("Could not initialise shaders"),g},b.BitmapText=function(a,c){b.DisplayObjectContainer.call(this),this.setText(a),this.setStyle(c),this.updateText(),this.dirty=!1},b.BitmapText.prototype=Object.create(b.DisplayObjectContainer.prototype),b.BitmapText.prototype.constructor=b.BitmapText,b.BitmapText.prototype.setText=function(a){this.text=a||" ",this.dirty=!0},b.BitmapText.prototype.setStyle=function(a){a=a||{},a.align=a.align||"left",this.style=a;var c=a.font.split(" ");this.fontName=c[c.length-1],this.fontSize=c.length>=2?parseInt(c[c.length-2],10):b.BitmapText.fonts[this.fontName].size,this.dirty=!0},b.BitmapText.prototype.updateText=function(){for(var a=b.BitmapText.fonts[this.fontName],c=new b.Point,d=null,e=[],f=0,g=[],h=0,i=this.fontSize/a.size,j=0;j=j;j++){var n=0;"right"===this.style.align?n=f-g[j]:"center"===this.style.align&&(n=(f-g[j])/2),m.push(n)}for(j=0;j0;)this.removeChild(this.getChildAt(0));this.updateText(),this.dirty=!1}b.DisplayObjectContainer.prototype.updateTransform.call(this)},b.BitmapText.fonts={},b.Text=function(a,c){this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),b.Sprite.call(this,b.Texture.fromCanvas(this.canvas)),this.setText(a),this.setStyle(c),this.updateText(),this.dirty=!1},b.Text.prototype=Object.create(b.Sprite.prototype),b.Text.prototype.constructor=b.Text,b.Text.prototype.setStyle=function(a){a=a||{},a.font=a.font||"bold 20pt Arial",a.fill=a.fill||"black",a.align=a.align||"left",a.stroke=a.stroke||"black",a.strokeThickness=a.strokeThickness||0,a.wordWrap=a.wordWrap||!1,a.wordWrapWidth=a.wordWrapWidth||100,this.style=a,this.dirty=!0},b.Text.prototype.setText=function(a){this.text=a.toString()||" ",this.dirty=!0},b.Text.prototype.updateText=function(){this.context.font=this.style.font;var a=this.text;this.style.wordWrap&&(a=this.wordWrap(this.text));for(var c=a.split(/(?:\r\n|\r|\n)/),d=[],e=0,f=0;fe?(g>0&&(b+="\n"),b+=f[g]+" ",e=this.style.wordWrapWidth-h):(e-=i,b+=f[g]+" ")}b+="\n"}return b},b.Text.prototype.destroy=function(a){a&&this.texture.destroy()},b.Text.heightCache={},b.BaseTextureCache={},b.texturesToUpdate=[],b.texturesToDestroy=[],b.BaseTexture=function(a,c){if(b.EventTarget.call(this),this.width=100,this.height=100,this.scaleMode=c||b.BaseTexture.SCALE_MODE.DEFAULT,this.hasLoaded=!1,this.source=a,a){if(this.source instanceof Image||this.source instanceof HTMLImageElement)if(this.source.complete)this.hasLoaded=!0,this.width=this.source.width,this.height=this.source.height,b.texturesToUpdate.push(this);else{var d=this;this.source.onload=function(){d.hasLoaded=!0,d.width=d.source.width,d.height=d.source.height,b.texturesToUpdate.push(d),d.dispatchEvent({type:"loaded",content:d})}}else this.hasLoaded=!0,this.width=this.source.width,this.height=this.source.height,b.texturesToUpdate.push(this);this.imageUrl=null,this._powerOf2=!1}},b.BaseTexture.prototype.constructor=b.BaseTexture,b.BaseTexture.prototype.destroy=function(){this.source instanceof Image&&(this.imageUrl in b.BaseTextureCache&&delete b.BaseTextureCache[this.imageUrl],this.imageUrl=null,this.source.src=null),this.source=null,b.texturesToDestroy.push(this)},b.BaseTexture.prototype.updateSourceImage=function(a){this.hasLoaded=!1,this.source.src=null,this.source.src=a},b.BaseTexture.fromImage=function(a,c,d){var e=b.BaseTextureCache[a];if(!e){var f=new Image;c&&(f.crossOrigin=""),f.src=a,e=new b.BaseTexture(f,d),e.imageUrl=a,b.BaseTextureCache[a]=e}return e},b.BaseTexture.SCALE_MODE={DEFAULT:0,LINEAR:0,NEAREST:1},b.TextureCache={},b.FrameCache={},b.Texture=function(a,c){if(b.EventTarget.call(this),c||(this.noFrame=!0,c=new b.Rectangle(0,0,1,1)),a instanceof b.Texture&&(a=a.baseTexture),this.baseTexture=a,this.frame=c,this.trim=new b.Point,this.scope=this,a.hasLoaded)this.noFrame&&(c=new b.Rectangle(0,0,a.width,a.height)),this.setFrame(c);else{var d=this;a.addEventListener("loaded",function(){d.onBaseTextureLoaded()})}},b.Texture.prototype.constructor=b.Texture,b.Texture.prototype.onBaseTextureLoaded=function(){var a=this.baseTexture;a.removeEventListener("loaded",this.onLoaded),this.noFrame&&(this.frame=new b.Rectangle(0,0,a.width,a.height)),this.noFrame=!1,this.width=this.frame.width,this.height=this.frame.height,this.scope.dispatchEvent({type:"update",content:this})},b.Texture.prototype.destroy=function(a){a&&this.baseTexture.destroy()},b.Texture.prototype.setFrame=function(a){if(this.frame=a,this.width=a.width,this.height=a.height,a.x+a.width>this.baseTexture.width||a.y+a.height>this.baseTexture.height)throw new Error("Texture Error: frame does not fit inside the base Texture dimensions "+this);this.updateFrame=!0,b.Texture.frameUpdates.push(this)},b.Texture.fromImage=function(a,c,d){var e=b.TextureCache[a];return e||(e=new b.Texture(b.BaseTexture.fromImage(a,c,d)),b.TextureCache[a]=e),e},b.Texture.fromFrame=function(a){var c=b.TextureCache[a];if(!c)throw new Error('The frameId "'+a+'" does not exist in the texture cache '+this);return c},b.Texture.fromCanvas=function(a,c){var d=new b.BaseTexture(a,c);return new b.Texture(d)},b.Texture.addTextureToCache=function(a,c){b.TextureCache[c]=a},b.Texture.removeTextureFromCache=function(a){var c=b.TextureCache[a];return b.TextureCache[a]=null,c},b.Texture.frameUpdates=[],b.Texture.SCALE_MODE=b.BaseTexture.SCALE_MODE,b.RenderTexture=function(a,c){b.EventTarget.call(this),this.width=a||100,this.height=c||100,this.indetityMatrix=b.mat3.create(),this.frame=new b.Rectangle(0,0,this.width,this.height),b.gl?this.initWebGL():this.initCanvas()},b.RenderTexture.prototype=Object.create(b.Texture.prototype),b.RenderTexture.prototype.constructor=b.RenderTexture,b.RenderTexture.prototype.initWebGL=function(){var a=b.gl;this.glFramebuffer=a.createFramebuffer(),a.bindFramebuffer(a.FRAMEBUFFER,this.glFramebuffer),this.glFramebuffer.width=this.width,this.glFramebuffer.height=this.height,this.baseTexture=new b.BaseTexture,this.baseTexture.width=this.width,this.baseTexture.height=this.height,this.baseTexture._glTexture=a.createTexture(),a.bindTexture(a.TEXTURE_2D,this.baseTexture._glTexture),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,this.width,this.height,0,a.RGBA,a.UNSIGNED_BYTE,null),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE),this.baseTexture.isRender=!0,a.bindFramebuffer(a.FRAMEBUFFER,this.glFramebuffer),a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,this.baseTexture._glTexture,0),this.projection=new b.Point(this.width/2,-this.height/2),this.render=this.renderWebGL},b.RenderTexture.prototype.resize=function(a,c){if(this.width=a,this.height=c,b.gl){this.projection.x=this.width/2,this.projection.y=-this.height/2;var d=b.gl;d.bindTexture(d.TEXTURE_2D,this.baseTexture._glTexture),d.texImage2D(d.TEXTURE_2D,0,d.RGBA,this.width,this.height,0,d.RGBA,d.UNSIGNED_BYTE,null)}else this.frame.width=this.width,this.frame.height=this.height,this.renderer.resize(this.width,this.height)},b.RenderTexture.prototype.initCanvas=function(){this.renderer=new b.CanvasRenderer(this.width,this.height,null,0),this.baseTexture=new b.BaseTexture(this.renderer.view),this.frame=new b.Rectangle(0,0,this.width,this.height),this.render=this.renderCanvas},b.RenderTexture.prototype.renderWebGL=function(a,c,d){var e=b.gl;e.colorMask(!0,!0,!0,!0),e.viewport(0,0,this.width,this.height),e.bindFramebuffer(e.FRAMEBUFFER,this.glFramebuffer),d&&(e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT));var f=a.children,g=a.worldTransform;a.worldTransform=b.mat3.create(),a.worldTransform[4]=-1,a.worldTransform[5]=-2*this.projection.y,c&&(a.worldTransform[2]=c.x,a.worldTransform[5]-=c.y),b.visibleCount++,a.vcount=b.visibleCount;for(var h=0,i=f.length;i>h;h++)f[h].updateTransform();var j=a.__renderGroup;j?a===j.root?j.render(this.projection,this.glFramebuffer):j.renderSpecific(a,this.projection,this.glFramebuffer):(this.renderGroup||(this.renderGroup=new b.WebGLRenderGroup(e)),this.renderGroup.setRenderable(a),this.renderGroup.render(this.projection,this.glFramebuffer)),a.worldTransform=g},b.RenderTexture.prototype.renderCanvas=function(a,c,d){var e=a.children;a.worldTransform=b.mat3.create(),c&&(a.worldTransform[2]=c.x,a.worldTransform[5]=c.y);for(var f=0,g=e.length;g>f;f++)e[f].updateTransform();d&&this.renderer.context.clearRect(0,0,this.width,this.height),this.renderer.renderDisplayObject(a),this.renderer.context.setTransform(1,0,0,1,0,0)},b.EventTarget=function(){var a={};this.addEventListener=this.on=function(b,c){void 0===a[b]&&(a[b]=[]),-1===a[b].indexOf(c)&&a[b].push(c)},this.dispatchEvent=this.emit=function(b){if(a[b.type]&&a[b.type].length)for(var c=0,d=a[b.type].length;d>c;c++)a[b.type][c](b)},this.removeEventListener=this.off=function(b,c){var d=a[b].indexOf(c);-1!==d&&a[b].splice(d,1)},this.removeAllEventListeners=function(b){var c=a[b];c&&(c.length=0)}},b.PolyK={},b.PolyK.Triangulate=function(a){var c=!0,d=a.length>>1;if(3>d)return[];for(var e=[],f=[],g=0;d>g;g++)f.push(g);g=0;for(var h=d;h>3;){var i=f[(g+0)%h],j=f[(g+1)%h],k=f[(g+2)%h],l=a[2*i],m=a[2*i+1],n=a[2*j],o=a[2*j+1],p=a[2*k],q=a[2*k+1],r=!1;if(b.PolyK._convex(l,m,n,o,p,q,c)){r=!0;for(var s=0;h>s;s++){var t=f[s];if(t!==i&&t!==j&&t!==k&&b.PolyK._PointInTriangle(a[2*t],a[2*t+1],l,m,n,o,p,q)){r=!1;break}}}if(r)e.push(i,j,k),f.splice((g+1)%h,1),h--,g=0;else if(g++>3*h){if(!c)return window.console.log("PIXI Warning: shape too complex to fill"),[];for(e=[],f=[],g=0;d>g;g++)f.push(g);g=0,h=d,c=!1}}return e.push(f[0],f[1],f[2]),e},b.PolyK._PointInTriangle=function(a,b,c,d,e,f,g,h){var i=g-c,j=h-d,k=e-c,l=f-d,m=a-c,n=b-d,o=i*i+j*j,p=i*k+j*l,q=i*m+j*n,r=k*k+l*l,s=k*m+l*n,t=1/(o*r-p*p),u=(r*q-p*s)*t,v=(o*s-p*q)*t;return u>=0&&v>=0&&1>u+v},b.PolyK._convex=function(a,b,c,d,e,f,g){return(b-d)*(e-c)+(c-a)*(f-d)>=0===g},c.Camera=function(a,b,d,e,f,g){this.game=a,this.world=a.world,this.id=0,this.view=new c.Rectangle(d,e,f,g),this.screenView=new c.Rectangle(d,e,f,g),this.bounds=new c.Rectangle(d,e,f,g),this.deadzone=null,this.visible=!0,this.atLimit={x:!1,y:!1},this.target=null,this._edge=0,this.displayObject=null},c.Camera.FOLLOW_LOCKON=0,c.Camera.FOLLOW_PLATFORMER=1,c.Camera.FOLLOW_TOPDOWN=2,c.Camera.FOLLOW_TOPDOWN_TIGHT=3,c.Camera.prototype={follow:function(a,b){"undefined"==typeof b&&(b=c.Camera.FOLLOW_LOCKON),this.target=a;var d;switch(b){case c.Camera.FOLLOW_PLATFORMER:var e=this.width/8,f=this.height/3;this.deadzone=new c.Rectangle((this.width-e)/2,(this.height-f)/2-.25*f,e,f);break;case c.Camera.FOLLOW_TOPDOWN:d=Math.max(this.width,this.height)/4,this.deadzone=new c.Rectangle((this.width-d)/2,(this.height-d)/2,d,d);break;case c.Camera.FOLLOW_TOPDOWN_TIGHT:d=Math.max(this.width,this.height)/8,this.deadzone=new c.Rectangle((this.width-d)/2,(this.height-d)/2,d,d);break;case c.Camera.FOLLOW_LOCKON:this.deadzone=null;break;default:this.deadzone=null}},focusOn:function(a){this.setPosition(Math.round(a.x-this.view.halfWidth),Math.round(a.y-this.view.halfHeight))},focusOnXY:function(a,b){this.setPosition(Math.round(a-this.view.halfWidth),Math.round(b-this.view.halfHeight))},update:function(){this.target&&this.updateTarget(),this.bounds&&this.checkBounds(),this.displayObject.position.x=-this.view.x,this.displayObject.position.y=-this.view.y},updateTarget:function(){this.deadzone?(this._edge=this.target.bounds.x-this.deadzone.x,this.view.x>this._edge&&(this.view.x=this._edge),this._edge=this.target.bounds.right-this.deadzone.x-this.deadzone.width,this.view.xthis._edge&&(this.view.y=this._edge),this._edge=this.target.bounds.bottom-this.deadzone.y-this.deadzone.height,this.view.ythis.bounds.right-this.width&&(this.atLimit.x=!0,this.view.x=this.bounds.right-this.width+1),this.view.ythis.bounds.bottom-this.height&&(this.atLimit.y=!0,this.view.y=this.bounds.bottom-this.height+1),this.view.floor()},setPosition:function(a,b){this.view.x=a,this.view.y=b,this.bounds&&this.checkBounds()},setSize:function(a,b){this.view.width=a,this.view.height=b}},c.Camera.prototype.constructor=c.Camera,Object.defineProperty(c.Camera.prototype,"x",{get:function(){return this.view.x},set:function(a){this.view.x=a,this.bounds&&this.checkBounds()}}),Object.defineProperty(c.Camera.prototype,"y",{get:function(){return this.view.y},set:function(a){this.view.y=a,this.bounds&&this.checkBounds()}}),Object.defineProperty(c.Camera.prototype,"width",{get:function(){return this.view.width},set:function(a){this.view.width=a}}),Object.defineProperty(c.Camera.prototype,"height",{get:function(){return this.view.height},set:function(a){this.view.height=a}}),c.State=function(){this.game=null,this.add=null,this.camera=null,this.cache=null,this.input=null,this.load=null,this.math=null,this.sound=null,this.stage=null,this.time=null,this.tweens=null,this.world=null,this.particles=null,this.physics=null},c.State.prototype={preload:function(){},loadUpdate:function(){},loadRender:function(){},create:function(){},update:function(){},render:function(){},paused:function(){},destroy:function(){}},c.State.prototype.constructor=c.State,c.StateManager=function(a,b){this.game=a,this.states={},this._pendingState=null,"undefined"!=typeof b&&null!==b&&(this._pendingState=b),this._created=!1,this.current="",this.onInitCallback=null,this.onPreloadCallback=null,this.onCreateCallback=null,this.onUpdateCallback=null,this.onRenderCallback=null,this.onPreRenderCallback=null,this.onLoadUpdateCallback=null,this.onLoadRenderCallback=null,this.onPausedCallback=null,this.onShutDownCallback=null},c.StateManager.prototype={boot:function(){this.game.onPause.add(this.pause,this),this.game.onResume.add(this.resume,this),null!==this._pendingState&&("string"==typeof this._pendingState?this.start(this._pendingState,!1,!1):this.add("default",this._pendingState,!0))},add:function(a,b,d){"undefined"==typeof d&&(d=!1);var e;return b instanceof c.State?e=b:"object"==typeof b?(e=b,e.game=this.game):"function"==typeof b&&(e=new b(this.game)),this.states[a]=e,d&&(this.game.isBooted?this.start(a):this._pendingState=a),e},remove:function(a){this.current==a&&(this.callbackContext=null,this.onInitCallback=null,this.onShutDownCallback=null,this.onPreloadCallback=null,this.onLoadRenderCallback=null,this.onLoadUpdateCallback=null,this.onCreateCallback=null,this.onUpdateCallback=null,this.onRenderCallback=null,this.onPausedCallback=null,this.onDestroyCallback=null),delete this.states[a]},start:function(a,b,c){return"undefined"==typeof b&&(b=!0),"undefined"==typeof c&&(c=!1),this.game.isBooted===!1?(this._pendingState=a,void 0):(this.checkState(a)!==!1&&(this.current&&this.onShutDownCallback.call(this.callbackContext,this.game),b&&(this.game.tweens.removeAll(),this.game.world.destroy(),c===!0&&this.game.cache.destroy()),this.setCurrentState(a),this.onPreloadCallback?(this.game.load.reset(),this.onPreloadCallback.call(this.callbackContext,this.game),0===this.game.load.totalQueuedFiles()?this.game.loadComplete():this.game.load.start()):this.game.loadComplete()),void 0)},dummy:function(){},checkState:function(a){if(this.states[a]){var b=!1;return this.states[a].preload&&(b=!0),b===!1&&this.states[a].loadRender&&(b=!0),b===!1&&this.states[a].loadUpdate&&(b=!0),b===!1&&this.states[a].create&&(b=!0),b===!1&&this.states[a].update&&(b=!0),b===!1&&this.states[a].preRender&&(b=!0),b===!1&&this.states[a].render&&(b=!0),b===!1&&this.states[a].paused&&(b=!0),b===!1?(console.warn("Invalid Phaser State object given. Must contain at least a one of the required functions."),!1):!0}return console.warn("Phaser.StateManager - No state found with the key: "+a),!1},link:function(a){this.states[a].game=this.game,this.states[a].add=this.game.add,this.states[a].camera=this.game.camera,this.states[a].cache=this.game.cache,this.states[a].input=this.game.input,this.states[a].load=this.game.load,this.states[a].math=this.game.math,this.states[a].sound=this.game.sound,this.states[a].stage=this.game.stage,this.states[a].time=this.game.time,this.states[a].tweens=this.game.tweens,this.states[a].world=this.game.world,this.states[a].particles=this.game.particles,this.states[a].physics=this.game.physics,this.states[a].rnd=this.game.rnd},setCurrentState:function(a){this.callbackContext=this.states[a],this.link(a),this.onInitCallback=this.states[a].init||this.dummy,this.onPreloadCallback=this.states[a].preload||null,this.onLoadRenderCallback=this.states[a].loadRender||null,this.onLoadUpdateCallback=this.states[a].loadUpdate||null,this.onCreateCallback=this.states[a].create||null,this.onUpdateCallback=this.states[a].update||null,this.onPreRenderCallback=this.states[a].preRender||null,this.onRenderCallback=this.states[a].render||null,this.onPausedCallback=this.states[a].paused||null,this.onShutDownCallback=this.states[a].shutdown||this.dummy,this.current=a,this._created=!1,this.onInitCallback.call(this.callbackContext,this.game)},getCurrentState:function(){return this.states[this.current]},loadComplete:function(){this._created===!1&&this.onCreateCallback?(this._created=!0,this.onCreateCallback.call(this.callbackContext,this.game)):this._created=!0},pause:function(){this._created&&this.onPausedCallback&&this.onPausedCallback.call(this.callbackContext,this.game,!0)},resume:function(){this._created&&this.onre&&this.onPausedCallback.call(this.callbackContext,this.game,!1)},update:function(){this._created&&this.onUpdateCallback?this.onUpdateCallback.call(this.callbackContext,this.game):this.onLoadUpdateCallback&&this.onLoadUpdateCallback.call(this.callbackContext,this.game)},preRender:function(){this.onPreRenderCallback&&this.onPreRenderCallback.call(this.callbackContext,this.game)},render:function(){this._created&&this.onRenderCallback?(this.game.renderType===c.CANVAS&&(this.game.context.save(),this.game.context.setTransform(1,0,0,1,0,0)),this.onRenderCallback.call(this.callbackContext,this.game),this.game.renderType===c.CANVAS&&this.game.context.restore()):this.onLoadRenderCallback&&this.onLoadRenderCallback.call(this.callbackContext,this.game)},destroy:function(){this.callbackContext=null,this.onInitCallback=null,this.onShutDownCallback=null,this.onPreloadCallback=null,this.onLoadRenderCallback=null,this.onLoadUpdateCallback=null,this.onCreateCallback=null,this.onUpdateCallback=null,this.onRenderCallback=null,this.onPausedCallback=null,this.onDestroyCallback=null,this.game=null,this.states={},this._pendingState=null}},c.StateManager.prototype.constructor=c.StateManager,c.LinkedList=function(){this.next=null,this.prev=null,this.first=null,this.last=null,this.total=0},c.LinkedList.prototype={add:function(a){return 0===this.total&&null==this.first&&null==this.last?(this.first=a,this.last=a,this.next=a,a.prev=this,this.total++,a):(this.last.next=a,a.prev=this.last,this.last=a,this.total++,a)},remove:function(a){a==this.first?this.first=this.first.next:a==this.last&&(this.last=this.last.prev),a.prev&&(a.prev.next=a.next),a.next&&(a.next.prev=a.prev),a.next=a.prev=null,null==this.first&&(this.last=null),this.total--},callAll:function(a){if(this.first&&this.last){var b=this.first;do b&&b[a]&&b[a].call(b),b=b.next;while(b!=this.last.next)}}},c.LinkedList.prototype.constructor=c.LinkedList,c.Signal=function(){this._bindings=[],this._prevParams=null;var a=this;this.dispatch=function(){c.Signal.prototype.dispatch.apply(a,arguments)}},c.Signal.prototype={memorize:!1,_shouldPropagate:!0,active:!0,validateListener:function(a,b){if("function"!=typeof a)throw new Error("listener is a required param of {fn}() and should be a Function.".replace("{fn}",b))},_registerListener:function(a,b,d,e){var f,g=this._indexOfListener(a,d);if(-1!==g){if(f=this._bindings[g],f.isOnce()!==b)throw new Error("You cannot add"+(b?"":"Once")+"() then add"+(b?"Once":"")+"() the same listener without removing the relationship first.")}else f=new c.SignalBinding(this,a,b,d,e),this._addBinding(f);return this.memorize&&this._prevParams&&f.execute(this._prevParams),f},_addBinding:function(a){var b=this._bindings.length;do--b;while(this._bindings[b]&&a._priority<=this._bindings[b]._priority);this._bindings.splice(b+1,0,a)},_indexOfListener:function(a,b){for(var c,d=this._bindings.length;d--;)if(c=this._bindings[d],c._listener===a&&c.context===b)return d;return-1},has:function(a,b){return-1!==this._indexOfListener(a,b)},add:function(a,b,c){return this.validateListener(a,"add"),this._registerListener(a,!1,b,c)},addOnce:function(a,b,c){return this.validateListener(a,"addOnce"),this._registerListener(a,!0,b,c)},remove:function(a,b){this.validateListener(a,"remove");var c=this._indexOfListener(a,b);return-1!==c&&(this._bindings[c]._destroy(),this._bindings.splice(c,1)),a},removeAll:function(){for(var a=this._bindings.length;a--;)this._bindings[a]._destroy();this._bindings.length=0},getNumListeners:function(){return this._bindings.length},halt:function(){this._shouldPropagate=!1},dispatch:function(){if(this.active){var a,b=Array.prototype.slice.call(arguments),c=this._bindings.length;if(this.memorize&&(this._prevParams=b),c){a=this._bindings.slice(),this._shouldPropagate=!0;do c--;while(a[c]&&this._shouldPropagate&&a[c].execute(b)!==!1)}}},forget:function(){this._prevParams=null},dispose:function(){this.removeAll(),delete this._bindings,delete this._prevParams},toString:function(){return"[Phaser.Signal active:"+this.active+" numListeners:"+this.getNumListeners()+"]"}},c.Signal.prototype.constructor=c.Signal,c.SignalBinding=function(a,b,c,d,e){this._listener=b,this._isOnce=c,this.context=d,this._signal=a,this._priority=e||0},c.SignalBinding.prototype={active:!0,params:null,execute:function(a){var b,c;return this.active&&this._listener&&(c=this.params?this.params.concat(a):a,b=this._listener.apply(this.context,c),this._isOnce&&this.detach()),b},detach:function(){return this.isBound()?this._signal.remove(this._listener,this.context):null},isBound:function(){return!!this._signal&&!!this._listener},isOnce:function(){return this._isOnce},getListener:function(){return this._listener},getSignal:function(){return this._signal},_destroy:function(){delete this._signal,delete this._listener,delete this.context},toString:function(){return"[Phaser.SignalBinding isOnce:"+this._isOnce+", isBound:"+this.isBound()+", active:"+this.active+"]"}},c.SignalBinding.prototype.constructor=c.SignalBinding,c.Filter=function(a,b,d){this.game=a,this.type=c.WEBGL_FILTER,this.passes=[this],this.dirty=!0,this.padding=0,this.uniforms={time:{type:"1f",value:0},resolution:{type:"2f",value:{x:256,y:256}},mouse:{type:"2f",value:{x:0,y:0}}},this.fragmentSrc=d||[]},c.Filter.prototype={init:function(){},setResolution:function(a,b){this.uniforms.resolution.value.x=a,this.uniforms.resolution.value.y=b},update:function(a){"undefined"!=typeof a&&(a.x>0&&(this.uniforms.mouse.x=a.x.toFixed(2)),a.y>0&&(this.uniforms.mouse.y=a.y.toFixed(2))),this.uniforms.time.value=this.game.time.totalElapsedSeconds()},destroy:function(){this.game=null}},c.Filter.prototype.constructor=c.Filter,Object.defineProperty(c.Filter.prototype,"width",{get:function(){return this.uniforms.resolution.value.x},set:function(a){this.uniforms.resolution.value.x=a}}),Object.defineProperty(c.Filter.prototype,"height",{get:function(){return this.uniforms.resolution.value.y},set:function(a){this.uniforms.resolution.value.y=a}}),c.Plugin=function(a,b){"undefined"==typeof b&&(b=null),this.game=a,this.parent=b,this.active=!1,this.visible=!1,this.hasPreUpdate=!1,this.hasUpdate=!1,this.hasPostUpdate=!1,this.hasRender=!1,this.hasPostRender=!1},c.Plugin.prototype={preUpdate:function(){},update:function(){},render:function(){},postRender:function(){},destroy:function(){this.game=null,this.parent=null,this.active=!1,this.visible=!1}},c.Plugin.prototype.constructor=c.Plugin,c.PluginManager=function(a,b){this.game=a,this._parent=b,this.plugins=[],this._pluginsLength=0},c.PluginManager.prototype={add:function(a){var b=!1;return"function"==typeof a?a=new a(this.game,this._parent):(a.game=this.game,a.parent=this._parent),"function"==typeof a.preUpdate&&(a.hasPreUpdate=!0,b=!0),"function"==typeof a.update&&(a.hasUpdate=!0,b=!0),"function"==typeof a.postUpdate&&(a.hasPostUpdate=!0,b=!0),"function"==typeof a.render&&(a.hasRender=!0,b=!0),"function"==typeof a.postRender&&(a.hasPostRender=!0,b=!0),b?((a.hasPreUpdate||a.hasUpdate||a.hasPostUpdate)&&(a.active=!0),(a.hasRender||a.hasPostRender)&&(a.visible=!0),this._pluginsLength=this.plugins.push(a),"function"==typeof a.init&&a.init(),a):null +},remove:function(a){if(0!==this._pluginsLength)for(this._p=0;this._pthis._nextOffsetCheck&&(c.Canvas.getOffset(this.canvas,this.offset),this._nextOffsetCheck=this.game.time.now+this.checkOffsetInterval)},visibilityChange:function(a){this.disableVisibilityChange||(this.game.paused="pagehide"==a.type||"blur"==a.type||document.hidden===!0||document.webkitHidden===!0?!0:!1)}},c.Stage.prototype.constructor=c.Stage,Object.defineProperty(c.Stage.prototype,"backgroundColor",{get:function(){return this._backgroundColor},set:function(a){this._backgroundColor=a,this.game.transparent===!1&&(this.game.renderType==c.CANVAS?this.game.canvas.style.backgroundColor=a:("string"==typeof a&&(a=c.Color.hexToRGB(a)),this._stage.setBackgroundColor(a)))}}),c.Group=function(a,d,e,f){this.game=a,"undefined"==typeof d&&(d=a.world),this.name=e||"group","undefined"==typeof f&&(f=!1),f?this._container=this.game.stage._stage:(this._container=new b.DisplayObjectContainer,this._container.name=this.name,d?d instanceof c.Group?(d._container.addChild(this._container),d._container.updateTransform()):(d.addChild(this._container),d.updateTransform()):(this.game.stage._stage.addChild(this._container),this.game.stage._stage.updateTransform())),this.type=c.GROUP,this.alive=!0,this.exists=!0,this.group=null,this._container.scale=new c.Point(1,1),this.scale=this._container.scale,this.cursor=null},c.Group.RETURN_NONE=0,c.Group.RETURN_TOTAL=1,c.Group.RETURN_CHILD=2,c.Group.SORT_ASCENDING=-1,c.Group.SORT_DESCENDING=1,c.Group.prototype={add:function(a){return a.group!==this&&(a.type&&a.type===c.GROUP?(a.group=this,this._container.addChild(a._container),a._container.updateTransform()):(a.group=this,a.events&&a.events.onAddedToGroup.dispatch(a,this),this._container.addChild(a),a.updateTransform()),null===this.cursor&&(this.cursor=a)),a},addAt:function(a,b){return a.group!==this&&(a.type&&a.type===c.GROUP?(a.group=this,this._container.addChildAt(a._container,b),a._container.updateTransform()):(a.group=this,a.events&&a.events.onAddedToGroup.dispatch(a,this),this._container.addChildAt(a,b),a.updateTransform()),null===this.cursor&&(this.cursor=a)),a},getAt:function(a){return this._container.getChildAt(a)},create:function(a,b,d,e,f){"undefined"==typeof f&&(f=!0);var g=new c.Sprite(this.game,a,b,d,e);return g.group=this,g.exists=f,g.visible=f,g.alive=f,g.events&&g.events.onAddedToGroup.dispatch(g,this),this._container.addChild(g),g.updateTransform(),null===this.cursor&&(this.cursor=g),g},createMultiple:function(a,b,d,e){"undefined"==typeof e&&(e=!1);for(var f=0;a>f;f++){var g=new c.Sprite(this.game,0,0,b,d);g.group=this,g.exists=e,g.visible=e,g.alive=e,g.events&&g.events.onAddedToGroup.dispatch(g,this),this._container.addChild(g),g.updateTransform(),null===this.cursor&&(this.cursor=g)}},next:function(){this.cursor&&(this.cursor=this.cursor==this._container.last?this._container._iNext:this.cursor._iNext)},previous:function(){this.cursor&&(this.cursor=this.cursor==this._container._iNext?this._container.last:this.cursor._iPrev)},childTest:function(a,b){var c=a+" next: ";c+=b._iNext?b._iNext.name:"-null-",c=c+" "+a+" prev: ",c+=b._iPrev?b._iPrev.name:"-null-",console.log(c)},swapIndex:function(a,b){var c=this.getAt(a),d=this.getAt(b);console.log("swapIndex ",a," with ",b),this.swap(c,d)},swap:function(a,b){if(a===b||!a.parent||!b.parent||a.group!==this||b.group!==this)return!1;var c=a._iPrev,d=a._iNext,e=b._iPrev,f=b._iNext,g=this._container.last._iNext,h=this.game.stage._stage;do h!==a&&h!==b&&(h.first===a?h.first=b:h.first===b&&(h.first=a),h.last===a?h.last=b:h.last===b&&(h.last=a)),h=h._iNext;while(h!=g);return a._iNext==b?(a._iNext=f,a._iPrev=b,b._iNext=a,b._iPrev=c,c&&(c._iNext=b),f&&(f._iPrev=a),a.__renderGroup&&a.__renderGroup.updateTexture(a),b.__renderGroup&&b.__renderGroup.updateTexture(b),!0):b._iNext==a?(a._iNext=b,a._iPrev=e,b._iNext=d,b._iPrev=a,e&&(e._iNext=a),d&&(d._iPrev=b),a.__renderGroup&&a.__renderGroup.updateTexture(a),b.__renderGroup&&b.__renderGroup.updateTexture(b),!0):(a._iNext=f,a._iPrev=e,b._iNext=d,b._iPrev=c,c&&(c._iNext=b),d&&(d._iPrev=b),e&&(e._iNext=a),f&&(f._iPrev=a),a.__renderGroup&&a.__renderGroup.updateTexture(a),b.__renderGroup&&b.__renderGroup.updateTexture(b),!0)},bringToTop:function(a){return a.group===this&&(this.remove(a),this.add(a)),a},getIndex:function(a){return this._container.children.indexOf(a)},replace:function(a,b){if(this._container.first._iNext){var c=this.getIndex(a);-1!=c&&(void 0!==b.parent&&(b.events.onRemovedFromGroup.dispatch(b,this),b.parent.removeChild(b)),this._container.removeChild(a),this._container.addChildAt(b,c),b.events.onAddedToGroup.dispatch(b,this),b.updateTransform(),this.cursor==a&&(this.cursor=this._container._iNext))}},setProperty:function(a,b,c,d){d=d||0;var e=b.length;1==e?0===d?a[b[0]]=c:1==d?a[b[0]]+=c:2==d?a[b[0]]-=c:3==d?a[b[0]]*=c:4==d&&(a[b[0]]/=c):2==e?0===d?a[b[0]][b[1]]=c:1==d?a[b[0]][b[1]]+=c:2==d?a[b[0]][b[1]]-=c:3==d?a[b[0]][b[1]]*=c:4==d&&(a[b[0]][b[1]]/=c):3==e?0===d?a[b[0]][b[1]][b[2]]=c:1==d?a[b[0]][b[1]][b[2]]+=c:2==d?a[b[0]][b[1]][b[2]]-=c:3==d?a[b[0]][b[1]][b[2]]*=c:4==d&&(a[b[0]][b[1]][b[2]]/=c):4==e&&(0===d?a[b[0]][b[1]][b[2]][b[3]]=c:1==d?a[b[0]][b[1]][b[2]][b[3]]+=c:2==d?a[b[0]][b[1]][b[2]][b[3]]-=c:3==d?a[b[0]][b[1]][b[2]][b[3]]*=c:4==d&&(a[b[0]][b[1]][b[2]][b[3]]/=c))},set:function(a,b,c,d,e,f){b=b.split("."),"undefined"==typeof d&&(d=!1),"undefined"==typeof e&&(e=!1),(d===!1||d&&a.alive)&&(e===!1||e&&a.visible)&&this.setProperty(a,b,c,f)},setAll:function(a,b,c,d,e){if(a=a.split("."),"undefined"==typeof c&&(c=!1),"undefined"==typeof d&&(d=!1),e=e||0,this._container.children.length>0&&this._container.first._iNext){var f=this._container.first._iNext;do(c===!1||c&&f.alive)&&(d===!1||d&&f.visible)&&this.setProperty(f,a,b,e),f=f._iNext;while(f!=this._container.last._iNext)}},addAll:function(a,b,c,d){this.setAll(a,b,c,d,1)},subAll:function(a,b,c,d){this.setAll(a,b,c,d,2)},multiplyAll:function(a,b,c,d){this.setAll(a,b,c,d,3)},divideAll:function(a,b,c,d){this.setAll(a,b,c,d,4)},callAllExists:function(a,b){var c=Array.prototype.splice.call(arguments,2);if(this._container.children.length>0&&this._container.first._iNext){var d=this._container.first._iNext;do d.exists==b&&d[a]&&d[a].apply(d,c),d=d._iNext;while(d!=this._container.last._iNext)}},callbackFromArray:function(a,b,c){if(1==c){if(a[b[0]])return a[b[0]]}else if(2==c){if(a[b[0]][b[1]])return a[b[0]][b[1]]}else if(3==c){if(a[b[0]][b[1]][b[2]])return a[b[0]][b[1]][b[2]]}else if(4==c){if(a[b[0]][b[1]][b[2]][b[3]])return a[b[0]][b[1]][b[2]][b[3]]}else if(a[b])return a[b];return!1},callAll:function(a,b){if("undefined"!=typeof a){a=a.split(".");var c=a.length;if("undefined"==typeof b)b=null;else if("string"==typeof b){b=b.split(".");var d=b.length}var e=Array.prototype.splice.call(arguments,2),f=null,g=null;if(this._container.children.length>0&&this._container.first._iNext){var h=this._container.first._iNext;do f=this.callbackFromArray(h,a,c),b&&f?(g=this.callbackFromArray(h,b,d),f&&f.apply(g,e)):f&&f.apply(h,e),h=h._iNext;while(h!=this._container.last._iNext)}}},forEach:function(a,b,c){"undefined"==typeof c&&(c=!1);var d=Array.prototype.splice.call(arguments,3);if(d.unshift(null),this._container.children.length>0&&this._container.first._iNext){var e=this._container.first._iNext;do(c===!1||c&&e.exists)&&(d[0]=e,a.apply(b,d)),e=e._iNext;while(e!=this._container.last._iNext)}},forEachExists:function(a,b){var d=Array.prototype.splice.call(arguments,2);d.unshift(null),this.iterate("exists",!0,c.Group.RETURN_TOTAL,a,b,d)},forEachAlive:function(a,b){var d=Array.prototype.splice.call(arguments,2);d.unshift(null),this.iterate("alive",!0,c.Group.RETURN_TOTAL,a,b,d)},forEachDead:function(a,b){var d=Array.prototype.splice.call(arguments,2);d.unshift(null),this.iterate("alive",!1,c.Group.RETURN_TOTAL,a,b,d)},sort:function(a,b){"undefined"==typeof a&&(a="y"),"undefined"==typeof b&&(b=c.Group.SORT_ASCENDING);var d,e;do{d=!1;for(var f=0,g=this._container.children.length-1;g>f;f++)b==c.Group.SORT_ASCENDING?this._container.children[f][a]>this._container.children[f+1][a]&&(this.swap(this.getAt(f),this.getAt(f+1)),e=this._container.children[f],this._container.children[f]=this._container.children[f+1],this._container.children[f+1]=e,d=!0):this._container.children[f][a]0&&this._container.first._iNext){var i=this._container.first._iNext;do{if(i[a]===b&&(h++,e&&(g[0]=i,e.apply(f,g)),d===c.Group.RETURN_CHILD))return i;i=i._iNext}while(i!=this._container.last._iNext)}return d===c.Group.RETURN_TOTAL?h:d===c.Group.RETURN_CHILD?null:void 0},getFirstExists:function(a){return"boolean"!=typeof a&&(a=!0),this.iterate("exists",a,c.Group.RETURN_CHILD)},getFirstAlive:function(){return this.iterate("alive",!0,c.Group.RETURN_CHILD)},getFirstDead:function(){return this.iterate("alive",!1,c.Group.RETURN_CHILD)},countLiving:function(){return this.iterate("alive",!0,c.Group.RETURN_TOTAL)},countDead:function(){return this.iterate("alive",!1,c.Group.RETURN_TOTAL)},getRandom:function(a,b){return 0===this._container.children.length?null:(a=a||0,b=b||this._container.children.length,this.game.math.getRandom(this._container.children,a,b))},remove:function(a){return a.group!==this?!1:(a.events&&a.events.onRemovedFromGroup.dispatch(a,this),a.parent===this._container&&this._container.removeChild(a),this.cursor==a&&(this.cursor=this._container._iNext?this._container._iNext:null),a.group=null,!0)},removeAll:function(){if(0!==this._container.children.length){do this._container.children[0].events&&this._container.children[0].events.onRemovedFromGroup.dispatch(this._container.children[0],this),this._container.removeChild(this._container.children[0]);while(this._container.children.length>0);this.cursor=null}},removeBetween:function(a,b){if(0!==this._container.children.length){if(a>b||0>a||b>this._container.children.length)return!1;for(var c=a;b>c;c++){var d=this._container.children[c];d.events.onRemovedFromGroup.dispatch(d,this),this._container.removeChild(d),this.cursor==d&&(this.cursor=this._container._iNext?this._container._iNext:null)}}},destroy:function(a){if("undefined"==typeof a&&(a=!1),a){if(this._container.children.length>0)do this._container.children[0].group&&this._container.children[0].destroy();while(this._container.children.length>0)}else this.removeAll();this._container.parent.removeChild(this._container),this._container=null,this.game=null,this.exists=!1,this.cursor=null},validate:function(){var a=this.game.stage._stage.last._iNext,b=this.game.stage._stage,c=null,d=null,e=0;do{if(e>0){if(b!==c)return console.log("check next fail"),!1;if(b._iPrev!==d)return console.log("check previous fail"),!1}c=b._iNext,d=b,b=b._iNext,e++}while(b!=a);return!0},dump:function(a){"undefined"==typeof a&&(a=!1);var b=20,d="\n"+c.Utils.pad("Node",b)+"|"+c.Utils.pad("Next",b)+"|"+c.Utils.pad("Previous",b)+"|"+c.Utils.pad("First",b)+"|"+c.Utils.pad("Last",b);console.log(d);var d=c.Utils.pad("----------",b)+"|"+c.Utils.pad("----------",b)+"|"+c.Utils.pad("----------",b)+"|"+c.Utils.pad("----------",b)+"|"+c.Utils.pad("----------",b);if(console.log(d),a)var e=this.game.stage._stage.last._iNext,f=this.game.stage._stage;else var e=this._container.last._iNext,f=this._container;do{var g=f.name||"*";if(this.cursor==f)var g="> "+g;var h="-",i="-",j="-",k="-";f._iNext&&(h=f._iNext.name),f._iPrev&&(i=f._iPrev.name),f.first&&(j=f.first.name),f.last&&(k=f.last.name),"undefined"==typeof h&&(h="-"),"undefined"==typeof i&&(i="-"),"undefined"==typeof j&&(j="-"),"undefined"==typeof k&&(k="-");var d=c.Utils.pad(g,b)+"|"+c.Utils.pad(h,b)+"|"+c.Utils.pad(i,b)+"|"+c.Utils.pad(j,b)+"|"+c.Utils.pad(k,b);console.log(d),f=f._iNext}while(f!=e)}},c.Group.prototype.constructor=c.Group,Object.defineProperty(c.Group.prototype,"total",{get:function(){return this._container?this.iterate("exists",!0,c.Group.RETURN_TOTAL):0}}),Object.defineProperty(c.Group.prototype,"length",{get:function(){return this._container?this._container.children.length:0}}),Object.defineProperty(c.Group.prototype,"x",{get:function(){return this._container.position.x},set:function(a){this._container.position.x=a}}),Object.defineProperty(c.Group.prototype,"y",{get:function(){return this._container.position.y},set:function(a){this._container.position.y=a}}),Object.defineProperty(c.Group.prototype,"angle",{get:function(){return c.Math.radToDeg(this._container.rotation)},set:function(a){this._container.rotation=c.Math.degToRad(a)}}),Object.defineProperty(c.Group.prototype,"rotation",{get:function(){return this._container.rotation},set:function(a){this._container.rotation=a}}),Object.defineProperty(c.Group.prototype,"visible",{get:function(){return this._container.visible},set:function(a){this._container.visible=a}}),Object.defineProperty(c.Group.prototype,"alpha",{get:function(){return this._container.alpha},set:function(a){this._container.alpha=a}}),c.World=function(a){c.Group.call(this,a,null,"__world",!1),this.bounds=new c.Rectangle(0,0,a.width,a.height),this.camera=null,this.currentRenderOrderID=0},c.World.prototype=Object.create(c.Group.prototype),c.World.prototype.constructor=c.World,c.World.prototype.boot=function(){this.camera=new c.Camera(this.game,0,0,0,this.game.width,this.game.height),this.camera.displayObject=this._container,this.game.camera=this.camera},c.World.prototype.preUpdate=function(){if(this.game.stage._stage.first._iNext){var a=this.game.stage._stage.first._iNext;do a=a.preUpdate&&!a.preUpdate()?a.last._iNext:a._iNext;while(a!=this.game.stage._stage.last._iNext)}},c.World.prototype.update=function(){if(this.currentRenderOrderID=0,this.game.stage._stage.first._iNext){var a=this.game.stage._stage.first._iNext;do a=a.update&&!a.update()?a.last._iNext:a._iNext;while(a!=this.game.stage._stage.last._iNext)}},c.World.prototype.postUpdate=function(){if(this.camera.update(),this.game.stage._stage.first._iNext){var a=this.game.stage._stage.first._iNext;do a.postUpdate&&a.postUpdate(),a=a._iNext;while(a!=this.game.stage._stage.last._iNext)}},c.World.prototype.setBounds=function(a,b,c,d){c0;b--)null===this["pointer"+b]&&(a=b);return 0===a?(console.warn("You can only have 10 Pointer objects"),null):(this["pointer"+a]=new c.Pointer(this.game,a),this["pointer"+a])},update:function(){return this.pollRate>0&&this._pollCounter=b;b++)this["pointer"+b]&&this["pointer"+b].reset();this.currentPointers=0,"none"!==this.game.canvas.style.cursor&&(this.game.canvas.style.cursor="default"),a===!0&&(this.onDown.dispose(),this.onUp.dispose(),this.onTap.dispose(),this.onHold.dispose(),this.onDown=new c.Signal,this.onUp=new c.Signal,this.onTap=new c.Signal,this.onHold=new c.Signal,this.interactiveItems.callAll("reset")),this._pollCounter=0}},resetSpeed:function(a,b){this._oldPosition.setTo(a,b),this.speed.setTo(0,0)},startPointer:function(a){if(this.maxPointers<10&&this.totalActivePointers==this.maxPointers)return null;if(this.pointer1.active===!1)return this.pointer1.start(a);if(this.pointer2.active===!1)return this.pointer2.start(a);for(var b=3;10>=b;b++)if(this["pointer"+b]&&this["pointer"+b].active===!1)return this["pointer"+b].start(a);return null},updatePointer:function(a){if(this.pointer1.active&&this.pointer1.identifier==a.identifier)return this.pointer1.move(a);if(this.pointer2.active&&this.pointer2.identifier==a.identifier)return this.pointer2.move(a);for(var b=3;10>=b;b++)if(this["pointer"+b]&&this["pointer"+b].active&&this["pointer"+b].identifier==a.identifier)return this["pointer"+b].move(a);return null},stopPointer:function(a){if(this.pointer1.active&&this.pointer1.identifier==a.identifier)return this.pointer1.stop(a);if(this.pointer2.active&&this.pointer2.identifier==a.identifier)return this.pointer2.stop(a);for(var b=3;10>=b;b++)if(this["pointer"+b]&&this["pointer"+b].active&&this["pointer"+b].identifier==a.identifier)return this["pointer"+b].stop(a);return null},getPointer:function(a){if(a=a||!1,this.pointer1.active==a)return this.pointer1;if(this.pointer2.active==a)return this.pointer2;for(var b=3;10>=b;b++)if(this["pointer"+b]&&this["pointer"+b].active==a)return this["pointer"+b];return null},getPointerFromIdentifier:function(a){if(this.pointer1.identifier==a)return this.pointer1;if(this.pointer2.identifier==a)return this.pointer2;for(var b=3;10>=b;b++)if(this["pointer"+b]&&this["pointer"+b].identifier==a)return this["pointer"+b];return null}},c.Input.prototype.constructor=c.Input,Object.defineProperty(c.Input.prototype,"x",{get:function(){return this._x},set:function(a){this._x=Math.floor(a)}}),Object.defineProperty(c.Input.prototype,"y",{get:function(){return this._y},set:function(a){this._y=Math.floor(a)}}),Object.defineProperty(c.Input.prototype,"pollLocked",{get:function(){return this.pollRate>0&&this._pollCounter=a;a++)this["pointer"+a]&&this["pointer"+a].active&&this.currentPointers++;return this.currentPointers}}),Object.defineProperty(c.Input.prototype,"worldX",{get:function(){return this.game.camera.view.x+this.x}}),Object.defineProperty(c.Input.prototype,"worldY",{get:function(){return this.game.camera.view.y+this.y}}),c.Key=function(a,b){this.game=a,this.isDown=!1,this.isUp=!1,this.altKey=!1,this.ctrlKey=!1,this.shiftKey=!1,this.timeDown=0,this.duration=0,this.timeUp=0,this.repeats=0,this.keyCode=b,this.onDown=new c.Signal,this.onUp=new c.Signal},c.Key.prototype={processKeyDown:function(a){this.altKey=a.altKey,this.ctrlKey=a.ctrlKey,this.shiftKey=a.shiftKey,this.isDown?(this.duration=a.timeStamp-this.timeDown,this.repeats++):(this.isDown=!0,this.isUp=!1,this.timeDown=a.timeStamp,this.duration=0,this.repeats=0,this.onDown.dispatch(this))},processKeyUp:function(a){this.isDown=!1,this.isUp=!0,this.timeUp=a.timeStamp,this.onUp.dispatch(this)},justPressed:function(a){return"undefined"==typeof a&&(a=250),this.isDown&&this.duration=this.game.input.holdRate&&((this.game.input.multiInputOverride==c.Input.MOUSE_OVERRIDES_TOUCH||this.game.input.multiInputOverride==c.Input.MOUSE_TOUCH_COMBINE||this.game.input.multiInputOverride==c.Input.TOUCH_OVERRIDES_MOUSE&&0===this.game.input.currentPointers)&&this.game.input.onHold.dispatch(this),this._holdSent=!0),this.game.input.recordPointerHistory&&this.game.time.now>=this._nextDrop&&(this._nextDrop=this.game.time.now+this.game.input.recordRate,this._history.push({x:this.position.x,y:this.position.y}),this._history.length>this.game.input.recordLimit&&this._history.shift()))},move:function(a){if(!this.game.input.pollLocked){if("undefined"!=typeof a.button&&(this.button=a.button),this.clientX=a.clientX,this.clientY=a.clientY,this.pageX=a.pageX,this.pageY=a.pageY,this.screenX=a.screenX,this.screenY=a.screenY,this.x=(this.pageX-this.game.stage.offset.x)*this.game.input.scale.x,this.y=(this.pageY-this.game.stage.offset.y)*this.game.input.scale.y,this.position.setTo(this.x,this.y),this.circle.x=this.x,this.circle.y=this.y,(this.game.input.multiInputOverride==c.Input.MOUSE_OVERRIDES_TOUCH||this.game.input.multiInputOverride==c.Input.MOUSE_TOUCH_COMBINE||this.game.input.multiInputOverride==c.Input.TOUCH_OVERRIDES_MOUSE&&0===this.game.input.currentPointers)&&(this.game.input.activePointer=this,this.game.input.x=this.x,this.game.input.y=this.y,this.game.input.position.setTo(this.game.input.x,this.game.input.y),this.game.input.circle.x=this.game.input.x,this.game.input.circle.y=this.game.input.y),this.game.paused)return this;if(null!==this.targetObject&&this.targetObject.isDragged===!0)return this.targetObject.update(this)===!1&&(this.targetObject=null),this;if(this._highestRenderOrderID=-1,this._highestRenderObject=null,this._highestInputPriorityID=-1,this.game.input.interactiveItems.total>0){var b=this.game.input.interactiveItems.next;do(b.pixelPerfect||b.priorityID>this._highestInputPriorityID||b.priorityID==this._highestInputPriorityID&&b.sprite.renderOrderID>this._highestRenderOrderID)&&b.checkPointerOver(this)&&(this._highestRenderOrderID=b.sprite.renderOrderID,this._highestInputPriorityID=b.priorityID,this._highestRenderObject=b),b=b.next;while(null!=b)}return null==this._highestRenderObject?this.targetObject&&(this.targetObject._pointerOutHandler(this),this.targetObject=null):null==this.targetObject?(this.targetObject=this._highestRenderObject,this._highestRenderObject._pointerOverHandler(this)):this.targetObject==this._highestRenderObject?this._highestRenderObject.update(this)===!1&&(this.targetObject=null):(this.targetObject._pointerOutHandler(this),this.targetObject=this._highestRenderObject,this.targetObject._pointerOverHandler(this)),this}},leave:function(a){this.withinGame=!1,this.move(a)},stop:function(a){if(this._stateReset)return a.preventDefault(),void 0;if(this.timeUp=this.game.time.now,(this.game.input.multiInputOverride==c.Input.MOUSE_OVERRIDES_TOUCH||this.game.input.multiInputOverride==c.Input.MOUSE_TOUCH_COMBINE||this.game.input.multiInputOverride==c.Input.TOUCH_OVERRIDES_MOUSE&&0===this.game.input.currentPointers)&&(this.game.input.onUp.dispatch(this,a),this.duration>=0&&this.duration<=this.game.input.tapRate&&(this.timeUp-this.previousTapTime0&&(this.active=!1),this.withinGame=!1,this.isDown=!1,this.isUp=!0,this.isMouse===!1&&this.game.input.currentPointers--,this.game.input.interactiveItems.total>0){var b=this.game.input.interactiveItems.next;do b&&b._releasedHandler(this),b=b.next;while(null!=b)}return this.targetObject&&this.targetObject._releasedHandler(this),this.targetObject=null,this},justPressed:function(a){return a=a||this.game.input.justPressedRate,this.isDown===!0&&this.timeDown+a>this.game.time.now},justReleased:function(a){return a=a||this.game.input.justReleasedRate,this.isUp===!0&&this.timeUp+a>this.game.time.now},reset:function(){this.isMouse===!1&&(this.active=!1),this.identifier=null,this.isDown=!1,this.isUp=!0,this.totalTouches=0,this._holdSent=!1,this._history.length=0,this._stateReset=!0,this.targetObject&&this.targetObject._releasedHandler(this),this.targetObject=null}},c.Pointer.prototype.constructor=c.Pointer,Object.defineProperty(c.Pointer.prototype,"duration",{get:function(){return this.isUp?-1:this.game.time.now-this.timeDown}}),Object.defineProperty(c.Pointer.prototype,"worldX",{get:function(){return this.game.world.camera.x+this.x}}),Object.defineProperty(c.Pointer.prototype,"worldY",{get:function(){return this.game.world.camera.y+this.y}}),c.Touch=function(a){this.game=a,this.disabled=!1,this.callbackContext=this.game,this.touchStartCallback=null,this.touchMoveCallback=null,this.touchEndCallback=null,this.touchEnterCallback=null,this.touchLeaveCallback=null,this.touchCancelCallback=null,this.preventDefault=!0,this.event=null,this._onTouchStart=null,this._onTouchMove=null,this._onTouchEnd=null,this._onTouchEnter=null,this._onTouchLeave=null,this._onTouchCancel=null,this._onTouchMove=null},c.Touch.prototype={start:function(){var a=this;this.game.device.touch&&(this._onTouchStart=function(b){return a.onTouchStart(b)},this._onTouchMove=function(b){return a.onTouchMove(b)},this._onTouchEnd=function(b){return a.onTouchEnd(b)},this._onTouchEnter=function(b){return a.onTouchEnter(b)},this._onTouchLeave=function(b){return a.onTouchLeave(b)},this._onTouchCancel=function(b){return a.onTouchCancel(b)},this.game.renderer.view.addEventListener("touchstart",this._onTouchStart,!1),this.game.renderer.view.addEventListener("touchmove",this._onTouchMove,!1),this.game.renderer.view.addEventListener("touchend",this._onTouchEnd,!1),this.game.renderer.view.addEventListener("touchenter",this._onTouchEnter,!1),this.game.renderer.view.addEventListener("touchleave",this._onTouchLeave,!1),this.game.renderer.view.addEventListener("touchcancel",this._onTouchCancel,!1))},consumeDocumentTouches:function(){this._documentTouchMove=function(a){a.preventDefault()},document.addEventListener("touchmove",this._documentTouchMove,!1)},onTouchStart:function(a){if(this.event=a,this.touchStartCallback&&this.touchStartCallback.call(this.callbackContext,a),!this.game.input.disabled&&!this.disabled){this.preventDefault&&a.preventDefault();for(var b=0;bd;d++)this._pointerData[d]={id:d,x:0,y:0,isDown:!1,isUp:!1,isOver:!1,isOut:!1,timeOver:0,timeOut:0,timeDown:0,timeUp:0,downDuration:0,isDragged:!1};this.snapOffset=new c.Point,this.enabled=!0,this.sprite.events&&null==this.sprite.events.onInputOver&&(this.sprite.events.onInputOver=new c.Signal,this.sprite.events.onInputOut=new c.Signal,this.sprite.events.onInputDown=new c.Signal,this.sprite.events.onInputUp=new c.Signal,this.sprite.events.onDragStart=new c.Signal,this.sprite.events.onDragStop=new c.Signal)}return this.sprite},reset:function(){this.enabled=!1;for(var a=0;10>a;a++)this._pointerData[a]={id:a,x:0,y:0,isDown:!1,isUp:!1,isOver:!1,isOut:!1,timeOver:0,timeOut:0,timeDown:0,timeUp:0,downDuration:0,isDragged:!1}},stop:function(){this.enabled!==!1&&(this.enabled=!1,this.game.input.interactiveItems.remove(this))},destroy:function(){this.enabled&&(this.enabled=!1,this.game.input.interactiveItems.remove(this),this.stop(),this.sprite=null)},pointerX:function(a){return a=a||0,this._pointerData[a].x},pointerY:function(a){return a=a||0,this._pointerData[a].y},pointerDown:function(a){return a=a||0,this._pointerData[a].isDown},pointerUp:function(a){return a=a||0,this._pointerData[a].isUp},pointerTimeDown:function(a){return a=a||0,this._pointerData[a].timeDown},pointerTimeUp:function(a){return a=a||0,this._pointerData[a].timeUp},pointerOver:function(a){if(this.enabled){if("undefined"!=typeof a)return this._pointerData[a].isOver;for(var b=0;10>b;b++)if(this._pointerData[b].isOver)return!0}return!1},pointerOut:function(a){if(this.enabled){if("undefined"!=typeof a)return this._pointerData[a].isOut;for(var b=0;10>b;b++)if(this._pointerData[b].isOut)return!0}return!1},pointerTimeOver:function(a){return a=a||0,this._pointerData[a].timeOver},pointerTimeOut:function(a){return a=a||0,this._pointerData[a].timeOut},pointerDragged:function(a){return a=a||0,this._pointerData[a].isDragged},checkPointerOver:function(a){return this.enabled===!1||this.sprite.visible===!1||this.sprite.group&&this.sprite.group.visible===!1?!1:(this.sprite.getLocalUnmodifiedPosition(this._tempPoint,a.x,a.y),this._tempPoint.x>=0&&this._tempPoint.x<=this.sprite.currentFrame.width&&this._tempPoint.y>=0&&this._tempPoint.y<=this.sprite.currentFrame.height?this.pixelPerfect?this.checkPixel(this._tempPoint.x,this._tempPoint.y):!0:void 0)},checkPixel:function(a,b){if(this.sprite.texture.baseTexture.source){this.game.input.hitContext.clearRect(0,0,1,1),a+=this.sprite.texture.frame.x,b+=this.sprite.texture.frame.y,this.game.input.hitContext.drawImage(this.sprite.texture.baseTexture.source,a,b,1,1,0,0,1,1);var c=this.game.input.hitContext.getImageData(0,0,1,1);if(c.data[3]>=this.pixelPerfectAlpha)return!0}return!1},update:function(a){return this.enabled===!1||this.sprite.visible===!1||this.sprite.group&&this.sprite.group.visible===!1?(this._pointerOutHandler(a),!1):this.draggable&&this._draggedPointerID==a.id?this.updateDrag(a):this._pointerData[a.id].isOver===!0?this.checkPointerOver(a)?(this._pointerData[a.id].x=a.x-this.sprite.x,this._pointerData[a.id].y=a.y-this.sprite.y,!0):(this._pointerOutHandler(a),!1):void 0},_pointerOverHandler:function(a){this._pointerData[a.id].isOver===!1&&(this._pointerData[a.id].isOver=!0,this._pointerData[a.id].isOut=!1,this._pointerData[a.id].timeOver=this.game.time.now,this._pointerData[a.id].x=a.x-this.sprite.x,this._pointerData[a.id].y=a.y-this.sprite.y,this.useHandCursor&&this._pointerData[a.id].isDragged===!1&&(this.game.canvas.style.cursor="pointer"),this.sprite.events.onInputOver.dispatch(this.sprite,a))},_pointerOutHandler:function(a){this._pointerData[a.id].isOver=!1,this._pointerData[a.id].isOut=!0,this._pointerData[a.id].timeOut=this.game.time.now,this.useHandCursor&&this._pointerData[a.id].isDragged===!1&&(this.game.canvas.style.cursor="default"),this.sprite&&this.sprite.events&&this.sprite.events.onInputOut.dispatch(this.sprite,a)},_touchedHandler:function(a){return this._pointerData[a.id].isDown===!1&&this._pointerData[a.id].isOver===!0&&(this._pointerData[a.id].isDown=!0,this._pointerData[a.id].isUp=!1,this._pointerData[a.id].timeDown=this.game.time.now,this.sprite.events.onInputDown.dispatch(this.sprite,a),this.draggable&&this.isDragged===!1&&this.startDrag(a),this.bringToTop&&this.sprite.bringToTop()),this.consumePointerEvent},_releasedHandler:function(a){this._pointerData[a.id].isDown&&a.isUp&&(this._pointerData[a.id].isDown=!1,this._pointerData[a.id].isUp=!0,this._pointerData[a.id].timeUp=this.game.time.now,this._pointerData[a.id].downDuration=this._pointerData[a.id].timeUp-this._pointerData[a.id].timeDown,this.checkPointerOver(a)?this.sprite.events.onInputUp.dispatch(this.sprite,a,!0):(this.sprite.events.onInputUp.dispatch(this.sprite,a,!1),this.useHandCursor&&(this.game.canvas.style.cursor="default")),this.draggable&&this.isDragged&&this._draggedPointerID==a.id&&this.stopDrag(a))},updateDrag:function(a){return a.isUp?(this.stopDrag(a),!1):(this.sprite.fixedToCamera?(this.allowHorizontalDrag&&(this.sprite.cameraOffset.x=a.x+this._dragPoint.x+this.dragOffset.x),this.allowVerticalDrag&&(this.sprite.cameraOffset.y=a.y+this._dragPoint.y+this.dragOffset.y),this.boundsRect&&this.checkBoundsRect(),this.boundsSprite&&this.checkBoundsSprite(),this.snapOnDrag&&(this.sprite.cameraOffset.x=Math.round((this.sprite.cameraOffset.x-this.snapOffsetX%this.snapX)/this.snapX)*this.snapX+this.snapOffsetX%this.snapX,this.sprite.cameraOffset.y=Math.round((this.sprite.cameraOffset.y-this.snapOffsetY%this.snapY)/this.snapY)*this.snapY+this.snapOffsetY%this.snapY)):(this.allowHorizontalDrag&&(this.sprite.x=a.x+this._dragPoint.x+this.dragOffset.x),this.allowVerticalDrag&&(this.sprite.y=a.y+this._dragPoint.y+this.dragOffset.y),this.boundsRect&&this.checkBoundsRect(),this.boundsSprite&&this.checkBoundsSprite(),this.snapOnDrag&&(this.sprite.x=Math.round((this.sprite.x-this.snapOffsetX%this.snapX)/this.snapX)*this.snapX+this.snapOffsetX%this.snapX,this.sprite.y=Math.round((this.sprite.y-this.snapOffsetY%this.snapY)/this.snapY)*this.snapY+this.snapOffsetY%this.snapY)),!0)},justOver:function(a,b){return a=a||0,b=b||500,this._pointerData[a].isOver&&this.overDuration(a)a;a++)this._pointerData[a].isDragged=!1;this.draggable=!1,this.isDragged=!1,this._draggedPointerID=-1},startDrag:function(a){this.isDragged=!0,this._draggedPointerID=a.id,this._pointerData[a.id].isDragged=!0,this.sprite.fixedToCamera?this.dragFromCenter?(this.sprite.centerOn(a.x,a.y),this._dragPoint.setTo(this.sprite.cameraOffset.x-a.x,this.sprite.cameraOffset.y-a.y)):this._dragPoint.setTo(this.sprite.cameraOffset.x-a.x,this.sprite.cameraOffset.y-a.y):this.dragFromCenter?(this.sprite.centerOn(a.x,a.y),this._dragPoint.setTo(this.sprite.x-a.x,this.sprite.y-a.y)):this._dragPoint.setTo(this.sprite.x-a.x,this.sprite.y-a.y),this.updateDrag(a),this.bringToTop&&this.sprite.bringToTop(),this.sprite.events.onDragStart.dispatch(this.sprite,a)},stopDrag:function(a){this.isDragged=!1,this._draggedPointerID=-1,this._pointerData[a.id].isDragged=!1,this.snapOnRelease&&(this.sprite.fixedToCamera?(this.sprite.cameraOffset.x=Math.round((this.sprite.cameraOffset.x-this.snapOffsetX%this.snapX)/this.snapX)*this.snapX+this.snapOffsetX%this.snapX,this.sprite.cameraOffset.y=Math.round((this.sprite.cameraOffset.y-this.snapOffsetY%this.snapY)/this.snapY)*this.snapY+this.snapOffsetY%this.snapY):(this.sprite.x=Math.round((this.sprite.x-this.snapOffsetX%this.snapX)/this.snapX)*this.snapX+this.snapOffsetX%this.snapX,this.sprite.y=Math.round((this.sprite.y-this.snapOffsetY%this.snapY)/this.snapY)*this.snapY+this.snapOffsetY%this.snapY)),this.sprite.events.onDragStop.dispatch(this.sprite,a),this.sprite.events.onInputUp.dispatch(this.sprite,a),this.checkPointerOver(a)===!1&&this._pointerOutHandler(a)},setDragLock:function(a,b){"undefined"==typeof a&&(a=!0),"undefined"==typeof b&&(b=!0),this.allowHorizontalDrag=a,this.allowVerticalDrag=b},enableSnap:function(a,b,c,d){"undefined"==typeof c&&(c=!0),"undefined"==typeof d&&(d=!1),"undefined"==typeof snapOffsetX&&(snapOffsetX=0),"undefined"==typeof snapOffsetY&&(snapOffsetY=0),this.snapX=a,this.snapY=b,this.snapOffsetX=snapOffsetX,this.snapOffsetY=snapOffsetY,this.snapOnDrag=c,this.snapOnRelease=d},disableSnap:function(){this.snapOnDrag=!1,this.snapOnRelease=!1},checkBoundsRect:function(){this.sprite.fixedToCamera?(this.sprite.cameraOffset.xthis.boundsRect.right&&(this.sprite.cameraOffset.x=this.boundsRect.right-this.sprite.width),this.sprite.cameraOffset.ythis.boundsRect.bottom&&(this.sprite.cameraOffset.y=this.boundsRect.bottom-this.sprite.height)):(this.sprite.xthis.boundsRect.right&&(this.sprite.x=this.boundsRect.right-this.sprite.width),this.sprite.ythis.boundsRect.bottom&&(this.sprite.y=this.boundsRect.bottom-this.sprite.height))},checkBoundsSprite:function(){this.sprite.fixedToCamera&&this.boundsSprite.fixedToCamera?(this.sprite.cameraOffset.xthis.boundsSprite.camerOffset.x+this.boundsSprite.width&&(this.sprite.cameraOffset.x=this.boundsSprite.camerOffset.x+this.boundsSprite.width-this.sprite.width),this.sprite.cameraOffset.ythis.boundsSprite.camerOffset.y+this.boundsSprite.height&&(this.sprite.cameraOffset.y=this.boundsSprite.camerOffset.y+this.boundsSprite.height-this.sprite.height)):(this.sprite.xthis.boundsSprite.x+this.boundsSprite.width&&(this.sprite.x=this.boundsSprite.x+this.boundsSprite.width-this.sprite.width),this.sprite.ythis.boundsSprite.y+this.boundsSprite.height&&(this.sprite.y=this.boundsSprite.y+this.boundsSprite.height-this.sprite.height))}},c.InputHandler.prototype.constructor=c.InputHandler,c.Gamepad=function(a){this.game=a,this._gamepads=[new c.SinglePad(a,this),new c.SinglePad(a,this),new c.SinglePad(a,this),new c.SinglePad(a,this)],this._gamepadIndexMap={},this._rawPads=[],this._active=!1,this.disabled=!1,this._gamepadSupportAvailable=!!navigator.webkitGetGamepads||!!navigator.webkitGamepads||-1!=navigator.userAgent.indexOf("Firefox/"),this._prevRawGamepadTypes=[],this._prevTimestamps=[],this.callbackContext=this,this.onConnectCallback=null,this.onDisconnectCallback=null,this.onDownCallback=null,this.onUpCallback=null,this.onAxisCallback=null,this.onFloatCallback=null,this._ongamepadconnected=null,this._gamepaddisconnected=null +},c.Gamepad.prototype={addCallbacks:function(a,b){"undefined"!=typeof b&&(this.onConnectCallback="function"==typeof b.onConnect?b.onConnect:this.onConnectCallback,this.onDisconnectCallback="function"==typeof b.onDisconnect?b.onDisconnect:this.onDisconnectCallback,this.onDownCallback="function"==typeof b.onDown?b.onDown:this.onDownCallback,this.onUpCallback="function"==typeof b.onUp?b.onUp:this.onUpCallback,this.onAxisCallback="function"==typeof b.onAxis?b.onAxis:this.onAxisCallback,this.onFloatCallback="function"==typeof b.onFloat?b.onFloat:this.onFloatCallback)},start:function(){this._active=!0;var a=this;this._ongamepadconnected=function(b){var c=b.gamepad;a._rawPads.push(c),a._gamepads[c.index].connect(c)},window.addEventListener("gamepadconnected",this._ongamepadconnected,!1),this._ongamepaddisconnected=function(b){var c=b.gamepad;for(var d in a._rawPads)a._rawPads[d].index===c.index&&a._rawPads.splice(d,1);a._gamepads[c.index].disconnect()},window.addEventListener("gamepaddisconnected",this._ongamepaddisconnected,!1)},update:function(){this._pollGamepads();for(var a=0;a0&&e>this.deadZone||0>e&&e<-this.deadZone?this.processAxisChange({axis:d,value:e}):this.processAxisChange({axis:d,value:0})}this._prevTimestamp=this._rawPad.timestamp}},connect:function(a){var b=!this._connected;this._index=a.index,this._connected=!0,this._rawPad=a,this._rawButtons=a.buttons,this._axes=a.axes,b&&this._padParent.onConnectCallback&&this._padParent.onConnectCallback.call(this._padParent.callbackContext,this._index),b&&this.onConnectCallback&&this.onConnectCallback.call(this.callbackContext)},disconnect:function(){var a=this._connected;this._connected=!1,this._rawPad=void 0,this._rawButtons=[],this._buttons=[];var b=this._index;this._index=null,a&&this._padParent.onDisconnectCallback&&this._padParent.onDisconnectCallback.call(this._padParent.callbackContext,b),a&&this.onDisconnectCallback&&this.onDisconnectCallback.call(this.callbackContext)},processAxisChange:function(a){this.game.input.disabled||this.game.input.gamepad.disabled||this._axes[a.axis]!==a.value&&(this._axes[a.axis]=a.value,this._padParent.onAxisCallback&&this._padParent.onAxisCallback.call(this._padParent.callbackContext,a,this._index),this.onAxisCallback&&this.onAxisCallback.call(this.callbackContext,a))},processButtonDown:function(a,b){this.game.input.disabled||this.game.input.gamepad.disabled||(this._padParent.onDownCallback&&this._padParent.onDownCallback.call(this._padParent.callbackContext,a,b,this._index),this.onDownCallback&&this.onDownCallback.call(this.callbackContext,a,b),this._buttons[a]&&this._buttons[a].isDown?this._buttons[a].duration=this.game.time.now-this._buttons[a].timeDown:this._buttons[a]?(this._buttons[a].isDown=!0,this._buttons[a].timeDown=this.game.time.now,this._buttons[a].duration=0,this._buttons[a].value=b):this._buttons[a]={isDown:!0,timeDown:this.game.time.now,timeUp:0,duration:0,value:b},this._hotkeys[a]&&this._hotkeys[a].processButtonDown(b))},processButtonUp:function(a,b){this.game.input.disabled||this.game.input.gamepad.disabled||(this._padParent.onUpCallback&&this._padParent.onUpCallback.call(this._padParent.callbackContext,a,b,this._index),this.onUpCallback&&this.onUpCallback.call(this.callbackContext,a,b),this._hotkeys[a]&&this._hotkeys[a].processButtonUp(b),this._buttons[a]?(this._buttons[a].isDown=!1,this._buttons[a].timeUp=this.game.time.now,this._buttons[a].value=b):this._buttons[a]={isDown:!1,timeDown:this.game.time.now,timeUp:this.game.time.now,duration:0,value:b})},processButtonFloat:function(a,b){this.game.input.disabled||this.game.input.gamepad.disabled||(this._padParent.onFloatCallback&&this._padParent.onFloatCallback.call(this._padParent.callbackContext,a,b,this._index),this.onFloatCallback&&this.onFloatCallback.call(this.callbackContext,a,b),this._buttons[a]?this._buttons[a].value=b:this._buttons[a]={value:b},this._hotkeys[a]&&this._hotkeys[a].processButtonFloat(b))},axis:function(a){return this._axes[a]?this._axes[a]:!1},isDown:function(a){return this._buttons[a]?this._buttons[a].isDown:!1},justReleased:function(a,b){return"undefined"==typeof b&&(b=250),this._buttons[a]&&this._buttons[a].isDown===!1&&this.game.time.now-this._buttons[a].timeUp=0&&a<=this.width&&b>=0&&b<=this.height&&(this.pixels[b*this.width+a]=f<<24|e<<16|d<<8|c,this.context.putImageData(this.imageData,0,0),this._dirty=!0)},setPixel:function(a,b,c,d,e){this.setPixel32(a,b,c,d,e,255)},getPixel:function(a,b){return a>=0&&a<=this.width&&b>=0&&b<=this.height?this.data32[b*this.width+a]:void 0},getPixel32:function(a,b){return a>=0&&a<=this.width&&b>=0&&b<=this.height?this.data32[b*this.width+a]:void 0},getPixels:function(a){return this.context.getImageData(a.x,a.y,a.width,a.height)},arc:function(a,b,c,d,e,f){return"undefined"==typeof f&&(f=!1),this._dirty=!0,this.context.arc(a,b,c,d,e,f),this},arcTo:function(a,b,c,d,e){return this._dirty=!0,this.context.arcTo(a,b,c,d,e),this},beginFill:function(a){return this.fillStyle(a),this},beginLinearGradientFill:function(a,b,c,d,e,f){for(var g=this.createLinearGradient(c,d,e,f),h=0,i=a.length;i>h;h++)g.addColorStop(b[h],a[h]);return this.fillStyle(g),this},beginLinearGradientStroke:function(a,b,c,d,e,f){for(var g=this.createLinearGradient(c,d,e,f),h=0,i=a.length;i>h;h++)g.addColorStop(b[h],a[h]);return this.strokeStyle(g),this},beginRadialGradientStroke:function(a,b,c,d,e,f,g,h){for(var i=this.createRadialGradient(c,d,e,f,g,h),j=0,k=a.length;k>j;j++)i.addColorStop(b[j],a[j]);return this.strokeStyle(i),this},beginPath:function(){return this.context.beginPath(),this},beginStroke:function(a){return this.strokeStyle(a),this},bezierCurveTo:function(a,b,c,d,e,f){return this._dirty=!0,this.context.bezierCurveTo(a,b,c,d,e,f),this},circle:function(a,b,c){return this.arc(a,b,c,0,2*Math.PI),this},clearRect:function(a,b,c,d){return this._dirty=!0,this.context.clearRect(a,b,c,d),this},clip:function(){return this._dirty=!0,this.context.clip(),this},closePath:function(){return this._dirty=!0,this.context.closePath(),this},createLinearGradient:function(a,b,c,d){return this.context.createLinearGradient(a,b,c,d)},createRadialGradient:function(a,b,c,d,e,f){return this.context.createRadialGradient(a,b,c,d,e,f)},ellipse:function(a,b,c,d){var e=.5522848,f=c/2*e,g=d/2*e,h=a+c,i=b+d,j=a+c/2,k=b+d/2;return this.moveTo(a,k),this.bezierCurveTo(a,k-g,j-f,b,j,b),this.bezierCurveTo(j+f,b,h,k-g,h,k),this.bezierCurveTo(h,k+g,j+f,i,j,i),this.bezierCurveTo(j-f,i,a,k+g,a,k),this},fill:function(){return this._dirty=!0,this.context.fill(),this},fillRect:function(a,b,c,d){return this._dirty=!0,this.context.fillRect(a,b,c,d),this},fillStyle:function(a){return this.context.fillStyle=a,this},font:function(a){return this.context.font=a,this},globalAlpha:function(a){return this.context.globalAlpha=a,this},globalCompositeOperation:function(a){return this.context.globalCompositeOperation=a,this},lineCap:function(a){return this.context.lineCap=a,this},lineDashOffset:function(a){return this.context.lineDashOffset=a,this},lineJoin:function(a){return this.context.lineJoin=a,this},lineWidth:function(a){return this.context.lineWidth=a,this},miterLimit:function(a){return this.context.miterLimit=a,this},lineTo:function(a,b){return this._dirty=!0,this.context.lineTo(a,b),this},moveTo:function(a,b){return this.context.moveTo(a,b),this},quadraticCurveTo:function(a,b,c,d){return this._dirty=!0,this.context.quadraticCurveTo(a,b,c,d),this},rect:function(a,b,c,d){return this._dirty=!0,this.context.rect(a,b,c,d),this},restore:function(){return this._dirty=!0,this.context.restore(),this},rotate:function(a){return this._dirty=!0,this.context.rotate(a),this},setStrokeStyle:function(a,b,c,d,e){return"undefined"==typeof a&&(a=1),"undefined"==typeof b&&(b="butt"),"undefined"==typeof c&&(c="miter"),"undefined"==typeof d&&(d=10),e=!1,this.lineWidth(a),this.lineCap(b),this.lineJoin(c),this.miterLimit(d),this},save:function(){return this._dirty=!0,this.context.save(),this},scale:function(a,b){return this._dirty=!0,this.context.scale(a,b),this},scrollPathIntoView:function(){return this._dirty=!0,this.context.scrollPathIntoView(),this},stroke:function(){return this._dirty=!0,this.context.stroke(),this},strokeRect:function(a,b,c,d){return this._dirty=!0,this.context.strokeRect(a,b,c,d),this},strokeStyle:function(a){return this.context.strokeStyle=a,this},render:function(){this._dirty&&(this.game.renderType==c.WEBGL&&b.texturesToUpdate.push(this.baseTexture),this._dirty=!1)}},c.BitmapData.prototype.constructor=c.BitmapData,c.BitmapData.prototype.mt=c.BitmapData.prototype.moveTo,c.BitmapData.prototype.lt=c.BitmapData.prototype.lineTo,c.BitmapData.prototype.at=c.BitmapData.prototype.arcTo,c.BitmapData.prototype.bt=c.BitmapData.prototype.bezierCurveTo,c.BitmapData.prototype.qt=c.BitmapData.prototype.quadraticCurveTo,c.BitmapData.prototype.a=c.BitmapData.prototype.arc,c.BitmapData.prototype.r=c.BitmapData.prototype.rect,c.BitmapData.prototype.cp=c.BitmapData.prototype.closePath,c.BitmapData.prototype.c=c.BitmapData.prototype.clear,c.BitmapData.prototype.f=c.BitmapData.prototype.beginFill,c.BitmapData.prototype.lf=c.BitmapData.prototype.beginLinearGradientFill,c.BitmapData.prototype.rf=c.BitmapData.prototype.beginRadialGradientFill,c.BitmapData.prototype.ef=c.BitmapData.prototype.endFill,c.BitmapData.prototype.ss=c.BitmapData.prototype.setStrokeStyle,c.BitmapData.prototype.s=c.BitmapData.prototype.beginStroke,c.BitmapData.prototype.ls=c.BitmapData.prototype.beginLinearGradientStroke,c.BitmapData.prototype.rs=c.BitmapData.prototype.beginRadialGradientStroke,c.BitmapData.prototype.dr=c.BitmapData.prototype.rect,c.BitmapData.prototype.dc=c.BitmapData.prototype.circle,c.BitmapData.prototype.de=c.BitmapData.prototype.ellipse,c.Sprite=function(a,d,e,f,g){d=d||0,e=e||0,f=f||null,g=g||null,this.game=a,this.exists=!0,this.alive=!0,this.group=null,this.name="",this.type=c.SPRITE,this.renderOrderID=-1,this.lifespan=0,this.events=new c.Events(this),this.animations=new c.AnimationManager(this),this.input=new c.InputHandler(this),this.key=f,this.currentFrame=null,f instanceof c.RenderTexture?(b.Sprite.call(this,f),this.currentFrame=this.game.cache.getTextureFrame(f.name)):f instanceof c.BitmapData?(b.Sprite.call(this,f.texture,f.textureFrame),this.currentFrame=f.textureFrame):f instanceof b.Texture?(b.Sprite.call(this,f),this.currentFrame=g):(null===f||"undefined"==typeof f?(f="__default",this.key=f):"string"==typeof f&&this.game.cache.checkImageKey(f)===!1&&(f="__missing",this.key=f),b.Sprite.call(this,b.TextureCache[f]),this.game.cache.isSpriteSheet(f)?(this.animations.loadFrameData(this.game.cache.getFrameData(f)),null!==g&&("string"==typeof g?this.frameName=g:this.frame=g)):this.currentFrame=this.game.cache.getFrame(f)),this.textureRegion=new c.Rectangle(this.texture.frame.x,this.texture.frame.y,this.texture.frame.width,this.texture.frame.height),this.anchor=new c.Point,this.x=d,this.y=e,this.position.x=d,this.position.y=e,this.world=new c.Point(d,e),this.autoCull=!1,this.scale=new c.Point(1,1),this._cache={dirty:!1,a00:-1,a01:-1,a02:-1,a10:-1,a11:-1,a12:-1,id:-1,i01:-1,i10:-1,idi:-1,left:null,right:null,top:null,bottom:null,prevX:d,prevY:e,x:-1,y:-1,scaleX:1,scaleY:1,width:this.currentFrame.sourceSizeW,height:this.currentFrame.sourceSizeH,halfWidth:Math.floor(this.currentFrame.sourceSizeW/2),halfHeight:Math.floor(this.currentFrame.sourceSizeH/2),calcWidth:-1,calcHeight:-1,frameID:-1,frameWidth:this.currentFrame.width,frameHeight:this.currentFrame.height,cameraVisible:!0,cropX:0,cropY:0,cropWidth:this.currentFrame.sourceSizeW,cropHeight:this.currentFrame.sourceSizeH},this.offset=new c.Point,this.center=new c.Point(d+Math.floor(this._cache.width/2),e+Math.floor(this._cache.height/2)),this.topLeft=new c.Point(d,e),this.topRight=new c.Point(d+this._cache.width,e),this.bottomRight=new c.Point(d+this._cache.width,e+this._cache.height),this.bottomLeft=new c.Point(d,e+this._cache.height),this.bounds=new c.Rectangle(d,e,this._cache.width,this._cache.height),this.body=new c.Physics.Arcade.Body(this),this.health=1,this.inWorld=c.Rectangle.intersects(this.bounds,this.game.world.bounds),this.inWorldThreshold=0,this.outOfBoundsKill=!1,this._outOfBoundsFired=!1,this.fixedToCamera=!1,this.cameraOffset=new c.Point(d,e),this.crop=new c.Rectangle(0,0,this._cache.width,this._cache.height),this.cropEnabled=!1,this.updateCache(),this.updateBounds()},c.Sprite.prototype=Object.create(b.Sprite.prototype),c.Sprite.prototype.constructor=c.Sprite,c.Sprite.prototype.preUpdate=function(){return!this.exists||this.group&&!this.group.exists?(this.renderOrderID=-1,!1):this.lifespan>0&&(this.lifespan-=this.game.time.elapsed,this.lifespan<=0)?(this.kill(),!1):(this._cache.dirty=!1,this.visible&&(this.renderOrderID=this.game.world.currentRenderOrderID++),this.updateCache(),this.updateAnimation(),this.updateCrop(),(this._cache.dirty||this.world.x!==this._cache.prevX||this.world.y!==this._cache.prevY)&&this.updateBounds(),this.body&&this.body.preUpdate(),!0)},c.Sprite.prototype.updateCache=function(){this._cache.prevX=this.world.x,this._cache.prevY=this.world.y,this.fixedToCamera&&(this.x=this.game.camera.view.x+this.cameraOffset.x,this.y=this.game.camera.view.y+this.cameraOffset.y),this.world.setTo(this.game.camera.x+this.worldTransform[2],this.game.camera.y+this.worldTransform[5]),(this.worldTransform[1]!=this._cache.i01||this.worldTransform[3]!=this._cache.i10||this.worldTransform[0]!=this._cache.a00||this.worldTransform[41]!=this._cache.a11)&&(this._cache.a00=this.worldTransform[0],this._cache.a01=this.worldTransform[1],this._cache.a10=this.worldTransform[3],this._cache.a11=this.worldTransform[4],this._cache.i01=this.worldTransform[1],this._cache.i10=this.worldTransform[3],this._cache.scaleX=Math.sqrt(this._cache.a00*this._cache.a00+this._cache.a01*this._cache.a01),this._cache.scaleY=Math.sqrt(this._cache.a10*this._cache.a10+this._cache.a11*this._cache.a11),this._cache.a01*=-1,this._cache.a10*=-1,this._cache.id=1/(this._cache.a00*this._cache.a11+this._cache.a01*-this._cache.a10),this._cache.idi=1/(this._cache.a00*this._cache.a11+this._cache.i01*-this._cache.i10),this._cache.dirty=!0),this._cache.a02=this.worldTransform[2],this._cache.a12=this.worldTransform[5]},c.Sprite.prototype.updateAnimation=function(){(this.animations.update()||this.currentFrame&&this.currentFrame.uuid!=this._cache.frameID)&&(this._cache.frameID=this.currentFrame.uuid,this._cache.frameWidth=this.texture.frame.width,this._cache.frameHeight=this.texture.frame.height,this._cache.width=this.currentFrame.width,this._cache.height=this.currentFrame.height,this._cache.halfWidth=Math.floor(this._cache.width/2),this._cache.halfHeight=Math.floor(this._cache.height/2),this._cache.dirty=!0)},c.Sprite.prototype.updateCrop=function(){!this.cropEnabled||this.crop.width==this._cache.cropWidth&&this.crop.height==this._cache.cropHeight&&this.crop.x==this._cache.cropX&&this.crop.y==this._cache.cropY||(this.crop.floorAll(),this._cache.cropX=this.crop.x,this._cache.cropY=this.crop.y,this._cache.cropWidth=this.crop.width,this._cache.cropHeight=this.crop.height,this.texture.frame=this.crop,this.texture.width=this.crop.width,this.texture.height=this.crop.height,this.texture.updateFrame=!0,b.Texture.frameUpdates.push(this.texture))},c.Sprite.prototype.updateBounds=function(){this.offset.setTo(this._cache.a02-this.anchor.x*this.width,this._cache.a12-this.anchor.y*this.height),this.getLocalPosition(this.center,this.offset.x+this.width/2,this.offset.y+this.height/2),this.getLocalPosition(this.topLeft,this.offset.x,this.offset.y),this.getLocalPosition(this.topRight,this.offset.x+this.width,this.offset.y),this.getLocalPosition(this.bottomLeft,this.offset.x,this.offset.y+this.height),this.getLocalPosition(this.bottomRight,this.offset.x+this.width,this.offset.y+this.height),this._cache.left=c.Math.min(this.topLeft.x,this.topRight.x,this.bottomLeft.x,this.bottomRight.x),this._cache.right=c.Math.max(this.topLeft.x,this.topRight.x,this.bottomLeft.x,this.bottomRight.x),this._cache.top=c.Math.min(this.topLeft.y,this.topRight.y,this.bottomLeft.y,this.bottomRight.y),this._cache.bottom=c.Math.max(this.topLeft.y,this.topRight.y,this.bottomLeft.y,this.bottomRight.y),this.bounds.setTo(this._cache.left,this._cache.top,this._cache.right-this._cache.left,this._cache.bottom-this._cache.top),this.updateFrame=!0,this.inWorld===!1?(this.inWorld=c.Rectangle.intersects(this.bounds,this.game.world.bounds,this.inWorldThreshold),this.inWorld&&(this._outOfBoundsFired=!1)):(this.inWorld=c.Rectangle.intersects(this.bounds,this.game.world.bounds,this.inWorldThreshold),this.inWorld===!1&&(this.events.onOutOfBounds.dispatch(this),this._outOfBoundsFired=!0,this.outOfBoundsKill&&this.kill())),this._cache.cameraVisible=c.Rectangle.intersects(this.game.world.camera.screenView,this.bounds,0),this.autoCull&&(this.renderable=this._cache.cameraVisible),this.body&&this.body.updateBounds(this.center.x,this.center.y,this._cache.scaleX,this._cache.scaleY)},c.Sprite.prototype.getLocalPosition=function(a,b,c){return a.x=(this._cache.a11*this._cache.id*b+-this._cache.a01*this._cache.id*c+(this._cache.a12*this._cache.a01-this._cache.a02*this._cache.a11)*this._cache.id)*this.scale.x+this._cache.a02,a.y=(this._cache.a00*this._cache.id*c+-this._cache.a10*this._cache.id*b+(-this._cache.a12*this._cache.a00+this._cache.a02*this._cache.a10)*this._cache.id)*this.scale.y+this._cache.a12,a},c.Sprite.prototype.getLocalUnmodifiedPosition=function(a,b,c){return a.x=this._cache.a11*this._cache.idi*b+-this._cache.i01*this._cache.idi*c+(this._cache.a12*this._cache.i01-this._cache.a02*this._cache.a11)*this._cache.idi+this.anchor.x*this._cache.width,a.y=this._cache.a00*this._cache.idi*c+-this._cache.i10*this._cache.idi*b+(-this._cache.a12*this._cache.a00+this._cache.a02*this._cache.i10)*this._cache.idi+this.anchor.y*this._cache.height,a},c.Sprite.prototype.resetCrop=function(){this.crop=new c.Rectangle(0,0,this._cache.width,this._cache.height),this.texture.setFrame(this.crop),this.cropEnabled=!1},c.Sprite.prototype.postUpdate=function(){this.key instanceof c.BitmapData&&this.key._dirty&&this.key.render(),this.exists&&(this.body&&this.body.postUpdate(),this.fixedToCamera?(this._cache.x=this.game.camera.view.x+this.cameraOffset.x,this._cache.y=this.game.camera.view.y+this.cameraOffset.y):(this._cache.x=this.x,this._cache.y=this.y),this.world.setTo(this.game.camera.x+this.worldTransform[2],this.game.camera.y+this.worldTransform[5]),this.position.x=this._cache.x,this.position.y=this._cache.y)},c.Sprite.prototype.loadTexture=function(a,d){this.key=a,a instanceof c.RenderTexture?this.currentFrame=this.game.cache.getTextureFrame(a.name):a instanceof c.BitmapData?(this.setTexture(a.texture),this.currentFrame=a.textureFrame):a instanceof b.Texture?this.currentFrame=d:(("undefined"==typeof a||this.game.cache.checkImageKey(a)===!1)&&(a="__default",this.key=a),this.game.cache.isSpriteSheet(a)?(this.animations.loadFrameData(this.game.cache.getFrameData(a)),"undefined"!=typeof d&&("string"==typeof d?this.frameName=d:this.frame=d)):(this.currentFrame=this.game.cache.getFrame(a),this.setTexture(b.TextureCache[a])))},c.Sprite.prototype.centerOn=function(a,b){return this.fixedToCamera?(this.cameraOffset.x=a+(this.cameraOffset.x-this.center.x),this.cameraOffset.y=b+(this.cameraOffset.y-this.center.y)):(this.x=a+(this.x-this.center.x),this.y=b+(this.y-this.center.y)),this},c.Sprite.prototype.revive=function(a){return"undefined"==typeof a&&(a=1),this.alive=!0,this.exists=!0,this.visible=!0,this.health=a,this.events&&this.events.onRevived.dispatch(this),this},c.Sprite.prototype.kill=function(){return this.alive=!1,this.exists=!1,this.visible=!1,this.events&&this.events.onKilled.dispatch(this),this},c.Sprite.prototype.destroy=function(){this.filters&&(this.filters=null),this.group&&this.group.remove(this),this.input&&this.input.destroy(),this.events&&this.events.destroy(),this.animations&&this.animations.destroy(),this.alive=!1,this.exists=!1,this.visible=!1,this.game=null},c.Sprite.prototype.damage=function(a){return this.alive&&(this.health-=a,this.health<0&&this.kill()),this},c.Sprite.prototype.reset=function(a,b,c){return"undefined"==typeof c&&(c=1),this.x=a,this.y=b,this.position.x=this.x,this.position.y=this.y,this.alive=!0,this.exists=!0,this.visible=!0,this.renderable=!0,this._outOfBoundsFired=!1,this.health=c,this.body&&this.body.reset(),this},c.Sprite.prototype.bringToTop=function(){return this.group?this.group.bringToTop(this):this.game.world.bringToTop(this),this},c.Sprite.prototype.play=function(a,b,c,d){return this.animations?this.animations.play(a,b,c,d):void 0},Object.defineProperty(c.Sprite.prototype,"angle",{get:function(){return c.Math.wrapAngle(c.Math.radToDeg(this.rotation))},set:function(a){this.rotation=c.Math.degToRad(c.Math.wrapAngle(a))}}),Object.defineProperty(c.Sprite.prototype,"frame",{get:function(){return this.animations.frame},set:function(a){this.animations.frame=a}}),Object.defineProperty(c.Sprite.prototype,"frameName",{get:function(){return this.animations.frameName},set:function(a){this.animations.frameName=a}}),Object.defineProperty(c.Sprite.prototype,"inCamera",{get:function(){return this._cache.cameraVisible}}),Object.defineProperty(c.Sprite.prototype,"width",{get:function(){return this.scale.x*this.currentFrame.width},set:function(a){this.scale.x=a/this.currentFrame.width,this._cache.scaleX=a/this.currentFrame.width,this._width=a}}),Object.defineProperty(c.Sprite.prototype,"height",{get:function(){return this.scale.y*this.currentFrame.height},set:function(a){this.scale.y=a/this.currentFrame.height,this._cache.scaleY=a/this.currentFrame.height,this._height=a}}),Object.defineProperty(c.Sprite.prototype,"inputEnabled",{get:function(){return this.input.enabled},set:function(a){a?this.input.enabled===!1&&this.input.start():this.input.enabled&&this.input.stop()}}),c.TileSprite=function(a,d,e,f,g,h){d=d||0,e=e||0,f=f||256,g=g||256,h=h||null,c.Sprite.call(this,a,d,e,h),this.texture=b.TextureCache[h],b.TilingSprite.call(this,this.texture,f,g),this.type=c.TILESPRITE,this.tileScale=new c.Point(1,1),this.tilePosition=new c.Point(0,0),this.body.width=f,this.body.height=g +},c.TileSprite.prototype=c.Utils.extend(!0,b.TilingSprite.prototype,c.Sprite.prototype),c.TileSprite.prototype.constructor=c.TileSprite,Object.defineProperty(c.TileSprite.prototype,"angle",{get:function(){return c.Math.wrapAngle(c.Math.radToDeg(this.rotation))},set:function(a){this.rotation=c.Math.degToRad(c.Math.wrapAngle(a))}}),Object.defineProperty(c.TileSprite.prototype,"frame",{get:function(){return this.animations.frame},set:function(a){this.animations.frame=a}}),Object.defineProperty(c.TileSprite.prototype,"frameName",{get:function(){return this.animations.frameName},set:function(a){this.animations.frameName=a}}),Object.defineProperty(c.TileSprite.prototype,"inCamera",{get:function(){return this._cache.cameraVisible}}),Object.defineProperty(c.TileSprite.prototype,"inputEnabled",{get:function(){return this.input.enabled},set:function(a){a?this.input.enabled===!1&&this.input.start():this.input.enabled&&this.input.stop()}}),c.Text=function(a,d,e,f,g){d=d||0,e=e||0,f=f||"",g=g||"",this.game=a,this.exists=!0,this.alive=!0,this.group=null,this.name="",this.type=c.TEXT,this._text=f,this._style=g,b.Text.call(this,f,g),this.position.x=this.x=d,this.position.y=this.y=e,this.anchor=new c.Point,this.scale=new c.Point(1,1),this.fixedToCamera=!1,this.cameraOffset=new c.Point,this._cache={dirty:!1,a00:1,a01:0,a02:d,a10:0,a11:1,a12:e,id:1,x:-1,y:-1,scaleX:1,scaleY:1},this._cache.x=this.x,this._cache.y=this.y,this.renderable=!0},c.Text.prototype=Object.create(b.Text.prototype),c.Text.prototype.constructor=c.Text,c.Text.prototype.update=function(){this.exists&&(this.fixedToCamera&&(this.x=this.game.camera.view.x+this.cameraOffset.x,this.y=this.game.camera.view.y+this.cameraOffset.y),this._cache.dirty=!1,this._cache.x=this.x,this._cache.y=this.y,(this.position.x!=this._cache.x||this.position.y!=this._cache.y)&&(this.position.x=this._cache.x,this.position.y=this._cache.y,this._cache.dirty=!0))},c.Text.prototype.destroy=function(){this.group&&this.group.remove(this),this.canvas.parentNode?this.canvas.parentNode.removeChild(this.canvas):(this.canvas=null,this.context=null),this.exists=!1,this.group=null},Object.defineProperty(c.Text.prototype,"angle",{get:function(){return c.Math.radToDeg(this.rotation)},set:function(a){this.rotation=c.Math.degToRad(a)}}),Object.defineProperty(c.Text.prototype,"x",{get:function(){return this.position.x},set:function(a){this.position.x=a}}),Object.defineProperty(c.Text.prototype,"y",{get:function(){return this.position.y},set:function(a){this.position.y=a}}),Object.defineProperty(c.Text.prototype,"content",{get:function(){return this._text},set:function(a){a!==this._text&&(this._text=a,this.setText(a))}}),Object.defineProperty(c.Text.prototype,"font",{get:function(){return this._style},set:function(a){a!==this._style&&(this._style=a,this.setStyle(a))}}),c.BitmapText=function(a,d,e,f,g){d=d||0,e=e||0,f=f||"",g=g||"",this.game=a,this.exists=!0,this.alive=!0,this.group=null,this.name="",this.type=c.BITMAPTEXT,b.BitmapText.call(this,f,g),this.position.x=d,this.position.y=e,this.anchor=new c.Point,this.scale=new c.Point(1,1),this._cache={dirty:!1,a00:1,a01:0,a02:d,a10:0,a11:1,a12:e,id:1,x:-1,y:-1,scaleX:1,scaleY:1},this._cache.x=this.x,this._cache.y=this.y},c.BitmapText.prototype=Object.create(b.BitmapText.prototype),c.BitmapText.prototype.constructor=c.BitmapText,c.BitmapText.prototype.update=function(){this.exists&&(this._cache.dirty=!1,this._cache.x=this.x,this._cache.y=this.y,(this.position.x!=this._cache.x||this.position.y!=this._cache.y)&&(this.position.x=this._cache.x,this.position.y=this._cache.y,this._cache.dirty=!0),this.pivot.x=this.anchor.x*this.width,this.pivot.y=this.anchor.y*this.height)},c.BitmapText.prototype.destroy=function(){this.group&&this.group.remove(this),this.canvas&&this.canvas.parentNode?this.canvas.parentNode.removeChild(this.canvas):(this.canvas=null,this.context=null),this.exists=!1,this.group=null},Object.defineProperty(c.BitmapText.prototype,"angle",{get:function(){return c.Math.radToDeg(this.rotation)},set:function(a){this.rotation=c.Math.degToRad(a)}}),Object.defineProperty(c.BitmapText.prototype,"x",{get:function(){return this.position.x},set:function(a){this.position.x=a}}),Object.defineProperty(c.BitmapText.prototype,"y",{get:function(){return this.position.y},set:function(a){this.position.y=a}}),c.Button=function(a,b,d,e,f,g,h,i,j,k){b=b||0,d=d||0,e=e||null,f=f||null,g=g||this,c.Sprite.call(this,a,b,d,e,i),this.type=c.BUTTON,this._onOverFrameName=null,this._onOutFrameName=null,this._onDownFrameName=null,this._onUpFrameName=null,this._onOverFrameID=null,this._onOutFrameID=null,this._onDownFrameID=null,this._onUpFrameID=null,this.onOverSound=null,this.onOutSound=null,this.onDownSound=null,this.onUpSound=null,this.onOverSoundMarker="",this.onOutSoundMarker="",this.onDownSoundMarker="",this.onUpSoundMarker="",this.onInputOver=new c.Signal,this.onInputOut=new c.Signal,this.onInputDown=new c.Signal,this.onInputUp=new c.Signal,this.freezeFrames=!1,this.forceOut=!1,this.setFrames(h,i,j,k),null!==f&&this.onInputUp.add(f,g),this.input.start(0,!0),this.events.onInputOver.add(this.onInputOverHandler,this),this.events.onInputOut.add(this.onInputOutHandler,this),this.events.onInputDown.add(this.onInputDownHandler,this),this.events.onInputUp.add(this.onInputUpHandler,this)},c.Button.prototype=Object.create(c.Sprite.prototype),c.Button.prototype=c.Utils.extend(!0,c.Button.prototype,c.Sprite.prototype,b.Sprite.prototype),c.Button.prototype.constructor=c.Button,c.Button.prototype.clearFrames=function(){this._onOverFrameName=null,this._onOverFrameID=null,this._onOutFrameName=null,this._onOutFrameID=null,this._onDownFrameName=null,this._onDownFrameID=null,this._onUpFrameName=null,this._onUpFrameID=null},c.Button.prototype.setFrames=function(a,b,c,d){this.clearFrames(),null!==a&&("string"==typeof a?(this._onOverFrameName=a,this.input.pointerOver()&&(this.frameName=a)):(this._onOverFrameID=a,this.input.pointerOver()&&(this.frame=a))),null!==b&&("string"==typeof b?(this._onOutFrameName=b,this.input.pointerOver()===!1&&(this.frameName=b)):(this._onOutFrameID=b,this.input.pointerOver()===!1&&(this.frame=b))),null!==c&&("string"==typeof c?(this._onDownFrameName=c,this.input.pointerDown()&&(this.frameName=c)):(this._onDownFrameID=c,this.input.pointerDown()&&(this.frame=c))),null!==d&&("string"==typeof d?(this._onUpFrameName=d,this.input.pointerUp()&&(this.frameName=d)):(this._onUpFrameID=d,this.input.pointerUp()&&(this.frame=d)))},c.Button.prototype.setSounds=function(a,b,c,d,e,f,g,h){this.setOverSound(a,b),this.setOutSound(e,f),this.setDownSound(c,d),this.setUpSound(g,h)},c.Button.prototype.setOverSound=function(a,b){this.onOverSound=null,this.onOverSoundMarker="",a instanceof c.Sound&&(this.onOverSound=a),"string"==typeof b&&(this.onOverSoundMarker=b)},c.Button.prototype.setOutSound=function(a,b){this.onOutSound=null,this.onOutSoundMarker="",a instanceof c.Sound&&(this.onOutSound=a),"string"==typeof b&&(this.onOutSoundMarker=b)},c.Button.prototype.setDownSound=function(a,b){this.onDownSound=null,this.onDownSoundMarker="",a instanceof c.Sound&&(this.onDownSound=a),"string"==typeof b&&(this.onDownSoundMarker=b)},c.Button.prototype.setUpSound=function(a,b){this.onUpSound=null,this.onUpSoundMarker="",a instanceof c.Sound&&(this.onUpSound=a),"string"==typeof b&&(this.onUpSoundMarker=b)},c.Button.prototype.onInputOverHandler=function(a,b){this.freezeFrames===!1&&this.setState(1),this.onOverSound&&this.onOverSound.play(this.onOverSoundMarker),this.onInputOver&&this.onInputOver.dispatch(this,b)},c.Button.prototype.onInputOutHandler=function(a,b){this.freezeFrames===!1&&this.setState(2),this.onOutSound&&this.onOutSound.play(this.onOutSoundMarker),this.onInputOut&&this.onInputOut.dispatch(this,b)},c.Button.prototype.onInputDownHandler=function(a,b){this.freezeFrames===!1&&this.setState(3),this.onDownSound&&this.onDownSound.play(this.onDownSoundMarker),this.onInputDown&&this.onInputDown.dispatch(this,b)},c.Button.prototype.onInputUpHandler=function(a,b,c){this.onUpSound&&this.onUpSound.play(this.onUpSoundMarker),this.onInputUp&&this.onInputUp.dispatch(this,b,c),this.freezeFrames||(this.forceOut?this.setState(2):this._onUpFrameName||this._onUpFrameID?this.setState(4):c?this.setState(1):this.setState(2))},c.Button.prototype.setState=function(a){1===a?null!=this._onOverFrameName?this.frameName=this._onOverFrameName:null!=this._onOverFrameID&&(this.frame=this._onOverFrameID):2===a?null!=this._onOutFrameName?this.frameName=this._onOutFrameName:null!=this._onOutFrameID&&(this.frame=this._onOutFrameID):3===a?null!=this._onDownFrameName?this.frameName=this._onDownFrameName:null!=this._onDownFrameID&&(this.frame=this._onDownFrameID):4===a&&(null!=this._onUpFrameName?this.frameName=this._onUpFrameName:null!=this._onUpFrameID&&(this.frame=this._onUpFrameID))},c.Graphics=function(a,d,e){this.game=a,b.Graphics.call(this),this.type=c.GRAPHICS,this.position.x=d,this.position.y=e},c.Graphics.prototype=Object.create(b.Graphics.prototype),c.Graphics.prototype.constructor=c.Graphics,c.Graphics.prototype.destroy=function(){this.clear(),this.group&&this.group.remove(this),this.game=null},c.Graphics.prototype.drawPolygon=function(a){this.moveTo(a.points[0].x,a.points[0].y);for(var b=1;bh;h++)f[h].updateTransform();var j=a.__renderGroup;j?a==j.root?j.render(this.projection,this.glFramebuffer):j.renderSpecific(a,this.projection,this.glFramebuffer):(this.renderGroup||(this.renderGroup=new b.WebGLRenderGroup(e)),this.renderGroup.setRenderable(a),this.renderGroup.render(this.projection,this.glFramebuffer)),a.worldTransform=g},c.RenderTexture.prototype.renderCanvas=function(a,c,d,e){var f=a.children;a.worldTransform=b.mat3.create(),c&&(a.worldTransform[2]=c.x,a.worldTransform[5]=c.y);for(var g=0,h=f.length;h>g;g++)f[g].updateTransform();d&&this.renderer.context.clearRect(0,0,this.width,this.height),this.renderer.renderDisplayObject(a,e),this.renderer.context.setTransform(1,0,0,1,0,0)},c.Canvas={create:function(a,b,c){a=a||256,b=b||256;var d=document.createElement("canvas");return"string"==typeof c&&(d.id=c),d.width=a,d.height=b,d.style.display="block",d},getOffset:function(a,b){b=b||new c.Point;var d=a.getBoundingClientRect(),e=a.clientTop||document.body.clientTop||0,f=a.clientLeft||document.body.clientLeft||0,g=0,h=0;return"CSS1Compat"===document.compatMode?(g=window.pageYOffset||document.documentElement.scrollTop||a.scrollTop||0,h=window.pageXOffset||document.documentElement.scrollLeft||a.scrollLeft||0):(g=window.pageYOffset||document.body.scrollTop||a.scrollTop||0,h=window.pageXOffset||document.body.scrollLeft||a.scrollLeft||0),b.x=d.left+h-f,b.y=d.top+g-e,b},getAspectRatio:function(a){return a.width/a.height},setBackgroundColor:function(a,b){return b=b||"rgb(0,0,0)",a.style.backgroundColor=b,a},setTouchAction:function(a,b){return b=b||"none",a.style.msTouchAction=b,a.style["ms-touch-action"]=b,a.style["touch-action"]=b,a},setUserSelect:function(a,b){return b=b||"none",a.style["-webkit-touch-callout"]=b,a.style["-webkit-user-select"]=b,a.style["-khtml-user-select"]=b,a.style["-moz-user-select"]=b,a.style["-ms-user-select"]=b,a.style["user-select"]=b,a.style["-webkit-tap-highlight-color"]="rgba(0, 0, 0, 0)",a},addToDOM:function(a,b,c){var d;return"undefined"==typeof c&&(c=!0),b&&("string"==typeof b?d=document.getElementById(b):"object"==typeof b&&1===b.nodeType&&(d=b)),d||(d=document.body),c&&d.style&&(d.style.overflow="hidden"),d.appendChild(a),a},setTransform:function(a,b,c,d,e,f,g){return a.setTransform(d,f,g,e,b,c),a},setSmoothingEnabled:function(a,b){return a.imageSmoothingEnabled=b,a.mozImageSmoothingEnabled=b,a.oImageSmoothingEnabled=b,a.webkitImageSmoothingEnabled=b,a.msImageSmoothingEnabled=b,a},setImageRenderingCrisp:function(a){return a.style["image-rendering"]="optimizeSpeed",a.style["image-rendering"]="crisp-edges",a.style["image-rendering"]="-moz-crisp-edges",a.style["image-rendering"]="-webkit-optimize-contrast",a.style["image-rendering"]="optimize-contrast",a.style.msInterpolationMode="nearest-neighbor",a},setImageRenderingBicubic:function(a){return a.style["image-rendering"]="auto",a.style.msInterpolationMode="bicubic",a}},c.StageScaleMode=function(a,b,d){this.game=a,this.width=b,this.height=d,this.minWidth=null,this.maxWidth=null,this.minHeight=null,this.maxHeight=null,this._startHeight=0,this.forceLandscape=!1,this.forcePortrait=!1,this.incorrectOrientation=!1,this.pageAlignHorizontally=!1,this.pageAlignVertically=!1,this._width=0,this._height=0,this.maxIterations=5,this.orientationSprite=null,this.enterLandscape=new c.Signal,this.enterPortrait=new c.Signal,this.enterIncorrectOrientation=new c.Signal,this.leaveIncorrectOrientation=new c.Signal,this.hasResized=new c.Signal,this.orientation=window.orientation?window.orientation:window.outerWidth>window.outerHeight?90:0,this.scaleFactor=new c.Point(1,1),this.scaleFactorInversed=new c.Point(1,1),this.margin=new c.Point(0,0),this.aspectRatio=0,this.event=null;var e=this;window.addEventListener("orientationchange",function(a){return e.checkOrientation(a)},!1),window.addEventListener("resize",function(a){return e.checkResize(a)},!1),document.addEventListener("webkitfullscreenchange",function(a){return e.fullScreenChange(a)},!1),document.addEventListener("mozfullscreenchange",function(a){return e.fullScreenChange(a)},!1),document.addEventListener("fullscreenchange",function(a){return e.fullScreenChange(a)},!1)},c.StageScaleMode.EXACT_FIT=0,c.StageScaleMode.NO_SCALE=1,c.StageScaleMode.SHOW_ALL=2,c.StageScaleMode.prototype={startFullScreen:function(a){if(!this.isFullScreen){"undefined"!=typeof a&&c.Canvas.setSmoothingEnabled(this.game.context,a);var b=this.game.canvas;this._width=this.width,this._height=this.height,b.requestFullScreen?b.requestFullScreen():b.mozRequestFullScreen?b.parentNode.mozRequestFullScreen():b.webkitRequestFullScreen&&b.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT)}},stopFullScreen:function(){document.cancelFullScreen?document.cancelFullScreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen&&document.webkitCancelFullScreen()},fullScreenChange:function(a){this.event=a,this.isFullScreen?this.game.stage.fullScreenScaleMode===c.StageScaleMode.EXACT_FIT?(this.game.stage.canvas.style.width="100%",this.game.stage.canvas.style.height="100%",this.setMaximum(),this.game.input.scale.setTo(this.game.width/this.width,this.game.height/this.height),this.aspectRatio=this.width/this.height,this.scaleFactor.x=this.game.width/this.width,this.scaleFactor.y=this.game.height/this.height):this.game.stage.fullScreenScaleMode===c.StageScaleMode.SHOW_ALL&&(this.game.stage.scale.setShowAll(),this.game.stage.scale.refresh()):(this.game.stage.canvas.style.width=this.game.width+"px",this.game.stage.canvas.style.height=this.game.height+"px",this.width=this._width,this.height=this._height,this.game.input.scale.setTo(this.game.width/this.width,this.game.height/this.height),this.aspectRatio=this.width/this.height,this.scaleFactor.x=this.game.width/this.width,this.scaleFactor.y=this.game.height/this.height)},forceOrientation:function(a,c,d){"undefined"==typeof c&&(c=!1),this.forceLandscape=a,this.forcePortrait=c,"undefined"!=typeof d&&((null==d||this.game.cache.checkImageKey(d)===!1)&&(d="__default"),this.orientationSprite=new b.Sprite(b.TextureCache[d]),this.orientationSprite.anchor.x=.5,this.orientationSprite.anchor.y=.5,this.orientationSprite.position.x=this.game.width/2,this.orientationSprite.position.y=this.game.height/2,this.checkOrientationState(),this.incorrectOrientation?(this.orientationSprite.visible=!0,this.game.world.visible=!1):(this.orientationSprite.visible=!1,this.game.world.visible=!0),this.game.stage._stage.addChild(this.orientationSprite))},checkOrientationState:function(){this.incorrectOrientation?(this.forceLandscape&&window.innerWidth>window.innerHeight||this.forcePortrait&&window.innerHeight>window.innerWidth)&&(this.game.paused=!1,this.incorrectOrientation=!1,this.leaveIncorrectOrientation.dispatch(),this.orientationSprite&&(this.orientationSprite.visible=!1,this.game.world.visible=!0),this.refresh()):(this.forceLandscape&&window.innerWidthwindow.outerHeight?90:0,this.isLandscape?this.enterLandscape.dispatch(this.orientation,!0,!1):this.enterPortrait.dispatch(this.orientation,!1,!0),this.game.stage.scaleMode!==c.StageScaleMode.NO_SCALE&&this.refresh(),this.checkOrientationState()},refresh:function(){if(this.game.device.iPad===!1&&this.game.device.webApp===!1&&this.game.device.desktop===!1&&(this.game.device.android&&this.game.device.chrome===!1?window.scrollTo(0,1):window.scrollTo(0,0)),null==this._check&&this.maxIterations>0){this._iterations=this.maxIterations;var a=this;this._check=window.setInterval(function(){return a.setScreenSize()},10),this.setScreenSize()}},setScreenSize:function(a){"undefined"==typeof a&&(a=!1),this.game.device.iPad===!1&&this.game.device.webApp===!1&&this.game.device.desktop===!1&&(this.game.device.android&&this.game.device.chrome===!1?window.scrollTo(0,1):window.scrollTo(0,0)),this._iterations--,(a||window.innerHeight>this._startHeight||this._iterations<0)&&(document.documentElement.style.minHeight=window.innerHeight+"px",this.incorrectOrientation===!0?this.setMaximum():this.isFullScreen?this.game.stage.fullScreenScaleMode==c.StageScaleMode.EXACT_FIT?this.setExactFit():this.game.stage.fullScreenScaleMode==c.StageScaleMode.SHOW_ALL&&this.setShowAll():this.game.stage.scaleMode==c.StageScaleMode.EXACT_FIT?this.setExactFit():this.game.stage.scaleMode==c.StageScaleMode.SHOW_ALL&&this.setShowAll(),this.setSize(),clearInterval(this._check),this._check=null)},setSize:function(){this.incorrectOrientation===!1&&(this.maxWidth&&this.width>this.maxWidth&&(this.width=this.maxWidth),this.maxHeight&&this.height>this.maxHeight&&(this.height=this.maxHeight),this.minWidth&&this.widththis.maxWidth?this.maxWidth:a,this.height=this.maxHeight&&b>this.maxHeight?this.maxHeight:b}},c.StageScaleMode.prototype.constructor=c.StageScaleMode,Object.defineProperty(c.StageScaleMode.prototype,"isFullScreen",{get:function(){return document.fullscreenElement||document.mozFullScreenElement||document.webkitFullscreenElement}}),Object.defineProperty(c.StageScaleMode.prototype,"isPortrait",{get:function(){return 0===this.orientation||180==this.orientation}}),Object.defineProperty(c.StageScaleMode.prototype,"isLandscape",{get:function(){return 90===this.orientation||-90===this.orientation}}),c.Device=function(){this.patchAndroidClearRectBug=!1,this.desktop=!1,this.iOS=!1,this.cocoonJS=!1,this.ejecta=!1,this.android=!1,this.chromeOS=!1,this.linux=!1,this.macOS=!1,this.windows=!1,this.canvas=!1,this.file=!1,this.fileSystem=!1,this.localStorage=!1,this.webGL=!1,this.worker=!1,this.touch=!1,this.mspointer=!1,this.css3D=!1,this.pointerLock=!1,this.typedArray=!1,this.vibration=!1,this.quirksMode=!1,this.arora=!1,this.chrome=!1,this.epiphany=!1,this.firefox=!1,this.ie=!1,this.ieVersion=0,this.trident=!1,this.tridentVersion=0,this.mobileSafari=!1,this.midori=!1,this.opera=!1,this.safari=!1,this.webApp=!1,this.silk=!1,this.audioData=!1,this.webAudio=!1,this.ogg=!1,this.opus=!1,this.mp3=!1,this.wav=!1,this.m4a=!1,this.webm=!1,this.iPhone=!1,this.iPhone4=!1,this.iPad=!1,this.pixelRatio=0,this.littleEndian=!1,this._checkAudio(),this._checkBrowser(),this._checkCSS3D(),this._checkDevice(),this._checkFeatures(),this._checkOS()},c.Device.prototype={_checkOS:function(){var a=navigator.userAgent;/Android/.test(a)?this.android=!0:/CrOS/.test(a)?this.chromeOS=!0:/iP[ao]d|iPhone/i.test(a)?this.iOS=!0:/Linux/.test(a)?this.linux=!0:/Mac OS/.test(a)?this.macOS=!0:/Windows/.test(a)&&(this.windows=!0),(this.windows||this.macOS||this.linux&&this.silk===!1)&&(this.desktop=!0)},_checkFeatures:function(){this.canvas=!!window.CanvasRenderingContext2D;try{this.localStorage=!!localStorage.getItem}catch(a){this.localStorage=!1}this.file=!!(window.File&&window.FileReader&&window.FileList&&window.Blob),this.fileSystem=!!window.requestFileSystem,this.webGL=function(){try{var a=document.createElement("canvas");return!!window.WebGLRenderingContext&&(a.getContext("webgl")||a.getContext("experimental-webgl"))}catch(b){return!1}}(),this.webGL=null===this.webGL||this.webGL===!1?!1:!0,this.worker=!!window.Worker,("ontouchstart"in document.documentElement||window.navigator.maxTouchPoints&&window.navigator.maxTouchPoints>1)&&(this.touch=!0),(window.navigator.msPointerEnabled||window.navigator.pointerEnabled)&&(this.mspointer=!0),this.pointerLock="pointerLockElement"in document||"mozPointerLockElement"in document||"webkitPointerLockElement"in document,this.quirksMode="CSS1Compat"===document.compatMode?!1:!0},_checkBrowser:function(){var a=navigator.userAgent;/Arora/.test(a)?this.arora=!0:/Chrome/.test(a)?this.chrome=!0:/Epiphany/.test(a)?this.epiphany=!0:/Firefox/.test(a)?this.firefox=!0:/Mobile Safari/.test(a)?this.mobileSafari=!0:/MSIE (\d+\.\d+);/.test(a)?(this.ie=!0,this.ieVersion=parseInt(RegExp.$1,10)):/Midori/.test(a)?this.midori=!0:/Opera/.test(a)?this.opera=!0:/Safari/.test(a)?this.safari=!0:/Silk/.test(a)?this.silk=!0:/Trident\/(\d+\.\d+);/.test(a)&&(this.ie=!0,this.trident=!0,this.tridentVersion=parseInt(RegExp.$1,10)),navigator.standalone&&(this.webApp=!0),navigator.isCocoonJS&&(this.cocoonJS=!0),"undefined"!=typeof window.ejecta&&(this.ejecta=!0)},_checkAudio:function(){this.audioData=!!window.Audio,this.webAudio=!(!window.webkitAudioContext&&!window.AudioContext);var a=document.createElement("audio"),b=!1;try{(b=!!a.canPlayType)&&(a.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,"")&&(this.ogg=!0),a.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/,"")&&(this.opus=!0),a.canPlayType("audio/mpeg;").replace(/^no$/,"")&&(this.mp3=!0),a.canPlayType('audio/wav; codecs="1"').replace(/^no$/,"")&&(this.wav=!0),(a.canPlayType("audio/x-m4a;")||a.canPlayType("audio/aac;").replace(/^no$/,""))&&(this.m4a=!0),a.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/,"")&&(this.webm=!0))}catch(c){}},_checkDevice:function(){this.pixelRatio=window.devicePixelRatio||1,this.iPhone=-1!=navigator.userAgent.toLowerCase().indexOf("iphone"),this.iPhone4=2==this.pixelRatio&&this.iPhone,this.iPad=-1!=navigator.userAgent.toLowerCase().indexOf("ipad"),"undefined"!=typeof Int8Array?(this.littleEndian=new Int8Array(new Int16Array([1]).buffer)[0]>0,this.typedArray=!0):(this.littleEndian=!1,this.typedArray=!1),navigator.vibrate=navigator.vibrate||navigator.webkitVibrate||navigator.mozVibrate||navigator.msVibrate,navigator.vibrate&&(this.vibration=!0)},_checkCSS3D:function(){var a,b=document.createElement("p"),c={webkitTransform:"-webkit-transform",OTransform:"-o-transform",msTransform:"-ms-transform",MozTransform:"-moz-transform",transform:"transform"};document.body.insertBefore(b,null);for(var d in c)void 0!==b.style[d]&&(b.style[d]="translate3d(1px,1px,1px)",a=window.getComputedStyle(b).getPropertyValue(c[d]));document.body.removeChild(b),this.css3D=void 0!==a&&a.length>0&&"none"!==a},canPlayAudio:function(a){return"mp3"==a&&this.mp3?!0:"ogg"==a&&(this.ogg||this.opus)?!0:"m4a"==a&&this.m4a?!0:"wav"==a&&this.wav?!0:"webm"==a&&this.webm?!0:!1},isConsoleOpen:function(){return window.console&&window.console.firebug?!0:window.console?(console.profile(),console.profileEnd(),console.clear&&console.clear(),console.profiles.length>0):!1}},c.Device.prototype.constructor=c.Device,c.RequestAnimationFrame=function(a){this.game=a,this.isRunning=!1;for(var b=["ms","moz","webkit","o"],c=0;c>>0,b-=d,b*=d,d=b>>>0,b-=d,d+=4294967296*b;return 2.3283064365386963e-10*(d>>>0)},integer:function(){return 4294967296*this.rnd.apply(this)},frac:function(){return this.rnd.apply(this)+1.1102230246251565e-16*(0|2097152*this.rnd.apply(this))},real:function(){return this.integer()+this.frac()},integerInRange:function(a,b){return Math.floor(this.realInRange(a,b))},realInRange:function(a,b){return this.frac()*(b-a)+a},normal:function(){return 1-2*this.frac()},uuid:function(){var a="",b="";for(b=a="";a++<36;b+=~a%5|4&3*a?(15^a?8^this.frac()*(20^a?16:4):4).toString(16):"-");return b},pick:function(a){return a[this.integerInRange(0,a.length)]},weightedPick:function(a){return a[~~(Math.pow(this.frac(),2)*a.length)]},timestamp:function(a,b){return this.realInRange(a||9466848e5,b||1577862e6)},angle:function(){return this.integerInRange(-180,180)}},c.RandomDataGenerator.prototype.constructor=c.RandomDataGenerator,c.Math={PI2:2*Math.PI,fuzzyEqual:function(a,b,c){return"undefined"==typeof c&&(c=1e-4),Math.abs(a-b)a},fuzzyGreaterThan:function(a,b,c){return"undefined"==typeof c&&(c=1e-4),a>b-c},fuzzyCeil:function(a,b){return"undefined"==typeof b&&(b=1e-4),Math.ceil(a-b)},fuzzyFloor:function(a,b){return"undefined"==typeof b&&(b=1e-4),Math.floor(a+b)},average:function(){for(var a=[],b=0;b0?Math.floor(a):Math.ceil(a)},shear:function(a){return a%1},snapTo:function(a,b,c){return"undefined"==typeof c&&(c=0),0===b?a:(a-=c,a=b*Math.round(a/b),c+a)},snapToFloor:function(a,b,c){return"undefined"==typeof c&&(c=0),0===b?a:(a-=c,a=b*Math.floor(a/b),c+a)},snapToCeil:function(a,b,c){return"undefined"==typeof c&&(c=0),0===b?a:(a-=c,a=b*Math.ceil(a/b),c+a)},snapToInArray:function(a,b,c){if("undefined"==typeof c&&(c=!0),c&&b.sort(),a=f-a?f:e},roundTo:function(a,b,c){"undefined"==typeof b&&(b=0),"undefined"==typeof c&&(c=10);var d=Math.pow(c,-b);return Math.round(a*d)/d},floorTo:function(a,b,c){"undefined"==typeof b&&(b=0),"undefined"==typeof c&&(c=10);var d=Math.pow(c,-b);return Math.floor(a*d)/d},ceilTo:function(a,b,c){"undefined"==typeof b&&(b=0),"undefined"==typeof c&&(c=10);var d=Math.pow(c,-b);return Math.ceil(a*d)/d},interpolateFloat:function(a,b,c){return(b-a)*c+a},angleBetween:function(a,b,c,d){return Math.atan2(d-b,c-a)},normalizeAngle:function(a,b){"undefined"==typeof b&&(b=!0);var c=b?Math.PI:180;return this.wrap(a,-c,c)},nearestAngleBetween:function(a,b,c){"undefined"==typeof c&&(c=!0);var d=c?Math.PI:180;return a=this.normalizeAngle(a,c),b=this.normalizeAngle(b,c),-d/2>a&&b>d/2&&(a+=2*d),-d/2>b&&a>d/2&&(b+=2*d),b-a},interpolateAngles:function(a,b,c,d,e){return"undefined"==typeof d&&(d=!0),"undefined"==typeof e&&(e=null),a=this.normalizeAngle(a,d),b=this.normalizeAngleToAnother(b,a,d),"function"==typeof e?e(c,a,b-a,1):this.interpolateFloat(a,b,c)},chanceRoll:function(a){return"undefined"==typeof a&&(a=50),0>=a?!1:a>=100?!0:100*Math.random()>=a?!1:!0},numberArray:function(a,b){for(var c=[],d=a;b>=d;d++)c.push(d);return c},maxAdd:function(a,b,c){return a+=b,a>c&&(a=c),a},minSub:function(a,b,c){return a-=b,c>a&&(a=c),a},wrap:function(a,b,c){var d=c-b;if(0>=d)return 0;var e=(a-b)%d;return 0>e&&(e+=d),e+b},wrapValue:function(a,b,c){var d;return a=Math.abs(a),b=Math.abs(b),c=Math.abs(c),d=(a+b)%c},randomSign:function(){return Math.random()>.5?1:-1},isOdd:function(a){return 1&a},isEven:function(a){return 1&a?!1:!0},max:function(){for(var a=1,b=0,c=arguments.length;c>a;a++)arguments[b]a;a++)arguments[a]c?d=c:b>a&&(d=b),d},linearInterpolation:function(a,b){var c=a.length-1,d=c*b,e=Math.floor(d);return 0>b?this.linear(a[0],a[1],d):b>1?this.linear(a[c],a[c-1],c-d):this.linear(a[e],a[e+1>c?c:e+1],d-e)},bezierInterpolation:function(a,b){for(var c=0,d=a.length-1,e=0;d>=e;e++)c+=Math.pow(1-b,d-e)*Math.pow(b,e)*a[e]*this.bernstein(d,e);return c},catmullRomInterpolation:function(a,b){var c=a.length-1,d=c*b,e=Math.floor(d);return a[0]===a[c]?(0>b&&(e=Math.floor(d=c*(1+b))),this.catmullRom(a[(e-1+c)%c],a[e],a[(e+1)%c],a[(e+2)%c],d-e)):0>b?a[0]-(this.catmullRom(a[0],a[0],a[1],a[1],-d)-a[0]):b>1?a[c]-(this.catmullRom(a[c],a[c],a[c-1],a[c-1],d-c)-a[c]):this.catmullRom(a[e?e-1:0],a[e],a[e+1>c?c:e+1],a[e+2>c?c:e+2],d-e)},linear:function(a,b,c){return(b-a)*c+a},bernstein:function(a,b){return this.factorial(a)/this.factorial(b)/this.factorial(a-b)},catmullRom:function(a,b,c,d,e){var f=.5*(c-a),g=.5*(d-b),h=e*e,i=e*h;return(2*b-2*c+f+g)*i+(-3*b+3*c-2*f-g)*h+f*e+b},difference:function(a,b){return Math.abs(a-b)},getRandom:function(a,b,c){if("undefined"==typeof b&&(b=0),"undefined"==typeof c&&(c=0),null!=a){var d=c;if((0===d||d>a.length-b)&&(d=a.length-b),d>0)return a[b+Math.floor(Math.random()*d)]}return null},floor:function(a){var b=0|a;return a>0?b:b!=a?b-1:b},ceil:function(a){var b=0|a;return a>0?b!=a?b+1:b:b},sinCosGenerator:function(a,b,c,d){"undefined"==typeof b&&(b=1),"undefined"==typeof c&&(c=1),"undefined"==typeof d&&(d=1);for(var e=b,f=c,g=d*Math.PI/a,h=[],i=[],j=0;a>j;j++)f-=e*g,e+=f*g,h[j]=f,i[j]=e;return{sin:i,cos:h,length:a}},shift:function(a){var b=a.shift();return a.push(b),b},shuffleArray:function(a){for(var b=a.length-1;b>0;b--){var c=Math.floor(Math.random()*(b+1)),d=a[b];a[b]=a[c],a[c]=d}return a},distance:function(a,b,c,d){var e=a-c,f=b-d;return Math.sqrt(e*e+f*f)},distanceRounded:function(a,b,d,e){return Math.round(c.Math.distance(a,b,d,e))},clamp:function(a,b,c){return b>a?b:a>c?c:a},clampBottom:function(a,b){return b>a?b:a},within:function(a,b,c){return Math.abs(a-b)<=c},mapLinear:function(a,b,c,d,e){return d+(a-b)*(e-d)/(c-b)},smoothstep:function(a,b,c){return b>=a?0:a>=c?1:(a=(a-b)/(c-b),a*a*(3-2*a))},smootherstep:function(a,b,c){return b>=a?0:a>=c?1:(a=(a-b)/(c-b),a*a*a*(a*(6*a-15)+10))},sign:function(a){return 0>a?-1:a>0?1:0},degToRad:function(){var a=Math.PI/180;return function(b){return b*a}}(),radToDeg:function(){var a=180/Math.PI;return function(b){return b*a}}()},c.QuadTree=function(a,b,c,d,e,f,g,h){this.physicsManager=a,this.ID=a.quadTreeID,a.quadTreeID++,this.maxObjects=f||10,this.maxLevels=g||4,this.level=h||0,this.bounds={x:Math.round(b),y:Math.round(c),width:d,height:e,subWidth:Math.floor(d/2),subHeight:Math.floor(e/2),right:Math.round(b)+Math.floor(d/2),bottom:Math.round(c)+Math.floor(e/2)},this.objects=[],this.nodes=[]},c.QuadTree.prototype={split:function(){this.level++,this.nodes[0]=new c.QuadTree(this.physicsManager,this.bounds.right,this.bounds.y,this.bounds.subWidth,this.bounds.subHeight,this.maxObjects,this.maxLevels,this.level),this.nodes[1]=new c.QuadTree(this.physicsManager,this.bounds.x,this.bounds.y,this.bounds.subWidth,this.bounds.subHeight,this.maxObjects,this.maxLevels,this.level),this.nodes[2]=new c.QuadTree(this.physicsManager,this.bounds.x,this.bounds.bottom,this.bounds.subWidth,this.bounds.subHeight,this.maxObjects,this.maxLevels,this.level),this.nodes[3]=new c.QuadTree(this.physicsManager,this.bounds.right,this.bounds.bottom,this.bounds.subWidth,this.bounds.subHeight,this.maxObjects,this.maxLevels,this.level)},insert:function(a){var b,c=0;if(null!=this.nodes[0]&&(b=this.getIndex(a),-1!==b))return this.nodes[b].insert(a),void 0;if(this.objects.push(a),this.objects.length>this.maxObjects&&this.levelthis.bounds.bottom&&(b=2):a.x>this.bounds.right&&(a.ythis.bounds.bottom&&(b=3)),b},retrieve:function(a){var b=this.objects;return a.body.quadTreeIndex=this.getIndex(a.body),a.body.quadTreeIDs.push(this.ID),this.nodes[0]&&(-1!==a.body.quadTreeIndex?b=b.concat(this.nodes[a.body.quadTreeIndex].retrieve(a)):(b=b.concat(this.nodes[0].retrieve(a)),b=b.concat(this.nodes[1].retrieve(a)),b=b.concat(this.nodes[2].retrieve(a)),b=b.concat(this.nodes[3].retrieve(a)))),b},clear:function(){this.objects=[];for(var a=0,b=this.nodes.length;b>a;a++)this.nodes[a]&&(this.nodes[a].clear(),delete this.nodes[a])}},c.QuadTree.prototype.constructor=c.QuadTree,c.Circle=function(a,b,c){a=a||0,b=b||0,c=c||0,this.x=a,this.y=b,this._diameter=c,this._radius=c>0?.5*c:0},c.Circle.prototype={circumference:function(){return 2*Math.PI*this._radius},setTo:function(a,b,c){return this.x=a,this.y=b,this._diameter=c,this._radius=.5*c,this},copyFrom:function(a){return this.setTo(a.x,a.y,a.diameter)},copyTo:function(a){return a.x=this.x,a.y=this.y,a.diameter=this._diameter,a},distance:function(a,b){return"undefined"==typeof b&&(b=!1),b?c.Math.distanceRound(this.x,this.y,a.x,a.y):c.Math.distance(this.x,this.y,a.x,a.y)},clone:function(a){return"undefined"==typeof a&&(a=new c.Circle),a.setTo(this.x,this.y,this.diameter)},contains:function(a,b){return c.Circle.contains(this,a,b)},circumferencePoint:function(a,b,d){return c.Circle.circumferencePoint(this,a,b,d)},offset:function(a,b){return this.x+=a,this.y+=b,this},offsetPoint:function(a){return this.offset(a.x,a.y)},toString:function(){return"[{Phaser.Circle (x="+this.x+" y="+this.y+" diameter="+this.diameter+" radius="+this.radius+")}]"}},c.Circle.prototype.constructor=c.Circle,Object.defineProperty(c.Circle.prototype,"diameter",{get:function(){return this._diameter},set:function(a){a>0&&(this._diameter=a,this._radius=.5*a)}}),Object.defineProperty(c.Circle.prototype,"radius",{get:function(){return this._radius},set:function(a){a>0&&(this._radius=a,this._diameter=2*a)}}),Object.defineProperty(c.Circle.prototype,"left",{get:function(){return this.x-this._radius},set:function(a){a>this.x?(this._radius=0,this._diameter=0):this.radius=this.x-a}}),Object.defineProperty(c.Circle.prototype,"right",{get:function(){return this.x+this._radius},set:function(a){athis.y?(this._radius=0,this._diameter=0):this.radius=this.y-a}}),Object.defineProperty(c.Circle.prototype,"bottom",{get:function(){return this.y+this._radius},set:function(a){a0?Math.PI*this._radius*this._radius:0}}),Object.defineProperty(c.Circle.prototype,"empty",{get:function(){return 0===this._diameter},set:function(a){a===!0&&this.setTo(0,0,0)}}),c.Circle.contains=function(a,b,c){if(b>=a.left&&b<=a.right&&c>=a.top&&c<=a.bottom){var d=(a.x-b)*(a.x-b),e=(a.y-c)*(a.y-c);return d+e<=a.radius*a.radius}return!1},c.Circle.equals=function(a,b){return a.x==b.x&&a.y==b.y&&a.diameter==b.diameter},c.Circle.intersects=function(a,b){return c.Math.distance(a.x,a.y,b.x,b.y)<=a.radius+b.radius},c.Circle.circumferencePoint=function(a,b,d,e){return"undefined"==typeof d&&(d=!1),"undefined"==typeof e&&(e=new c.Point),d===!0&&(b=c.Math.radToDeg(b)),e.x=a.x+a.radius*Math.cos(b),e.y=a.y+a.radius*Math.sin(b),e},c.Circle.intersectsRectangle=function(a,b){var c=Math.abs(a.x-b.x-b.halfWidth),d=b.halfWidth+a.radius;if(c>d)return!1;var e=Math.abs(a.y-b.y-b.halfHeight),f=b.halfHeight+a.radius;if(e>f)return!1;if(c<=b.halfWidth||e<=b.halfHeight)return!0;var g=c-b.halfWidth,h=e-b.halfHeight,i=g*g,j=h*h,k=a.radius*a.radius;return k>=i+j},c.Point=function(a,b){a=a||0,b=b||0,this.x=a,this.y=b},c.Point.prototype={copyFrom:function(a){return this.setTo(a.x,a.y)},invert:function(){return this.setTo(this.y,this.x)},setTo:function(a,b){return this.x=a,this.y=b,this},add:function(a,b){return this.x+=a,this.y+=b,this},subtract:function(a,b){return this.x-=a,this.y-=b,this},multiply:function(a,b){return this.x*=a,this.y*=b,this},divide:function(a,b){return this.x/=a,this.y/=b,this},clampX:function(a,b){return this.x=c.Math.clamp(this.x,a,b),this},clampY:function(a,b){return this.y=c.Math.clamp(this.y,a,b),this},clamp:function(a,b){return this.x=c.Math.clamp(this.x,a,b),this.y=c.Math.clamp(this.y,a,b),this},clone:function(a){return"undefined"==typeof a&&(a=new c.Point),a.setTo(this.x,this.y)},copyTo:function(a){return a.x=this.x,a.y=this.y,a},distance:function(a,b){return c.Point.distance(this,a,b)},equals:function(a){return a.x==this.x&&a.y==this.y},rotate:function(a,b,d,e,f){return c.Point.rotate(this,a,b,d,e,f)},getMagnitude:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},setMagnitude:function(a){return this.normalize().multiply(a,a)},normalize:function(){if(!this.isZero()){var a=this.getMagnitude();this.x/=a,this.y/=a}return this},isZero:function(){return 0===this.x&&0===this.y},toString:function(){return"[{Point (x="+this.x+" y="+this.y+")}]"}},c.Point.prototype.constructor=c.Point,c.Point.add=function(a,b,d){return"undefined"==typeof d&&(d=new c.Point),d.x=a.x+b.x,d.y=a.y+b.y,d},c.Point.subtract=function(a,b,d){return"undefined"==typeof d&&(d=new c.Point),d.x=a.x-b.x,d.y=a.y-b.y,d},c.Point.multiply=function(a,b,d){return"undefined"==typeof d&&(d=new c.Point),d.x=a.x*b.x,d.y=a.y*b.y,d},c.Point.divide=function(a,b,d){return"undefined"==typeof d&&(d=new c.Point),d.x=a.x/b.x,d.y=a.y/b.y,d},c.Point.equals=function(a,b){return a.x==b.x&&a.y==b.y},c.Point.distance=function(a,b,d){return"undefined"==typeof d&&(d=!1),d?c.Math.distanceRound(a.x,a.y,b.x,b.y):c.Math.distance(a.x,a.y,b.x,b.y)},c.Point.rotate=function(a,b,d,e,f,g){return f=f||!1,g=g||null,f&&(e=c.Math.degToRad(e)),null===g&&(g=Math.sqrt((b-a.x)*(b-a.x)+(d-a.y)*(d-a.y))),a.setTo(b+g*Math.cos(e),d+g*Math.sin(e))},c.Rectangle=function(a,b,c,d){a=a||0,b=b||0,c=c||0,d=d||0,this.x=a,this.y=b,this.width=c,this.height=d},c.Rectangle.prototype={offset:function(a,b){return this.x+=a,this.y+=b,this},offsetPoint:function(a){return this.offset(a.x,a.y)},setTo:function(a,b,c,d){return this.x=a,this.y=b,this.width=c,this.height=d,this},floor:function(){this.x=Math.floor(this.x),this.y=Math.floor(this.y)},floorAll:function(){this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.width=Math.floor(this.width),this.height=Math.floor(this.height)},copyFrom:function(a){return this.setTo(a.x,a.y,a.width,a.height)},copyTo:function(a){return a.x=this.x,a.y=this.y,a.width=this.width,a.height=this.height,a},inflate:function(a,b){return c.Rectangle.inflate(this,a,b)},size:function(a){return c.Rectangle.size(this,a)},clone:function(a){return c.Rectangle.clone(this,a)},contains:function(a,b){return c.Rectangle.contains(this,a,b)},containsRect:function(a){return c.Rectangle.containsRect(this,a)},equals:function(a){return c.Rectangle.equals(this,a)},intersection:function(a,b){return c.Rectangle.intersection(this,a,b)},intersects:function(a,b){return c.Rectangle.intersects(this,a,b)},intersectsRaw:function(a,b,d,e,f){return c.Rectangle.intersectsRaw(this,a,b,d,e,f)},union:function(a,b){return c.Rectangle.union(this,a,b)},toString:function(){return"[{Rectangle (x="+this.x+" y="+this.y+" width="+this.width+" height="+this.height+" empty="+this.empty+")}]"}},c.Rectangle.prototype.constructor=c.Rectangle,Object.defineProperty(c.Rectangle.prototype,"halfWidth",{get:function(){return Math.round(this.width/2)}}),Object.defineProperty(c.Rectangle.prototype,"halfHeight",{get:function(){return Math.round(this.height/2)}}),Object.defineProperty(c.Rectangle.prototype,"bottom",{get:function(){return this.y+this.height},set:function(a){this.height=a<=this.y?0:this.y-a}}),Object.defineProperty(c.Rectangle.prototype,"bottomRight",{get:function(){return new c.Point(this.right,this.bottom)},set:function(a){this.right=a.x,this.bottom=a.y}}),Object.defineProperty(c.Rectangle.prototype,"left",{get:function(){return this.x},set:function(a){this.width=a>=this.right?0:this.right-a,this.x=a}}),Object.defineProperty(c.Rectangle.prototype,"right",{get:function(){return this.x+this.width},set:function(a){this.width=a<=this.x?0:this.x+a}}),Object.defineProperty(c.Rectangle.prototype,"volume",{get:function(){return this.width*this.height}}),Object.defineProperty(c.Rectangle.prototype,"perimeter",{get:function(){return 2*this.width+2*this.height}}),Object.defineProperty(c.Rectangle.prototype,"centerX",{get:function(){return this.x+this.halfWidth},set:function(a){this.x=a-this.halfWidth}}),Object.defineProperty(c.Rectangle.prototype,"centerY",{get:function(){return this.y+this.halfHeight},set:function(a){this.y=a-this.halfHeight}}),Object.defineProperty(c.Rectangle.prototype,"top",{get:function(){return this.y},set:function(a){a>=this.bottom?(this.height=0,this.y=a):this.height=this.bottom-a}}),Object.defineProperty(c.Rectangle.prototype,"topLeft",{get:function(){return new c.Point(this.x,this.y)},set:function(a){this.x=a.x,this.y=a.y}}),Object.defineProperty(c.Rectangle.prototype,"empty",{get:function(){return!this.width||!this.height},set:function(a){a===!0&&this.setTo(0,0,0,0)}}),c.Rectangle.inflate=function(a,b,c){return a.x-=b,a.width+=2*b,a.y-=c,a.height+=2*c,a},c.Rectangle.inflatePoint=function(a,b){return c.Rectangle.inflate(a,b.x,b.y)},c.Rectangle.size=function(a,b){return"undefined"==typeof b&&(b=new c.Point),b.setTo(a.width,a.height)},c.Rectangle.clone=function(a,b){return"undefined"==typeof b&&(b=new c.Rectangle),b.setTo(a.x,a.y,a.width,a.height)},c.Rectangle.contains=function(a,b,c){return b>=a.x&&b<=a.right&&c>=a.y&&c<=a.bottom},c.Rectangle.containsRaw=function(a,b,c,d,e,f){return e>=a&&a+c>=e&&f>=b&&b+d>=f},c.Rectangle.containsPoint=function(a,b){return c.Rectangle.contains(a,b.x,b.y)},c.Rectangle.containsRect=function(a,b){return a.volume>b.volume?!1:a.x>=b.x&&a.y>=b.y&&a.right<=b.right&&a.bottom<=b.bottom},c.Rectangle.equals=function(a,b){return a.x==b.x&&a.y==b.y&&a.width==b.width&&a.height==b.height},c.Rectangle.intersection=function(a,b,d){return d=d||new c.Rectangle,c.Rectangle.intersects(a,b)&&(d.x=Math.max(a.x,b.x),d.y=Math.max(a.y,b.y),d.width=Math.min(a.right,b.right)-d.x,d.height=Math.min(a.bottom,b.bottom)-d.y),d},c.Rectangle.intersects=function(a,b){return a.width<=0||a.height<=0||b.width<=0||b.height<=0?!1:!(a.rightb.right||a.y>b.bottom)},c.Rectangle.intersectsRaw=function(a,b,c,d,e,f){return"undefined"==typeof f&&(f=0),!(b>a.right+f||ca.bottom+f||e1){if(a&&a==this.decodeURI(e[0]))return this.decodeURI(e[1]);b[this.decodeURI(e[0])]=this.decodeURI(e[1])}}return b},decodeURI:function(a){return decodeURIComponent(a.replace(/\+/g," "))}},c.Net.prototype.constructor=c.Net,c.TweenManager=function(a){this.game=a,this._tweens=[],this._add=[],this.game.onPause.add(this.pauseAll,this),this.game.onResume.add(this.resumeAll,this)},c.TweenManager.prototype={REVISION:"11dev",getAll:function(){return this._tweens},removeAll:function(){this._tweens=[]},add:function(a){this._add.push(a)},create:function(a){return new c.Tween(a,this.game)},remove:function(a){var b=this._tweens.indexOf(a);-1!==b&&(this._tweens[b].pendingDelete=!0)},update:function(){if(0===this._tweens.length&&0===this._add.length)return!1;for(var a=0,b=this._tweens.length;b>a;)this._tweens[a].update(this.game.time.now)?a++:(this._tweens.splice(a,1),b--);return this._add.length>0&&(this._tweens=this._tweens.concat(this._add),this._add.length=0),!0},isTweening:function(a){return this._tweens.some(function(b){return b._object===a})},pauseAll:function(){for(var a=this._tweens.length-1;a>=0;a--)this._tweens[a].pause()},resumeAll:function(){for(var a=this._tweens.length-1;a>=0;a--)this._tweens[a].resume()}},c.TweenManager.prototype.constructor=c.TweenManager,c.Tween=function(a,b){this._object=a,this.game=b,this._manager=this.game.tweens,this._valuesStart={},this._valuesEnd={},this._valuesStartRepeat={},this._duration=1e3,this._repeat=0,this._yoyo=!1,this._reversed=!1,this._delayTime=0,this._startTime=null,this._easingFunction=c.Easing.Linear.None,this._interpolationFunction=c.Math.linearInterpolation,this._chainedTweens=[],this._onStartCallbackFired=!1,this._onUpdateCallback=null,this._pausedTime=0,this.pendingDelete=!1;for(var d in a)this._valuesStart[d]=parseFloat(a[d],10);this.onStart=new c.Signal,this.onLoop=new c.Signal,this.onComplete=new c.Signal,this.isRunning=!1},c.Tween.prototype={to:function(a,b,c,d,e,f,g){b=b||1e3,c=c||null,d=d||!1,e=e||0,f=f||0,g=g||!1;var h;return this._parent?(h=this._manager.create(this._object),this._lastChild.chain(h),this._lastChild=h):(h=this,this._parent=this,this._lastChild=this),h._repeat=f,h._duration=b,h._valuesEnd=a,null!==c&&(h._easingFunction=c),e>0&&(h._delayTime=e),h._yoyo=g,d?this.start():this},start:function(){if(null!==this.game&&null!==this._object){this._manager.add(this),this.isRunning=!0,this._onStartCallbackFired=!1,this._startTime=this.game.time.now+this._delayTime;for(var a in this._valuesEnd){if(this._valuesEnd[a]instanceof Array){if(0===this._valuesEnd[a].length)continue;this._valuesEnd[a]=[this._object[a]].concat(this._valuesEnd[a])}this._valuesStart[a]=this._object[a],this._valuesStart[a]instanceof Array==!1&&(this._valuesStart[a]*=1),this._valuesStartRepeat[a]=this._valuesStart[a]||0}return this}},stop:function(){return this.isRunning=!1,this._manager.remove(this),this},delay:function(a){return this._delayTime=a,this},repeat:function(a){return this._repeat=a,this},yoyo:function(a){return this._yoyo=a,this},easing:function(a){return this._easingFunction=a,this},interpolation:function(a){return this._interpolationFunction=a,this},chain:function(){return this._chainedTweens=arguments,this},loop:function(){return this._lastChild.chain(this),this},onUpdateCallback:function(a){return this._onUpdateCallback=a,this},pause:function(){this._paused=!0,this._pausedTime=this.game.time.now},resume:function(){this._paused=!1,this._startTime+=this.game.time.now-this._pausedTime},update:function(a){if(this.pendingDelete)return!1;if(this._paused||a1?1:c;var d=this._easingFunction(c);for(b in this._valuesEnd){var e=this._valuesStart[b]||0,f=this._valuesEnd[b];f instanceof Array?this._object[b]=this._interpolationFunction(f,d):("string"==typeof f&&(f=e+parseFloat(f,10)),"number"==typeof f&&(this._object[b]=e+(f-e)*d))}if(null!==this._onUpdateCallback&&this._onUpdateCallback.call(this._object,d),1==c){if(this._repeat>0){isFinite(this._repeat)&&this._repeat--;for(b in this._valuesStartRepeat){if("string"==typeof this._valuesEnd[b]&&(this._valuesStartRepeat[b]=this._valuesStartRepeat[b]+parseFloat(this._valuesEnd[b],10)),this._yoyo){var g=this._valuesStartRepeat[b];this._valuesStartRepeat[b]=this._valuesEnd[b],this._valuesEnd[b]=g,this._reversed=!this._reversed}this._valuesStart[b]=this._valuesStartRepeat[b]}return this._startTime=a+this._delayTime,this.onLoop.dispatch(this._object),!0}this.isRunning=!1,this.onComplete.dispatch(this._object);for(var h=0,i=this._chainedTweens.length;i>h;h++)this._chainedTweens[h].start(a);return!1}return!0}},c.Tween.prototype.constructor=c.Tween,c.Easing={Linear:{None:function(a){return a}},Quadratic:{In:function(a){return a*a},Out:function(a){return a*(2-a)},InOut:function(a){return(a*=2)<1?.5*a*a:-.5*(--a*(a-2)-1)}},Cubic:{In:function(a){return a*a*a},Out:function(a){return--a*a*a+1},InOut:function(a){return(a*=2)<1?.5*a*a*a:.5*((a-=2)*a*a+2)}},Quartic:{In:function(a){return a*a*a*a},Out:function(a){return 1- --a*a*a*a},InOut:function(a){return(a*=2)<1?.5*a*a*a*a:-.5*((a-=2)*a*a*a-2)}},Quintic:{In:function(a){return a*a*a*a*a},Out:function(a){return--a*a*a*a*a+1},InOut:function(a){return(a*=2)<1?.5*a*a*a*a*a:.5*((a-=2)*a*a*a*a+2)}},Sinusoidal:{In:function(a){return 1-Math.cos(a*Math.PI/2)},Out:function(a){return Math.sin(a*Math.PI/2)},InOut:function(a){return.5*(1-Math.cos(Math.PI*a))}},Exponential:{In:function(a){return 0===a?0:Math.pow(1024,a-1)},Out:function(a){return 1===a?1:1-Math.pow(2,-10*a)},InOut:function(a){return 0===a?0:1===a?1:(a*=2)<1?.5*Math.pow(1024,a-1):.5*(-Math.pow(2,-10*(a-1))+2)}},Circular:{In:function(a){return 1-Math.sqrt(1-a*a)},Out:function(a){return Math.sqrt(1- --a*a)},InOut:function(a){return(a*=2)<1?-.5*(Math.sqrt(1-a*a)-1):.5*(Math.sqrt(1-(a-=2)*a)+1)}},Elastic:{In:function(a){var b,c=.1,d=.4;return 0===a?0:1===a?1:(!c||1>c?(c=1,b=d/4):b=d*Math.asin(1/c)/(2*Math.PI),-(c*Math.pow(2,10*(a-=1))*Math.sin((a-b)*2*Math.PI/d)))},Out:function(a){var b,c=.1,d=.4;return 0===a?0:1===a?1:(!c||1>c?(c=1,b=d/4):b=d*Math.asin(1/c)/(2*Math.PI),c*Math.pow(2,-10*a)*Math.sin((a-b)*2*Math.PI/d)+1)},InOut:function(a){var b,c=.1,d=.4;return 0===a?0:1===a?1:(!c||1>c?(c=1,b=d/4):b=d*Math.asin(1/c)/(2*Math.PI),(a*=2)<1?-.5*c*Math.pow(2,10*(a-=1))*Math.sin((a-b)*2*Math.PI/d):.5*c*Math.pow(2,-10*(a-=1))*Math.sin((a-b)*2*Math.PI/d)+1)}},Back:{In:function(a){var b=1.70158;return a*a*((b+1)*a-b)},Out:function(a){var b=1.70158;return--a*a*((b+1)*a+b)+1},InOut:function(a){var b=2.5949095;return(a*=2)<1?.5*a*a*((b+1)*a-b):.5*((a-=2)*a*((b+1)*a+b)+2)}},Bounce:{In:function(a){return 1-c.Easing.Bounce.Out(1-a)},Out:function(a){return 1/2.75>a?7.5625*a*a:2/2.75>a?7.5625*(a-=1.5/2.75)*a+.75:2.5/2.75>a?7.5625*(a-=2.25/2.75)*a+.9375:7.5625*(a-=2.625/2.75)*a+.984375},InOut:function(a){return.5>a?.5*c.Easing.Bounce.In(2*a):.5*c.Easing.Bounce.Out(2*a-1)+.5}}},c.Time=function(a){this.game=a,this.physicsElapsed=0,this.time=0,this.pausedTime=0,this.now=0,this.elapsed=0,this.fps=0,this.fpsMin=1e3,this.fpsMax=0,this.msMin=1e3,this.msMax=0,this.frames=0,this.pauseDuration=0,this.timeToCall=0,this.lastTime=0,this.events=new c.Timer(this.game,!1),this._started=0,this._timeLastSecond=0,this._pauseStarted=0,this._justResumed=!1,this._timers=[],this._len=0,this._i=0,this.game.onPause.add(this.gamePaused,this),this.game.onResume.add(this.gameResumed,this)},c.Time.prototype={boot:function(){this.events.start()},create:function(a){"undefined"==typeof a&&(a=!0);var b=new c.Timer(this.game,a);return this._timers.push(b),b},removeAll:function(){for(var a=0;athis._timeLastSecond+1e3&&(this.fps=Math.round(1e3*this.frames/(this.now-this._timeLastSecond)),this.fpsMin=this.game.math.min(this.fpsMin,this.fps),this.fpsMax=this.game.math.max(this.fpsMax,this.fps),this._timeLastSecond=this.now,this.frames=0),this.time=this.now,this.lastTime=a+this.timeToCall,this.physicsElapsed=1*(this.elapsed/1e3),this.physicsElapsed>1&&(this.physicsElapsed=1),this.game.paused)this.pausedTime=this.now-this._pauseStarted;else for(this.events.update(this.now),this._i=0,this._len=this._timers.length;this._i0&&(this.events.sort(this.sortHandler),this.nextTick=this.events[0].tick)},sortHandler:function(a,b){return a.tickb.tick?1:0},update:function(a){if(this.paused)return!0;if(this._now=a-this._started,this._len=this.events.length,this.running&&this._now>=this.nextTick&&this._len>0){for(this._i=0;this._i=this.events[this._i].tick;)this.events[this._i].loop===!0?(this.events[this._i].tick+=this.events[this._i].delay-(this._now-this.events[this._i].tick),this.events[this._i].callback.apply(this.events[this._i].callbackContext,this.events[this._i].args)):this.events[this._i].repeatCount>0?(this.events[this._i].repeatCount--,this.events[this._i].tick+=this.events[this._i].delay-(this._now-this.events[this._i].tick),this.events[this._i].callback.apply(this.events[this._i].callbackContext,this.events[this._i].args)):(this.events[this._i].callback.apply(this.events[this._i].callbackContext,this.events[this._i].args),this.events.splice(this._i,1),this._len--),this._i++;this.events.length>0?this.order():(this.expired=!0,this.onComplete.dispatch(this))}return this.expired&&this.autoDestroy?!1:!0},pause:function(){this._pauseStarted=this.game.time.now,this.paused=!0},resume:function(){for(var a=this.game.time.now-this._pauseStarted,b=0;bthis._now?this.nextTick-this._now:0}}),Object.defineProperty(c.Timer.prototype,"length",{get:function(){return this.events.length}}),Object.defineProperty(c.Timer.prototype,"ms",{get:function(){return this._now}}),Object.defineProperty(c.Timer.prototype,"seconds",{get:function(){return.001*this._now}}),c.Timer.prototype.constructor=c.Timer,c.TimerEvent=function(a,b,c,d,e,f,g,h){this.timer=a,this.delay=b,this.tick=c,this.repeatCount=d-1,this.loop=e,this.callback=f,this.callbackContext=g,this.args=h},c.TimerEvent.prototype.constructor=c.TimerEvent,c.AnimationManager=function(a){this.sprite=a,this.game=a.game,this.currentFrame=null,this.updateIfVisible=!0,this.isLoaded=!1,this._frameData=null,this._anims={},this._outputFrames=[]},c.AnimationManager.prototype={loadFrameData:function(a){this._frameData=a,this.frame=0,this.isLoaded=!0},add:function(a,d,e,f,g){return null==this._frameData?(console.warn("No FrameData available for Phaser.Animation "+a),void 0):(e=e||60,"undefined"==typeof f&&(f=!1),"undefined"==typeof g&&(g=d&&"number"==typeof d[0]?!0:!1),null==this.sprite.events.onAnimationStart&&(this.sprite.events.onAnimationStart=new c.Signal,this.sprite.events.onAnimationComplete=new c.Signal,this.sprite.events.onAnimationLoop=new c.Signal),this._outputFrames.length=0,this._frameData.getFrameIndexes(d,g,this._outputFrames),this._anims[a]=new c.Animation(this.game,this.sprite,a,this._frameData,this._outputFrames,e,f),this.currentAnim=this._anims[a],this.currentFrame=this.currentAnim.currentFrame,this.sprite.setTexture(b.TextureCache[this.currentFrame.uuid]),this._anims[a]) +},validateFrames:function(a,b){"undefined"==typeof b&&(b=!0);for(var c=0;cthis._frameData.total)return!1}else if(this._frameData.checkFrameName(a[c])===!1)return!1;return!0},play:function(a,b,c,d){if(this._anims[a]){if(this.currentAnim!=this._anims[a])return this.currentAnim=this._anims[a],this.currentAnim.paused=!1,this.currentAnim.play(b,c,d);if(this.currentAnim.isPlaying===!1)return this.currentAnim.paused=!1,this.currentAnim.play(b,c,d)}},stop:function(a,b){"undefined"==typeof b&&(b=!1),"string"==typeof a?this._anims[a]&&(this.currentAnim=this._anims[a],this.currentAnim.stop(b)):this.currentAnim&&this.currentAnim.stop(b)},update:function(){return this.updateIfVisible&&this.sprite.visible===!1?!1:this.currentAnim&&this.currentAnim.update()===!0?(this.currentFrame=this.currentAnim.currentFrame,this.sprite.currentFrame=this.currentFrame,!0):!1},getAnimation:function(a){return"string"==typeof a&&this._anims[a]?this._anims[a]:!1},refreshFrame:function(){this.sprite.currentFrame=this.currentFrame,this.sprite.setTexture(b.TextureCache[this.currentFrame.uuid])},destroy:function(){this._anims={},this._frameData=null,this._frameIndex=0,this.currentAnim=null,this.currentFrame=null}},c.AnimationManager.prototype.constructor=c.AnimationManager,Object.defineProperty(c.AnimationManager.prototype,"frameData",{get:function(){return this._frameData}}),Object.defineProperty(c.AnimationManager.prototype,"frameTotal",{get:function(){return this._frameData?this._frameData.total:-1}}),Object.defineProperty(c.AnimationManager.prototype,"paused",{get:function(){return this.currentAnim.isPaused},set:function(a){this.currentAnim.paused=a}}),Object.defineProperty(c.AnimationManager.prototype,"frame",{get:function(){return this.currentFrame?this._frameIndex:void 0},set:function(a){"number"==typeof a&&this._frameData&&null!==this._frameData.getFrame(a)&&(this.currentFrame=this._frameData.getFrame(a),this._frameIndex=a,this.sprite.currentFrame=this.currentFrame,this.sprite.setTexture(b.TextureCache[this.currentFrame.uuid]))}}),Object.defineProperty(c.AnimationManager.prototype,"frameName",{get:function(){return this.currentFrame?this.currentFrame.name:void 0},set:function(a){"string"==typeof a&&this._frameData&&null!==this._frameData.getFrameByName(a)?(this.currentFrame=this._frameData.getFrameByName(a),this._frameIndex=this.currentFrame.index,this.sprite.currentFrame=this.currentFrame,this.sprite.setTexture(b.TextureCache[this.currentFrame.uuid])):console.warn("Cannot set frameName: "+a)}}),c.Animation=function(a,b,c,d,e,f,g){this.game=a,this._parent=b,this._frameData=d,this.name=c,this._frames=[],this._frames=this._frames.concat(e),this.delay=1e3/f,this.looped=g,this.killOnComplete=!1,this.isFinished=!1,this.isPlaying=!1,this.isPaused=!1,this._pauseStartTime=0,this._frameIndex=0,this._frameDiff=0,this._frameSkip=1,this.currentFrame=this._frameData.getFrame(this._frames[this._frameIndex])},c.Animation.prototype={play:function(a,c,d){return"number"==typeof a&&(this.delay=1e3/a),"boolean"==typeof c&&(this.looped=c),"undefined"!=typeof d&&(this.killOnComplete=d),this.isPlaying=!0,this.isFinished=!1,this.paused=!1,this._timeLastFrame=this.game.time.now,this._timeNextFrame=this.game.time.now+this.delay,this._frameIndex=0,this.currentFrame=this._frameData.getFrame(this._frames[this._frameIndex]),this._parent.setTexture(b.TextureCache[this.currentFrame.uuid]),this._parent.events&&this._parent.events.onAnimationStart.dispatch(this._parent,this),this},restart:function(){this.isPlaying=!0,this.isFinished=!1,this.paused=!1,this._timeLastFrame=this.game.time.now,this._timeNextFrame=this.game.time.now+this.delay,this._frameIndex=0,this.currentFrame=this._frameData.getFrame(this._frames[this._frameIndex])},stop:function(a){"undefined"==typeof a&&(a=!1),this.isPlaying=!1,this.isFinished=!0,this.paused=!1,a&&(this.currentFrame=this._frameData.getFrame(this._frames[0]))},update:function(){return this.isPaused?!1:this.isPlaying===!0&&this.game.time.now>=this._timeNextFrame?(this._frameSkip=1,this._frameDiff=this.game.time.now-this._timeNextFrame,this._timeLastFrame=this.game.time.now,this._frameDiff>this.delay&&(this._frameSkip=Math.floor(this._frameDiff/this.delay),this._frameDiff-=this._frameSkip*this.delay),this._timeNextFrame=this.game.time.now+(this.delay-this._frameDiff),this._frameIndex+=this._frameSkip,this._frameIndex>=this._frames.length?this.looped?(this._frameIndex%=this._frames.length,this.currentFrame=this._frameData.getFrame(this._frames[this._frameIndex]),this.currentFrame&&this._parent.setTexture(b.TextureCache[this.currentFrame.uuid]),this._parent.events.onAnimationLoop.dispatch(this._parent,this)):this.onComplete():(this.currentFrame=this._frameData.getFrame(this._frames[this._frameIndex]),this.currentFrame&&this._parent.setTexture(b.TextureCache[this.currentFrame.uuid])),!0):!1},destroy:function(){this.game=null,this._parent=null,this._frames=null,this._frameData=null,this.currentFrame=null,this.isPlaying=!1},onComplete:function(){this.isPlaying=!1,this.isFinished=!0,this.paused=!1,this._parent.events&&this._parent.events.onAnimationComplete.dispatch(this._parent,this),this.killOnComplete&&this._parent.kill()}},c.Animation.prototype.constructor=c.Animation,Object.defineProperty(c.Animation.prototype,"paused",{get:function(){return this.isPaused},set:function(a){this.isPaused=a,a?this._pauseStartTime=this.game.time.now:this.isPlaying&&(this._timeNextFrame=this.game.time.now+this.delay)}}),Object.defineProperty(c.Animation.prototype,"frameTotal",{get:function(){return this._frames.length}}),Object.defineProperty(c.Animation.prototype,"frame",{get:function(){return null!==this.currentFrame?this.currentFrame.index:this._frameIndex},set:function(a){this.currentFrame=this._frameData.getFrame(a),null!==this.currentFrame&&(this._frameIndex=a,this._parent.setTexture(b.TextureCache[this.currentFrame.uuid]))}}),c.Animation.generateFrameNames=function(a,b,d,e,f){"undefined"==typeof e&&(e="");var g=[],h="";if(d>b)for(var i=b;d>=i;i++)h="number"==typeof f?c.Utils.pad(i.toString(),f,"0",1):i.toString(),h=a+h+e,g.push(h);else for(var i=b;i>=d;i--)h="number"==typeof f?c.Utils.pad(i.toString(),f,"0",1):i.toString(),h=a+h+e,g.push(h);return g},c.Frame=function(a,b,d,e,f,g,h){this.index=a,this.x=b,this.y=d,this.width=e,this.height=f,this.name=g,this.uuid=h,this.centerX=Math.floor(e/2),this.centerY=Math.floor(f/2),this.distance=c.Math.distance(0,0,e,f),this.rotated=!1,this.rotationDirection="cw",this.trimmed=!1,this.sourceSizeW=e,this.sourceSizeH=f,this.spriteSourceSizeX=0,this.spriteSourceSizeY=0,this.spriteSourceSizeW=0,this.spriteSourceSizeH=0},c.Frame.prototype={setTrim:function(a,b,c,d,e,f,g){this.trimmed=a,a&&(this.width=b,this.height=c,this.sourceSizeW=b,this.sourceSizeH=c,this.centerX=Math.floor(b/2),this.centerY=Math.floor(c/2),this.spriteSourceSizeX=d,this.spriteSourceSizeY=e,this.spriteSourceSizeW=f,this.spriteSourceSizeH=g)}},c.Frame.prototype.constructor=c.Frame,c.FrameData=function(){this._frames=[],this._frameNames=[]},c.FrameData.prototype={addFrame:function(a){return a.index=this._frames.length,this._frames.push(a),""!==a.name&&(this._frameNames[a.name]=a.index),a},getFrame:function(a){return this._frames.length>a?this._frames[a]:null},getFrameByName:function(a){return"number"==typeof this._frameNames[a]?this._frames[this._frameNames[a]]:null},checkFrameName:function(a){return null==this._frameNames[a]?!1:!0},getFrameRange:function(a,b,c){"undefined"==typeof c&&(c=[]);for(var d=a;b>=d;d++)c.push(this._frames[d]);return c},getFrames:function(a,b,c){if("undefined"==typeof b&&(b=!0),"undefined"==typeof c&&(c=[]),"undefined"==typeof a||0===a.length)for(var d=0;dd;d++)b?c.push(this.getFrame(a[d])):c.push(this.getFrameByName(a[d]));return c},getFrameIndexes:function(a,b,c){if("undefined"==typeof b&&(b=!0),"undefined"==typeof c&&(c=[]),"undefined"==typeof a||0===a.length)for(var d=0,e=this._frames.length;e>d;d++)c.push(this._frames[d].index);else for(var d=0,e=a.length;e>d;d++)b?c.push(a[d]):this.getFrameByName(a[d])&&c.push(this.getFrameByName(a[d]).index);return c}},c.FrameData.prototype.constructor=c.FrameData,Object.defineProperty(c.FrameData.prototype,"total",{get:function(){return this._frames.length}}),c.AnimationParser={spriteSheet:function(a,d,e,f,g,h,i){var j=a.cache.getImage(d);if(null==j)return null;var k=j.width,l=j.height;0>=e&&(e=Math.floor(-k/Math.min(-1,e))),0>=f&&(f=Math.floor(-l/Math.min(-1,f)));var m=Math.round(k/e),n=Math.round(l/f),o=m*n;if(-1!==g&&(o=g),0===k||0===l||e>k||f>l||0===o)return console.warn("Phaser.AnimationParser.spriteSheet: width/height zero or width/height < given frameWidth/frameHeight"),null;for(var p=new c.FrameData,q=h,r=h,s=0;o>s;s++){var t=a.rnd.uuid();p.addFrame(new c.Frame(s,q,r,e,f,"",t)),b.TextureCache[t]=new b.Texture(b.BaseTextureCache[d],{x:q,y:r,width:e,height:f}),q+=e+i,q===k&&(q=h,r+=f+i)}return p},JSONData:function(a,d,e){if(!d.frames)return console.warn("Phaser.AnimationParser.JSONData: Invalid Texture Atlas JSON given, missing 'frames' array"),console.log(d),void 0;for(var f,g=new c.FrameData,h=d.frames,i=0;i tag"),void 0;for(var f,g,h,i,j,k,l,m,n,o,p,q,r=new c.FrameData,s=d.getElementsByTagName("SubTexture"),t=0;t0)for(var c=0;c0)for(var c=0;c0?(this._fileIndex=0,this._progressChunk=100/this._fileList.length,this.loadFile()):(this.progress=100,this.progressFloat=100,this.hasLoaded=!0,this.onLoadComplete.dispatch()))},loadFile:function(){if(!this._fileList[this._fileIndex])return console.warn("Phaser.Loader loadFile invalid index "+this._fileIndex),void 0;var a=this._fileList[this._fileIndex],b=this;switch(a.type){case"image":case"spritesheet":case"textureatlas":case"bitmapfont":a.data=new Image,a.data.name=a.key,a.data.onload=function(){return b.fileComplete(b._fileIndex)},a.data.onerror=function(){return b.fileError(b._fileIndex)},a.data.crossOrigin=this.crossOrigin,a.data.src=this.baseURL+a.url;break;case"audio":a.url=this.getAudioURL(a.url),null!==a.url?this.game.sound.usingWebAudio?(this._xhr.open("GET",this.baseURL+a.url,!0),this._xhr.responseType="arraybuffer",this._xhr.onload=function(){return b.fileComplete(b._fileIndex)},this._xhr.onerror=function(){return b.fileError(b._fileIndex)},this._xhr.send()):this.game.sound.usingAudioTag&&(this.game.sound.touchLocked?(a.data=new Audio,a.data.name=a.key,a.data.preload="auto",a.data.src=this.baseURL+a.url,this.fileComplete(this._fileIndex)):(a.data=new Audio,a.data.name=a.key,a.data.onerror=function(){return b.fileError(b._fileIndex)},a.data.preload="auto",a.data.src=this.baseURL+a.url,a.data.addEventListener("canplaythrough",c.GAMES[this.game.id].load.fileComplete(this._fileIndex),!1),a.data.load())):this.fileError(this._fileIndex);break;case"tilemap":if(this._xhr.open("GET",this.baseURL+a.url,!0),this._xhr.responseType="text",a.format===c.Tilemap.TILED_JSON)this._xhr.onload=function(){return b.jsonLoadComplete(b._fileIndex)};else{if(a.format!==c.Tilemap.CSV)throw new Error("Phaser.Loader. Invalid Tilemap format: "+a.format);this._xhr.onload=function(){return b.csvLoadComplete(b._fileIndex)}}this._xhr.onerror=function(){return b.dataLoadError(b._fileIndex)},this._xhr.send();break;case"text":case"script":this._xhr.open("GET",this.baseURL+a.url,!0),this._xhr.responseType="text",this._xhr.onload=function(){return b.fileComplete(b._fileIndex)},this._xhr.onerror=function(){return b.fileError(b._fileIndex)},this._xhr.send();break;case"binary":this._xhr.open("GET",this.baseURL+a.url,!0),this._xhr.responseType="arraybuffer",this._xhr.onload=function(){return b.fileComplete(b._fileIndex)},this._xhr.onerror=function(){return b.fileError(b._fileIndex)},this._xhr.send()}},getAudioURL:function(a){var b;"string"==typeof a&&(a=[a]);for(var c=0;c100&&(this.progress=100),null!==this.preloadSprite&&(0===this.preloadSprite.direction?this.preloadSprite.crop.width=Math.floor(this.preloadSprite.width/100*this.progress):this.preloadSprite.crop.height=Math.floor(this.preloadSprite.height/100*this.progress),this.preloadSprite.sprite.crop=this.preloadSprite.crop),this.onFileComplete.dispatch(this.progress,this._fileList[a].key,b,this.totalLoadedFiles(),this._fileList.length),this.totalQueuedFiles()>0?(this._fileIndex++,this.loadFile()):(this.hasLoaded=!0,this.isLoading=!1,this.removeAll(),this.onLoadComplete.dispatch())},totalLoadedFiles:function(){for(var a=0,b=0;b tag"),void 0;var e=b.TextureCache[d],f={},g=c.getElementsByTagName("info")[0],h=c.getElementsByTagName("common")[0];f.font=g.attributes.getNamedItem("face").nodeValue,f.size=parseInt(g.attributes.getNamedItem("size").nodeValue,10),f.lineHeight=parseInt(h.attributes.getNamedItem("lineHeight").nodeValue,10),f.chars={};for(var i=c.getElementsByTagName("char"),j=0;j=this.durationMS&&(this.usingWebAudio?this.loop?(this.onLoop.dispatch(this),""===this.currentMarker?(this.currentTime=0,this.startTime=this.game.time.now):this.play(this.currentMarker,0,this.volume,!0,!0)):this.stop():this.loop?(this.onLoop.dispatch(this),this.play(this.currentMarker,0,this.volume,!0,!0)):this.stop()))},play:function(a,b,c,d,e){if(a=a||"",b=b||0,"undefined"==typeof c&&(c=this._volume),"undefined"==typeof d&&(d=!1),"undefined"==typeof e&&(e=!0),this.isPlaying!==!0||e!==!1||this.override!==!1){if(this.isPlaying&&this.override&&(this.usingWebAudio?"undefined"==typeof this._sound.stop?this._sound.noteOff(0):this._sound.stop(0):this.usingAudioTag&&(this._sound.pause(),this._sound.currentTime=0)),this.currentMarker=a,""!==a){if(!this.markers[a])return console.warn("Phaser.Sound.play: audio marker "+a+" doesn't exist"),void 0;this.position=this.markers[a].start,this.volume=this.markers[a].volume,this.loop=this.markers[a].loop,this.duration=this.markers[a].duration,this.durationMS=this.markers[a].durationMS,this._tempMarker=a,this._tempPosition=this.position,this._tempVolume=this.volume,this._tempLoop=this.loop}else this.position=b,this.volume=c,this.loop=d,this.duration=0,this.durationMS=0,this._tempMarker=a,this._tempPosition=b,this._tempVolume=c,this._tempLoop=d;this.usingWebAudio?this.game.cache.isSoundDecoded(this.key)?(null==this._buffer&&(this._buffer=this.game.cache.getSoundData(this.key)),this._sound=this.context.createBufferSource(),this._sound.buffer=this._buffer,this.externalNode?this._sound.connect(this.externalNode.input):this._sound.connect(this.gainNode),this.totalDuration=this._sound.buffer.duration,0===this.duration&&(this.duration=this.totalDuration,this.durationMS=1e3*this.totalDuration),this.loop&&""===a&&(this._sound.loop=!0),"undefined"==typeof this._sound.start?this._sound.noteGrainOn(0,this.position,this.duration):this._sound.start(0,this.position,this.duration),this.isPlaying=!0,this.startTime=this.game.time.now,this.currentTime=0,this.stopTime=this.startTime+this.durationMS,this.onPlay.dispatch(this)):(this.pendingPlayback=!0,this.game.cache.getSound(this.key)&&this.game.cache.getSound(this.key).isDecoding===!1&&this.game.sound.decode(this.key,this)):this.game.cache.getSound(this.key)&&this.game.cache.getSound(this.key).locked?(this.game.cache.reloadSound(this.key),this.pendingPlayback=!0):this._sound&&(this.game.device.cocoonJS||4===this._sound.readyState)?(this._sound.play(),this.totalDuration=this._sound.duration,0===this.duration&&(this.duration=this.totalDuration,this.durationMS=1e3*this.totalDuration),this._sound.currentTime=this.position,this._sound.muted=this._muted,this._sound.volume=this._muted?0:this._volume,this.isPlaying=!0,this.startTime=this.game.time.now,this.currentTime=0,this.stopTime=this.startTime+this.durationMS,this.onPlay.dispatch(this)):this.pendingPlayback=!0}},restart:function(a,b,c,d){a=a||"",b=b||0,c=c||1,"undefined"==typeof d&&(d=!1),this.play(a,b,c,d,!0)},pause:function(){this.isPlaying&&this._sound&&(this.stop(),this.isPlaying=!1,this.paused=!0,this.pausedPosition=this.currentTime,this.pausedTime=this.game.time.now,this.onPause.dispatch(this))},resume:function(){if(this.paused&&this._sound){if(this.usingWebAudio){var a=this.position+this.pausedPosition/1e3;this._sound=this.context.createBufferSource(),this._sound.buffer=this._buffer,this.externalNode?this._sound.connect(this.externalNode.input):this._sound.connect(this.gainNode),this.loop&&(this._sound.loop=!0),"undefined"==typeof this._sound.start?this._sound.noteGrainOn(0,a,this.duration):this._sound.start(0,a,this.duration)}else this._sound.play();this.isPlaying=!0,this.paused=!1,this.startTime+=this.game.time.now-this.pausedTime,this.onResume.dispatch(this)}},stop:function(){this.isPlaying&&this._sound&&(this.usingWebAudio?"undefined"==typeof this._sound.stop?this._sound.noteOff(0):this._sound.stop(0):this.usingAudioTag&&(this._sound.pause(),this._sound.currentTime=0)),this.isPlaying=!1;var a=this.currentMarker;this.currentMarker="",this.onStop.dispatch(this,a)}},c.Sound.prototype.constructor=c.Sound,Object.defineProperty(c.Sound.prototype,"isDecoding",{get:function(){return this.game.cache.getSound(this.key).isDecoding}}),Object.defineProperty(c.Sound.prototype,"isDecoded",{get:function(){return this.game.cache.isSoundDecoded(this.key)}}),Object.defineProperty(c.Sound.prototype,"mute",{get:function(){return this._muted},set:function(a){a=a||null,a?(this._muted=!0,this.usingWebAudio?(this._muteVolume=this.gainNode.gain.value,this.gainNode.gain.value=0):this.usingAudioTag&&this._sound&&(this._muteVolume=this._sound.volume,this._sound.volume=0)):(this._muted=!1,this.usingWebAudio?this.gainNode.gain.value=this._muteVolume:this.usingAudioTag&&this._sound&&(this._sound.volume=this._muteVolume)),this.onMute.dispatch(this)}}),Object.defineProperty(c.Sound.prototype,"volume",{get:function(){return this._volume},set:function(a){this.usingWebAudio?(this._volume=a,this.gainNode.gain.value=a):this.usingAudioTag&&this._sound&&a>=0&&1>=a&&(this._volume=a,this._sound.volume=a)}}),c.SoundManager=function(a){this.game=a,this.onSoundDecode=new c.Signal,this._muted=!1,this._unlockSource=null,this._volume=1,this._sounds=[],this.context=null,this.usingWebAudio=!0,this.usingAudioTag=!1,this.noAudio=!1,this.connectToMaster=!0,this.touchLocked=!1,this.channels=32},c.SoundManager.prototype={boot:function(){if(this.game.device.iOS&&this.game.device.webAudio===!1&&(this.channels=1),this.game.device.iOS||window.PhaserGlobal&&window.PhaserGlobal.fakeiOSTouchLock?(this.game.input.touch.callbackContext=this,this.game.input.touch.touchStartCallback=this.unlock,this.game.input.mouse.callbackContext=this,this.game.input.mouse.mouseDownCallback=this.unlock,this.touchLocked=!0):this.touchLocked=!1,window.PhaserGlobal){if(window.PhaserGlobal.disableAudio===!0)return this.usingWebAudio=!1,this.noAudio=!0,void 0;if(window.PhaserGlobal.disableWebAudio===!0)return this.usingWebAudio=!1,this.usingAudioTag=!0,this.noAudio=!1,void 0}window.AudioContext?this.context=new window.AudioContext:window.webkitAudioContext?this.context=new window.webkitAudioContext:window.Audio?(this.usingWebAudio=!1,this.usingAudioTag=!0):(this.usingWebAudio=!1,this.noAudio=!0),null!==this.context&&(this.masterGain="undefined"==typeof this.context.createGain?this.context.createGainNode():this.context.createGain(),this.masterGain.gain.value=1,this.masterGain.connect(this.context.destination))},unlock:function(){if(this.touchLocked!==!1)if(this.game.device.webAudio===!1||window.PhaserGlobal&&window.PhaserGlobal.disableWebAudio===!0)this.touchLocked=!1,this._unlockSource=null,this.game.input.touch.callbackContext=null,this.game.input.touch.touchStartCallback=null,this.game.input.mouse.callbackContext=null,this.game.input.mouse.mouseDownCallback=null;else{var a=this.context.createBuffer(1,1,22050);this._unlockSource=this.context.createBufferSource(),this._unlockSource.buffer=a,this._unlockSource.connect(this.context.destination),this._unlockSource.noteOn(0)}},stopAll:function(){for(var a=0;a255)return c.Color.getColor(255,255,255);if(a>b)return c.Color.getColor(255,255,255);var e=a+Math.round(Math.random()*(b-a)),f=a+Math.round(Math.random()*(b-a)),g=a+Math.round(Math.random()*(b-a));return c.Color.getColor32(d,e,f,g)},getRGB:function(a){return{alpha:a>>>24,red:255&a>>16,green:255&a>>8,blue:255&a}},getWebRGB:function(a){var b=(a>>>24)/255,c=255&a>>16,d=255&a>>8,e=255&a;return"rgba("+c.toString()+","+d.toString()+","+e.toString()+","+b.toString()+")"},getAlpha:function(a){return a>>>24},getAlphaFloat:function(a){return(a>>>24)/255},getRed:function(a){return 255&a>>16},getGreen:function(a){return 255&a>>8},getBlue:function(a){return 255&a}},c.Physics={},c.Physics.Arcade=function(a){this.game=a,this.gravity=new c.Point,this.bounds=new c.Rectangle(0,0,a.world.width,a.world.height),this.maxObjects=10,this.maxLevels=4,this.OVERLAP_BIAS=4,this.quadTree=new c.QuadTree(this,this.game.world.bounds.x,this.game.world.bounds.y,this.game.world.bounds.width,this.game.world.bounds.height,this.maxObjects,this.maxLevels),this.quadTreeID=0,this._bounds1=new c.Rectangle,this._bounds2=new c.Rectangle,this._overlap=0,this._maxOverlap=0,this._velocity1=0,this._velocity2=0,this._newVelocity1=0,this._newVelocity2=0,this._average=0,this._mapData=[],this._mapTiles=0,this._result=!1,this._total=0,this._angle=0,this._dx=0,this._dy=0},c.Physics.Arcade.prototype={updateMotion:function(a){a.allowGravity?(this._gravityX=this.gravity.x+a.gravity.x,this._gravityY=this.gravity.y+a.gravity.y):(this._gravityX=0,this._gravityY=0),a.allowRotation&&(this._velocityDelta=a.angularAcceleration*this.game.time.physicsElapsed,0!==a.angularDrag&&0===a.angularAcceleration&&(this._drag=a.angularDrag*this.game.time.physicsElapsed,a.angularVelocity>0?a.angularVelocity-=this._drag:a.angularVelocity<0&&(a.angularVelocity+=this._drag)),a.rotation+=this.game.time.physicsElapsed*(a.angularVelocity+this._velocityDelta/2),a.angularVelocity+=this._velocityDelta,a.angularVelocity>a.maxAngular?a.angularVelocity=a.maxAngular:a.angularVelocity<-a.maxAngular&&(a.angularVelocity=-a.maxAngular)),a.motionVelocity.x=(a.acceleration.x+this._gravityX)*this.game.time.physicsElapsed,a.motionVelocity.y=(a.acceleration.y+this._gravityY)*this.game.time.physicsElapsed},preUpdate:function(){this.quadTree.clear(),this.quadTreeID=0,this.quadTree=new c.QuadTree(this,this.game.world.bounds.x,this.game.world.bounds.y,this.game.world.bounds.width,this.game.world.bounds.height,this.maxObjects,this.maxLevels)},postUpdate:function(){this.quadTree.clear()},overlap:function(a,b,d,e,f){return d=d||null,e=e||null,f=f||d,this._result=!1,this._total=0,a&&b&&a.exists&&b.exists&&(a.type==c.SPRITE||a.type==c.TILESPRITE?b.type==c.SPRITE||b.type==c.TILESPRITE?this.overlapSpriteVsSprite(a,b,d,e,f):(b.type==c.GROUP||b.type==c.EMITTER)&&this.overlapSpriteVsGroup(a,b,d,e,f):a.type==c.GROUP?b.type==c.SPRITE||b.type==c.TILESPRITE?this.overlapSpriteVsGroup(b,a,d,e,f):(b.type==c.GROUP||b.type==c.EMITTER)&&this.overlapGroupVsGroup(a,b,d,e,f):a.type==c.EMITTER&&(b.type==c.SPRITE||b.type==c.TILESPRITE?this.overlapSpriteVsGroup(b,a,d,e,f):(b.type==c.GROUP||b.type==c.EMITTER)&&this.overlapGroupVsGroup(a,b,d,e,f))),this._total>0},overlapSpriteVsSprite:function(a,b,d,e,f){this._result=c.Rectangle.intersects(a.body,b.body),this._result&&(e?e.call(f,a,b)&&(this._total++,d&&d.call(f,a,b)):(this._total++,d&&d.call(f,a,b)))},overlapSpriteVsGroup:function(a,b,d,e,f){if(0!==b.length){this._potentials=this.quadTree.retrieve(a);for(var g=0,h=this._potentials.length;h>g;g++)this._potentials[g].sprite.group==b&&(this._result=c.Rectangle.intersects(a.body,this._potentials[g]),this._result&&e&&(this._result=e.call(f,a,this._potentials[g].sprite)),this._result&&(this._total++,d&&d.call(f,a,this._potentials[g].sprite)))}},overlapGroupVsGroup:function(a,b,c,d,e){if(0!==a.length&&0!==b.length&&a._container.first._iNext){var f=a._container.first._iNext;do f.exists&&this.overlapSpriteVsGroup(f,b,c,d,e),f=f._iNext;while(f!=a._container.last._iNext)}},collide:function(a,b,d,e,f){return d=d||null,e=e||null,f=f||d,this._result=!1,this._total=0,a&&b&&a.exists&&b.exists&&(a.type==c.SPRITE||a.type==c.TILESPRITE?b.type==c.SPRITE||b.type==c.TILESPRITE?this.collideSpriteVsSprite(a,b,d,e,f):b.type==c.GROUP||b.type==c.EMITTER?this.collideSpriteVsGroup(a,b,d,e,f):b.type==c.TILEMAPLAYER&&this.collideSpriteVsTilemapLayer(a,b,d,e,f):a.type==c.GROUP?b.type==c.SPRITE||b.type==c.TILESPRITE?this.collideSpriteVsGroup(b,a,d,e,f):b.type==c.GROUP||b.type==c.EMITTER?this.collideGroupVsGroup(a,b,d,e,f):b.type==c.TILEMAPLAYER&&this.collideGroupVsTilemapLayer(a,b,d,e,f):a.type==c.TILEMAPLAYER?b.type==c.SPRITE||b.type==c.TILESPRITE?this.collideSpriteVsTilemapLayer(b,a,d,e,f):(b.type==c.GROUP||b.type==c.EMITTER)&&this.collideGroupVsTilemapLayer(b,a,d,e,f):a.type==c.EMITTER&&(b.type==c.SPRITE||b.type==c.TILESPRITE?this.collideSpriteVsGroup(b,a,d,e,f):b.type==c.GROUP||b.type==c.EMITTER?this.collideGroupVsGroup(a,b,d,e,f):b.type==c.TILEMAPLAYER&&this.collideGroupVsTilemapLayer(a,b,d,e,f))),this._total>0},collideSpriteVsTilemapLayer:function(a,b,c,d,e){if(this._mapData=b.getTiles(a.body.x,a.body.y,a.body.width,a.body.height,!0),0!==this._mapData.length)if(this._mapData.length>1)this.separateTiles(a.body,this._mapData);else{var f=0;this.separateTile(a.body,this._mapData[f])&&(d?d.call(e,a,this._mapData[f])&&(this._total++,c&&c.call(e,a,this._mapData[f])):(this._total++,c&&c.call(e,a,this._mapData[f])))}},collideGroupVsTilemapLayer:function(a,b,c,d,e){if(0!==a.length&&a._container.first._iNext){var f=a._container.first._iNext;do f.exists&&this.collideSpriteVsTilemapLayer(f,b,c,d,e),f=f._iNext;while(f!=a._container.last._iNext)}},collideSpriteVsSprite:function(a,b,c,d,e){this.separate(a.body,b.body),this._result&&(d?d.call(e,a,b)&&(this._total++,c&&c.call(e,a,b)):(this._total++,c&&c.call(e,a,b)))},collideSpriteVsGroup:function(a,b,c,d,e){if(0!==b.length){this._potentials=this.quadTree.retrieve(a); +for(var f=0,g=this._potentials.length;g>f;f++)this._potentials[f].sprite.group==b&&(this.separate(a.body,this._potentials[f]),this._result&&d&&(this._result=d.call(e,a,this._potentials[f].sprite)),this._result&&(this._total++,c&&c.call(e,a,this._potentials[f].sprite)))}},collideGroupVsGroup:function(a,b,c,d,e){if(0!==a.length&&0!==b.length&&a._container.first._iNext){var f=a._container.first._iNext;do f.exists&&this.collideSpriteVsGroup(f,b,c,d,e),f=f._iNext;while(f!=a._container.last._iNext)}},separate:function(a,b){this._result=a!==b?this.separateX(a,b)||this.separateY(a,b):!1},separateX:function(a,b){return a.immovable&&b.immovable?!1:(this._overlap=0,c.Rectangle.intersects(a,b)&&(this._maxOverlap=a.deltaAbsX()+b.deltaAbsX()+this.OVERLAP_BIAS,0===a.deltaX()&&0===b.deltaX()?(a.embedded=!0,b.embedded=!0):a.deltaX()>b.deltaX()?(this._overlap=a.x+a.width-b.x,this._overlap>this._maxOverlap||a.allowCollision.right===!1||b.allowCollision.left===!1?this._overlap=0:(a.touching.right=!0,b.touching.left=!0)):a.deltaX()this._maxOverlap||a.allowCollision.left===!1||b.allowCollision.right===!1?this._overlap=0:(a.touching.left=!0,b.touching.right=!0)),0!==this._overlap)?(a.overlapX=this._overlap,b.overlapX=this._overlap,a.customSeparateX||b.customSeparateX?!0:(this._velocity1=a.velocity.x,this._velocity2=b.velocity.x,a.immovable||b.immovable?a.immovable?b.immovable||(b.x+=this._overlap,b.velocity.x=this._velocity1-this._velocity2*b.bounce.x):(a.x=a.x-this._overlap,a.velocity.x=this._velocity2-this._velocity1*a.bounce.x):(this._overlap*=.5,a.x=a.x-this._overlap,b.x+=this._overlap,this._newVelocity1=Math.sqrt(this._velocity2*this._velocity2*b.mass/a.mass)*(this._velocity2>0?1:-1),this._newVelocity2=Math.sqrt(this._velocity1*this._velocity1*a.mass/b.mass)*(this._velocity1>0?1:-1),this._average=.5*(this._newVelocity1+this._newVelocity2),this._newVelocity1-=this._average,this._newVelocity2-=this._average,a.velocity.x=this._average+this._newVelocity1*a.bounce.x,b.velocity.x=this._average+this._newVelocity2*b.bounce.x),!0)):!1)},separateY:function(a,b){return a.immovable&&b.immovable?!1:(this._overlap=0,c.Rectangle.intersects(a,b)&&(this._maxOverlap=a.deltaAbsY()+b.deltaAbsY()+this.OVERLAP_BIAS,0===a.deltaY()&&0===b.deltaY()?(a.embedded=!0,b.embedded=!0):a.deltaY()>b.deltaY()?(this._overlap=a.y+a.height-b.y,this._overlap>this._maxOverlap||a.allowCollision.down===!1||b.allowCollision.up===!1?this._overlap=0:(a.touching.down=!0,b.touching.up=!0)):a.deltaY()this._maxOverlap||a.allowCollision.up===!1||b.allowCollision.down===!1?this._overlap=0:(a.touching.up=!0,b.touching.down=!0)),0!==this._overlap)?(a.overlapY=this._overlap,b.overlapY=this._overlap,a.customSeparateY||b.customSeparateY?!0:(this._velocity1=a.velocity.y,this._velocity2=b.velocity.y,a.immovable||b.immovable?a.immovable?b.immovable||(b.y+=this._overlap,b.velocity.y=this._velocity1-this._velocity2*b.bounce.y,a.moves&&(b.x+=a.x-a.preX)):(a.y-=this._overlap,a.velocity.y=this._velocity2-this._velocity1*a.bounce.y,b.moves&&(a.x+=b.x-b.preX)):(this._overlap*=.5,a.y=a.y-this._overlap,b.y+=this._overlap,this._newVelocity1=Math.sqrt(this._velocity2*this._velocity2*b.mass/a.mass)*(this._velocity2>0?1:-1),this._newVelocity2=Math.sqrt(this._velocity1*this._velocity1*a.mass/b.mass)*(this._velocity1>0?1:-1),this._average=.5*(this._newVelocity1+this._newVelocity2),this._newVelocity1-=this._average,this._newVelocity2-=this._average,a.velocity.y=this._average+this._newVelocity1*a.bounce.y,b.velocity.y=this._average+this._newVelocity2*b.bounce.y),!0)):!1)},separateTiles:function(a,b){if(a.immovable)return!1;a.overlapX=0,a.overlapY=0;for(var d,e=0,f=0,g=0;g=a.deltaX()&&(a.blocked.left=!0,a.touching.left=!0,a.touching.none=!1)):a.deltaX()>0&&a.allowCollision.right&&d.tile.faceLeft&&(e=a.right-d.x,e<=a.deltaX()&&(a.blocked.right=!0,a.touching.right=!0,a.touching.none=!1)),a.deltaY()<0&&a.allowCollision.up&&d.tile.faceBottom?(f=a.y-d.bottom,f>=a.deltaY()&&(a.blocked.up=!0,a.touching.up=!0,a.touching.none=!1)):a.deltaY()>0&&a.allowCollision.down&&d.tile.faceTop&&(f=a.bottom-d.y,f<=a.deltaY()&&(a.blocked.down=!0,a.touching.down=!0,a.touching.none=!1)));return 0!==e&&(a.overlapX=e),0!==f&&(a.overlapY=f),a.touching.none?!1:((a.touching.left||a.touching.right)&&(a.x-=a.overlapX,a.preX-=a.overlapX,a.velocity.x=0===a.bounce.x?0:-a.velocity.x*a.bounce.x),(a.touching.up||a.touching.down)&&(a.y-=a.overlapY,a.preY-=a.overlapY,a.velocity.y=0===a.bounce.y?0:-a.velocity.y*a.bounce.y),!0)},separateTile:function(a,b){return a.immovable||c.Rectangle.intersects(a,b)===!1?!1:(a.overlapX=0,a.overlapY=0,a.deltaX()<0&&a.allowCollision.left&&b.tile.faceRight?(a.overlapX=a.x-b.right,a.overlapX>=a.deltaX()&&(a.blocked.left=!0,a.touching.left=!0,a.touching.none=!1)):a.deltaX()>0&&a.allowCollision.right&&b.tile.faceLeft&&(a.overlapX=a.right-b.x,a.overlapX<=a.deltaX()&&(a.blocked.right=!0,a.touching.right=!0,a.touching.none=!1)),a.deltaY()<0&&a.allowCollision.up&&b.tile.faceBottom?(a.overlapY=a.y-b.bottom,a.overlapY>=a.deltaY()&&(a.blocked.up=!0,a.touching.up=!0,a.touching.none=!1)):a.deltaY()>0&&a.allowCollision.down&&b.tile.faceTop&&(a.overlapY=a.bottom-b.y,a.overlapY<=a.deltaY()&&(a.blocked.down=!0,a.touching.down=!0,a.touching.none=!1)),a.touching.none?!1:((a.touching.left||a.touching.right)&&(a.x-=a.overlapX,a.preX-=a.overlapX,a.velocity.x=0===a.bounce.x?0:-a.velocity.x*a.bounce.x),(a.touching.up||a.touching.down)&&(a.y-=a.overlapY,a.preY-=a.overlapY,a.velocity.y=0===a.bounce.y?0:-a.velocity.y*a.bounce.y),!0))},moveToObject:function(a,b,c,d){return"undefined"==typeof c&&(c=60),"undefined"==typeof d&&(d=0),this._angle=Math.atan2(b.y-a.y,b.x-a.x),d>0&&(c=this.distanceBetween(a,b)/(d/1e3)),a.body.velocity.x=Math.cos(this._angle)*c,a.body.velocity.y=Math.sin(this._angle)*c,this._angle},moveToPointer:function(a,b,c,d){return"undefined"==typeof b&&(b=60),c=c||this.game.input.activePointer,"undefined"==typeof d&&(d=0),this._angle=this.angleToPointer(a,c),d>0&&(b=this.distanceToPointer(a,c)/(d/1e3)),a.body.velocity.x=Math.cos(this._angle)*b,a.body.velocity.y=Math.sin(this._angle)*b,this._angle},moveToXY:function(a,b,c,d,e){return"undefined"==typeof d&&(d=60),"undefined"==typeof e&&(e=0),this._angle=Math.atan2(c-a.y,b-a.x),e>0&&(d=this.distanceToXY(a,b,c)/(e/1e3)),a.body.velocity.x=Math.cos(this._angle)*d,a.body.velocity.y=Math.sin(this._angle)*d,this._angle},velocityFromAngle:function(a,b,d){return"undefined"==typeof b&&(b=60),d=d||new c.Point,d.setTo(Math.cos(this.game.math.degToRad(a))*b,Math.sin(this.game.math.degToRad(a))*b)},velocityFromRotation:function(a,b,d){return"undefined"==typeof b&&(b=60),d=d||new c.Point,d.setTo(Math.cos(a)*b,Math.sin(a)*b)},accelerationFromRotation:function(a,b,d){return"undefined"==typeof b&&(b=60),d=d||new c.Point,d.setTo(Math.cos(a)*b,Math.sin(a)*b)},accelerateToObject:function(a,b,c,d,e){return"undefined"==typeof c&&(c=60),"undefined"==typeof d&&(d=1e3),"undefined"==typeof e&&(e=1e3),this._angle=this.angleBetween(a,b),a.body.acceleration.setTo(Math.cos(this._angle)*c,Math.sin(this._angle)*c),a.body.maxVelocity.setTo(d,e),this._angle},accelerateToPointer:function(a,b,c,d,e){return"undefined"==typeof c&&(c=60),"undefined"==typeof b&&(b=this.game.input.activePointer),"undefined"==typeof d&&(d=1e3),"undefined"==typeof e&&(e=1e3),this._angle=this.angleToPointer(a,b),a.body.acceleration.setTo(Math.cos(this._angle)*c,Math.sin(this._angle)*c),a.body.maxVelocity.setTo(d,e),this._angle},accelerateToXY:function(a,b,c,d,e,f){return"undefined"==typeof d&&(d=60),"undefined"==typeof e&&(e=1e3),"undefined"==typeof f&&(f=1e3),this._angle=this.angleToXY(a,b,c),a.body.acceleration.setTo(Math.cos(this._angle)*d,Math.sin(this._angle)*d),a.body.maxVelocity.setTo(e,f),this._angle},distanceBetween:function(a,b){return this._dx=a.x-b.x,this._dy=a.y-b.y,Math.sqrt(this._dx*this._dx+this._dy*this._dy)},distanceToXY:function(a,b,c){return this._dx=a.x-b,this._dy=a.y-c,Math.sqrt(this._dx*this._dx+this._dy*this._dy)},distanceToPointer:function(a,b){return b=b||this.game.input.activePointer,this._dx=a.x-b.x,this._dy=a.y-b.y,Math.sqrt(this._dx*this._dx+this._dy*this._dy)},angleBetween:function(a,b){return this._dx=b.x-a.x,this._dy=b.y-a.y,Math.atan2(this._dy,this._dx)},angleToXY:function(a,b,c){return this._dx=b-a.x,this._dy=c-a.y,Math.atan2(this._dy,this._dx)},angleToPointer:function(a,b){return b=b||this.game.input.activePointer,this._dx=b.worldX-a.x,this._dy=b.worldY-a.y,Math.atan2(this._dy,this._dx)}},c.Physics.Arcade.prototype.constructor=c.Physics.Arcade,c.Physics.Arcade.Body=function(a){this.sprite=a,this.game=a.game,this.offset=new c.Point,this.x=a.x,this.y=a.y,this.preX=a.x,this.preY=a.y,this.preRotation=a.angle,this.screenX=a.x,this.screenY=a.y,this.sourceWidth=a.currentFrame.sourceSizeW,this.sourceHeight=a.currentFrame.sourceSizeH,this.width=a.currentFrame.sourceSizeW,this.height=a.currentFrame.sourceSizeH,this.halfWidth=Math.floor(a.currentFrame.sourceSizeW/2),this.halfHeight=Math.floor(a.currentFrame.sourceSizeH/2),this.center=new c.Point(this.x+this.halfWidth,this.y+this.halfHeight),this._sx=a.scale.x,this._sy=a.scale.y,this.motionVelocity=new c.Point,this.velocity=new c.Point,this.prevVelocity=new c.Point,this.acceleration=new c.Point,this.speed=0,this.angle=0,this.drag=new c.Point,this.gravity=new c.Point,this.bounce=new c.Point,this.maxVelocity=new c.Point(1e4,1e4),this.angularVelocity=0,this.angularAcceleration=0,this.angularDrag=0,this.maxAngular=1e3,this.mass=1,this.skipQuadTree=!1,this.quadTreeIDs=[],this.quadTreeIndex=-1,this.allowCollision={none:!1,any:!0,up:!0,down:!0,left:!0,right:!0},this.touching={none:!0,up:!1,down:!1,left:!1,right:!1},this.wasTouching={none:!0,up:!1,down:!1,left:!1,right:!1},this.facing=c.NONE,this.immovable=!1,this.moves=!0,this.rotation=0,this.allowRotation=!0,this.allowGravity=!0,this.customSeparateX=!1,this.customSeparateY=!1,this.overlapX=0,this.overlapY=0,this.sleeping=!1,this.canSleep=!0,this.sleepMin=new c.Point(-20,-20),this.sleepMax=new c.Point(20,20),this.sleepDuration=2e3,this._sleepTimer=0,this._drag=0,this._debug=0,this.friction=0,this.embedded=!1,this.collideWorldBounds=!1,this.blocked={up:!1,down:!1,left:!1,right:!1}},c.Physics.Arcade.Body.prototype={updateBounds:function(a,b,c,d){(c!=this._sx||d!=this._sy)&&(this.width=this.sourceWidth*c,this.height=this.sourceHeight*d,this.halfWidth=Math.floor(this.width/2),this.halfHeight=Math.floor(this.height/2),this._sx=c,this._sy=d,this.center.setTo(this.x+this.halfWidth,this.y+this.halfHeight))},preUpdate:function(){this.wasTouching.none=this.touching.none,this.wasTouching.up=this.touching.up,this.wasTouching.down=this.touching.down,this.wasTouching.left=this.touching.left,this.wasTouching.right=this.touching.right,this.touching.none=!0,this.touching.up=!1,this.touching.down=!1,this.touching.left=!1,this.touching.right=!1,this.embedded=!1,this.screenX=this.sprite.worldTransform[2]-this.sprite.anchor.x*this.width+this.offset.x,this.screenY=this.sprite.worldTransform[5]-this.sprite.anchor.y*this.height+this.offset.y,this.preX=this.sprite.world.x-this.sprite.anchor.x*this.width+this.offset.x,this.preY=this.sprite.world.y-this.sprite.anchor.y*this.height+this.offset.y,this.preRotation=this.sprite.angle,this.canSleep&&this.sleeping&&(this.velocity.equals(this.prevVelocity)===!1||this.acceleration.isZero()===!1)&&(this.sleeping=!1,this._sleepTimer=0),this.x=this.preX,this.y=this.preY,this.rotation=this.preRotation,this.speed=Math.sqrt(this.velocity.x*this.velocity.x+this.velocity.y*this.velocity.y),this.angle=Math.atan2(this.velocity.y,this.velocity.x),this.blocked.up=!1,this.blocked.down=!1,this.blocked.left=!1,this.blocked.right=!1,this.moves&&(this.game.physics.updateMotion(this),this.canSleep?this.sleeping||(this.velocity.x>=this.sleepMin.x&&this.velocity.x<=this.sleepMax.x&&this.velocity.y>=this.sleepMin.y&&this.velocity.y<=this.sleepMax.y?this._sleepTimer>=this.sleepDuration?this.sleeping=!0:(this._sleepTimer+=this.game.time.elapsed,this.applyMotion()):this.applyMotion()):this.applyMotion()),this.skipQuadTree===!1&&this.allowCollision.none===!1&&this.sprite.visible&&this.sprite.alive&&(this.quadTreeIDs=[],this.quadTreeIndex=-1,this.game.physics.quadTree.insert(this)),this.prevVelocity.copyFrom(this.velocity)},applyMotion:function(){this.friction>0&&this.acceleration.isZero()&&(this.speed>this.friction?this.speed-=this.friction:this.speed=0,this.velocity.x=Math.cos(this.angle)*this.speed,this.velocity.y=Math.sin(this.angle)*this.speed),this.x+=this.game.time.physicsElapsed*(this.velocity.x+this.motionVelocity.x/2),this.velocity.x+=this.motionVelocity.x,this.y+=this.game.time.physicsElapsed*(this.velocity.y+this.motionVelocity.y/2),this.velocity.y+=this.motionVelocity.y,this.velocity.x>this.maxVelocity.x?this.velocity.x=this.maxVelocity.x:this.velocity.x<-this.maxVelocity.x&&(this.velocity.x=-this.maxVelocity.x),this.velocity.y>this.maxVelocity.y?this.velocity.y=this.maxVelocity.y:this.velocity.y<-this.maxVelocity.y&&(this.velocity.y=-this.maxVelocity.y),this.collideWorldBounds&&(this.checkWorldBounds(),this.blocked.left||this.blocked.right,this.blocked.up||this.blocked.down)},postUpdate:function(){this.moves&&(this.deltaX()<0&&this.blocked.left===!1?(this.facing=c.LEFT,this.sprite.x+=this.deltaX()):this.deltaX()>0&&this.blocked.right===!1&&(this.facing=c.RIGHT,this.sprite.x+=this.deltaX()),this.deltaY()<0&&this.blocked.up===!1?(this.facing=c.UP,this.sprite.y+=this.deltaY()):this.deltaY()>0&&this.blocked.down===!1&&(this.facing=c.DOWN,this.sprite.y+=this.deltaY()),this.collideWorldBounds&&this.checkWorldBounds(),this.center.setTo(this.x+this.halfWidth,this.y+this.halfHeight),this.allowRotation&&(this.sprite.angle+=this.deltaZ()))},checkWorldBounds:function(){this.velocity.x,this.velocity.y,this.xthis.game.world.bounds.right&&(this.blocked.right=!0,this.x=this.game.world.bounds.right-this.width,this.velocity.x*=-this.bounce.x),this.ythis.game.world.bounds.bottom&&(this.blocked.down=!0,this.y=this.game.world.bounds.bottom-this.height,this.velocity.y*=-this.bounce.y)},setSize:function(a,b,c,d){c=c||this.offset.x,d=d||this.offset.y,this.sourceWidth=a,this.sourceHeight=b,this.width=this.sourceWidth*this._sx,this.height=this.sourceHeight*this._sy,this.halfWidth=Math.floor(this.width/2),this.halfHeight=Math.floor(this.height/2),this.offset.setTo(c,d),this.center.setTo(this.x+this.halfWidth,this.y+this.halfHeight)},reset:function(){this.velocity.setTo(0,0),this.acceleration.setTo(0,0),this.angularVelocity=0,this.angularAcceleration=0,this.preX=this.sprite.world.x-this.sprite.anchor.x*this.width+this.offset.x,this.preY=this.sprite.world.y-this.sprite.anchor.y*this.height+this.offset.y,this.preRotation=this.sprite.angle,this.x=this.preX,this.y=this.preY,this.rotation=this.preRotation,this.center.setTo(this.x+this.halfWidth,this.y+this.halfHeight)},deltaAbsX:function(){return this.deltaX()>0?this.deltaX():-this.deltaX()},deltaAbsY:function(){return this.deltaY()>0?this.deltaY():-this.deltaY()},deltaX:function(){return this.x-this.preX},deltaY:function(){return this.y-this.preY},deltaZ:function(){return this.rotation-this.preRotation}},c.Physics.Arcade.Body.prototype.constructor=c.Physics.Arcade.Body,Object.defineProperty(c.Physics.Arcade.Body.prototype,"bottom",{get:function(){return Math.floor(this.y+this.height)},set:function(a){this.height=a<=this.y?0:this.y-a}}),Object.defineProperty(c.Physics.Arcade.Body.prototype,"right",{get:function(){return Math.floor(this.x+this.width)},set:function(a){this.width=a<=this.x?0:this.x+a}}),c.Particles=function(a){this.game=a,this.emitters={},this.ID=0},c.Particles.prototype={add:function(a){return this.emitters[a.name]=a,a},remove:function(a){delete this.emitters[a.name]},update:function(){for(var a in this.emitters)this.emitters[a].exists&&this.emitters[a].update()}},c.Particles.prototype.constructor=c.Particles,c.Particles.Arcade={},c.Particles.Arcade.Emitter=function(a,b,d,e){this.maxParticles=e||50,c.Group.call(this,a),this.name="emitter"+this.game.particles.ID++,this.type=c.EMITTER,this.x=0,this.y=0,this.width=1,this.height=1,this.minParticleSpeed=new c.Point(-100,-100),this.maxParticleSpeed=new c.Point(100,100),this.minParticleScale=1,this.maxParticleScale=1,this.minRotation=-360,this.maxRotation=360,this.gravity=2,this.particleClass=null,this.particleDrag=new c.Point,this.angularDrag=0,this.frequency=100,this.lifespan=2e3,this.bounce=new c.Point,this._quantity=0,this._timer=0,this._counter=0,this._explode=!0,this.on=!1,this.exists=!0,this.emitX=b,this.emitY=d},c.Particles.Arcade.Emitter.prototype=Object.create(c.Group.prototype),c.Particles.Arcade.Emitter.prototype.constructor=c.Particles.Arcade.Emitter,c.Particles.Arcade.Emitter.prototype.update=function(){if(this.on)if(this._explode){this._counter=0;do this.emitParticle(),this._counter++;while(this._counter=this._timer&&(this.emitParticle(),this._counter++,this._quantity>0&&this._counter>=this._quantity&&(this.on=!1),this._timer=this.game.time.now+this.frequency)},c.Particles.Arcade.Emitter.prototype.makeParticles=function(a,b,d,e,f){"undefined"==typeof b&&(b=0),d=d||this.maxParticles,e=e||0,"undefined"==typeof f&&(f=!1);for(var g,h=0,i=a,j=0;d>h;)null==this.particleClass&&("object"==typeof a&&(i=this.game.rnd.pick(a)),"object"==typeof b&&(j=this.game.rnd.pick(b)),g=new c.Sprite(this.game,0,0,i,j)),e>0?(g.body.allowCollision.any=!0,g.body.allowCollision.none=!1):g.body.allowCollision.none=!0,g.body.collideWorldBounds=f,g.exists=!1,g.visible=!1,g.anchor.setTo(.5,.5),this.add(g),h++;return this},c.Particles.Arcade.Emitter.prototype.kill=function(){this.on=!1,this.alive=!1,this.exists=!1},c.Particles.Arcade.Emitter.prototype.revive=function(){this.alive=!0,this.exists=!0},c.Particles.Arcade.Emitter.prototype.start=function(a,b,c,d){"boolean"!=typeof a&&(a=!0),b=b||0,c=c||250,d=d||0,this.revive(),this.visible=!0,this.on=!0,this._explode=a,this.lifespan=b,this.frequency=c,a?this._quantity=d:this._quantity+=d,this._counter=0,this._timer=this.game.time.now+c},c.Particles.Arcade.Emitter.prototype.emitParticle=function(){var a=this.getFirstExists(!1);if(null!=a){if(this.width>1||this.height>1?a.reset(this.game.rnd.integerInRange(this.left,this.right),this.game.rnd.integerInRange(this.top,this.bottom)):a.reset(this.emitX,this.emitY),a.lifespan=this.lifespan,a.body.bounce.setTo(this.bounce.x,this.bounce.y),a.body.velocity.x=this.minParticleSpeed.x!=this.maxParticleSpeed.x?this.game.rnd.integerInRange(this.minParticleSpeed.x,this.maxParticleSpeed.x):this.minParticleSpeed.x,a.body.velocity.y=this.minParticleSpeed.y!=this.maxParticleSpeed.y?this.game.rnd.integerInRange(this.minParticleSpeed.y,this.maxParticleSpeed.y):this.minParticleSpeed.y,a.body.gravity.y=this.gravity,a.body.angularVelocity=this.minRotation!=this.maxRotation?this.game.rnd.integerInRange(this.minRotation,this.maxRotation):this.minRotation,1!==this.minParticleScale||1!==this.maxParticleScale){var b=this.game.rnd.realInRange(this.minParticleScale,this.maxParticleScale);a.scale.setTo(b,b)}a.body.drag.x=this.particleDrag.x,a.body.drag.y=this.particleDrag.y,a.body.angularDrag=this.angularDrag}},c.Particles.Arcade.Emitter.prototype.setSize=function(a,b){this.width=a,this.height=b},c.Particles.Arcade.Emitter.prototype.setXSpeed=function(a,b){a=a||0,b=b||0,this.minParticleSpeed.x=a,this.maxParticleSpeed.x=b},c.Particles.Arcade.Emitter.prototype.setYSpeed=function(a,b){a=a||0,b=b||0,this.minParticleSpeed.y=a,this.maxParticleSpeed.y=b},c.Particles.Arcade.Emitter.prototype.setRotation=function(a,b){a=a||0,b=b||0,this.minRotation=a,this.maxRotation=b},c.Particles.Arcade.Emitter.prototype.at=function(a){this.emitX=a.center.x,this.emitY=a.center.y},Object.defineProperty(c.Particles.Arcade.Emitter.prototype,"alpha",{get:function(){return this._container.alpha},set:function(a){this._container.alpha=a}}),Object.defineProperty(c.Particles.Arcade.Emitter.prototype,"visible",{get:function(){return this._container.visible},set:function(a){this._container.visible=a}}),Object.defineProperty(c.Particles.Arcade.Emitter.prototype,"x",{get:function(){return this.emitX},set:function(a){this.emitX=a}}),Object.defineProperty(c.Particles.Arcade.Emitter.prototype,"y",{get:function(){return this.emitY},set:function(a){this.emitY=a}}),Object.defineProperty(c.Particles.Arcade.Emitter.prototype,"left",{get:function(){return Math.floor(this.x-this.width/2)}}),Object.defineProperty(c.Particles.Arcade.Emitter.prototype,"right",{get:function(){return Math.floor(this.x+this.width/2)}}),Object.defineProperty(c.Particles.Arcade.Emitter.prototype,"top",{get:function(){return Math.floor(this.y-this.height/2)}}),Object.defineProperty(c.Particles.Arcade.Emitter.prototype,"bottom",{get:function(){return Math.floor(this.y+this.height/2)}}),c.Tile=function(a,b,c,d,e){this.index=a,this.x=b,this.y=c,this.width=d,this.height=e,this.alpha=1,this.properties={},this.faceTop=!1,this.faceBottom=!1,this.faceLeft=!1,this.faceRight=!1,this.collides=!1,this.collideNone=!0,this.collideLeft=!1,this.collideRight=!1,this.collideUp=!1,this.collideDown=!1,this.collisionCallback=null,this.collisionCallbackContext=this},c.Tile.prototype={setCollisionCallback:function(a,b){this.collisionCallbackContext=b,this.collisionCallback=a},destroy:function(){this.collisionCallback=null,this.collisionCallbackContext=null,this.properties=null},setCollision:function(a,b,c,d){this.collideLeft=a,this.collideRight=b,this.collideUp=c,this.collideDown=d,this.collideNone=a||b||c||d?!1:!0},resetCollision:function(){this.collideNone=!0,this.collideLeft=!1,this.collideRight=!1,this.collideUp=!1,this.collideDown=!1}},c.Tile.prototype.constructor=c.Tile,Object.defineProperty(c.Tile.prototype,"bottom",{get:function(){return this.y+this.height}}),Object.defineProperty(c.Tile.prototype,"right",{get:function(){return this.x+this.width}}),c.Tilemap=function(a,b){this.game=a,this.key=b;var d=c.TilemapParser.parse(this.game,b);null!==d&&(this.width=d.width,this.height=d.height,this.tileWidth=d.tileWidth,this.tileHeight=d.tileHeight,this.orientation=d.orientation,this.version=d.version,this.properties=d.properties,this.widthInPixels=d.widthInPixels,this.heightInPixels=d.heightInPixels,this.layers=d.layers,this.tilesets=d.tilesets,this.tiles=d.tiles,this.objects=d.objects,this.images=d.images,this.currentLayer=0,this.debugMap=[],this._results=[],this._tempA=0,this._tempB=0)},c.Tilemap.CSV=0,c.Tilemap.TILED_JSON=1,c.Tilemap.prototype={create:function(a,b,d){for(var e=[],f=0;d>f;f++){e[f]=[];for(var g=0;b>g;g++)e[f][g]=0}this.layers.push({name:a,width:b,height:d,alpha:1,visible:!0,tileMargin:0,tileSpacing:0,format:c.Tilemap.CSV,data:e,indexes:[],dirty:!0}),this.currentLayer=this.layers.length-1},addTilesetImage:function(a,b){if("undefined"==typeof b){if("string"!=typeof a)return!1;b=a}return"string"==typeof a&&(a=this.getTilesetIndex(a)),this.tilesets[a]?(this.tilesets[a].image=this.game.cache.getImage(b),!0):!1},createFromTiles:function(a,b,c,d,e){"undefined"==typeof e&&(e=this.game.world)},createFromObjects:function(a,b,c,d,e,f,g){if("undefined"==typeof e&&(e=!0),"undefined"==typeof f&&(f=!0),"undefined"==typeof g&&(g=this.game.world),!this.objects[a])return console.warn("Tilemap.createFromObjects: Invalid objectgroup name given: "+a),void 0;for(var h,i=0,j=this.objects[a].length;j>i;i++)if(this.objects[a][i].gid===b){h=g.create(this.objects[a][i].x,this.objects[a][i].y,c,d,e),h.anchor.setTo(0,1),h.name=this.objects[a][i].name,h.visible=this.objects[a][i].visible,h.autoCull=f;for(property in this.objects[a][i].properties)g.set(h,property,this.objects[a][i].properties[property],!1,!1,0)}},createLayer:function(a,b,d,e){"undefined"==typeof b&&(b=this.game.width),"undefined"==typeof d&&(d=this.game.height),"undefined"==typeof e&&(e=this.game.world);var f=a;return"string"==typeof a&&(f=this.getLayerIndex(a)),null===f||f>this.layers.length?(console.warn("Tilemap.createLayer: Invalid layer ID given: "+f),void 0):e.add(new c.TilemapLayer(this.game,this,f,b,d))},getIndex:function(a,b){for(var c=0;cc;c++)-1===a.indexOf(c)&&this.setCollisionByIndex(c,b,!1);this.calculateFaces(b)},setCollision:function(a,b){if("undefined"==typeof b&&(b=this.currentLayer),"number"==typeof a)return this.setCollisionByIndex(a,b);for(var c=0,d=a.length;d>c;c++)this.setCollisionByIndex(c,b,!1);this.calculateFaces(b)},setCollisionBetween:function(a,b,c){if(!(a>b)){for(var d=a;b>=d;d++)var e=this.setCollisionByIndex(d,c,!1);this.calculateFaces(e)}},setCollisionByIndex:function(a,b,d){"undefined"==typeof b?b=this.currentLayer:"string"==typeof b?b=this.getLayerIndex(b):b instanceof c.TilemapLayer&&(b=b.index),"undefined"==typeof d&&(d=!0);for(var e=0;ef;f++)for(var h=0,i=this.layers[a].width;i>h;h++){var j=this.layers[a].data[f][h];j&&(b=this.getTileAbove(a,h,f),c=this.getTileBelow(a,h,f),d=this.getTileLeft(a,h,f),e=this.getTileRight(a,h,f),b&&b.collides&&(j.faceTop=!1),c&&c.collides&&(j.faceBottom=!1),d&&d.collides&&(j.faceLeft=!1),e&&e.collides&&(j.faceRight=!1))}},getTileAbove:function(a,b,c){return c>0?this.layers[a].data[c-1][b]:null},getTileBelow:function(a,b,c){return c0?this.layers[a].data[c][b-1]:null},getTileRight:function(a,b,c){return b=0&&b=0&&c=0&&a=0&&b=0&&a=0&&b=0&&b=0&&ca&&(a=0),0>b&&(b=0),c>this.layers[e].width&&(c=this.layers[e].width),d>this.layers[e].height&&(d=this.layers[e].height),this._results.length=0,this._results.push({x:a,y:b,width:c,height:d,layer:e});for(var f=b;b+d>f;f++)for(var g=a;a+c>g;g++)this._results.push({x:g,y:f,index:this.layers[e].data[f][g]});return this._results},paste:function(a,b,c,d){if("undefined"==typeof a&&(a=0),"undefined"==typeof b&&(b=0),"undefined"==typeof d&&(d=this.currentLayer),c&&!(c.length<2)){for(var e=c[1].x-a,f=c[1].y-b,g=1;g1?this.debugMap[this.layers[this.currentLayer].data[c][d]]?b.push("background: "+this.debugMap[this.layers[this.currentLayer].data[c][d]]):b.push("background: #ffffff"):b.push("background: rgb(0, 0, 0)");a+="\n"}b[0]=a,console.log.apply(console,b)},destroy:function(){this.removeAllLayers(),this.game=null}},c.Tilemap.prototype.constructor=c.Tilemap,c.TilemapLayer=function(a,d,e,f,g){this.game=a,this.map=d,this.index=e,this.layer=d.layers[e],this.canvas=c.Canvas.create(f,g),this.context=this.canvas.getContext("2d"),this.baseTexture=new b.BaseTexture(this.canvas),this.texture=new b.Texture(this.baseTexture),this.textureFrame=new c.Frame(0,0,0,f,g,"tilemapLayer",a.rnd.uuid()),c.Sprite.call(this,this.game,0,0,this.texture,this.textureFrame),this.name="",this.type=c.TILEMAPLAYER,this.fixedToCamera=!0,this.cameraOffset=new c.Point(0,0),this.tileColor="rgb(255, 255, 255)",this.debug=!1,this.debugAlpha=.5,this.debugColor="rgba(0, 255, 0, 1)",this.debugFill=!1,this.debugFillColor="rgba(0, 255, 0, 0.2)",this.scrollFactorX=1,this.scrollFactorY=1,this.dirty=!0,this._cw=d.tileWidth,this._ch=d.tileHeight,this._ga=1,this._dx=0,this._dy=0,this._dw=0,this._dh=0,this._tx=0,this._ty=0,this._tw=0,this._th=0,this._tl=0,this._maxX=0,this._maxY=0,this._startX=0,this._startY=0,this._results=[],this._x=0,this._y=0,this._prevX=0,this._prevY=0,this.updateMax()},c.TilemapLayer.prototype=Object.create(c.Sprite.prototype),c.TilemapLayer.prototype=c.Utils.extend(!0,c.TilemapLayer.prototype,c.Sprite.prototype,b.Sprite.prototype),c.TilemapLayer.prototype.constructor=c.TilemapLayer,c.TilemapLayer.prototype.postUpdate=function(){c.Sprite.prototype.postUpdate.call(this),this.scrollX=this.game.camera.x*this.scrollFactorX,this.scrollY=this.game.camera.y*this.scrollFactorY,this.render()},c.TilemapLayer.prototype.resizeWorld=function(){this.game.world.setBounds(0,0,this.layer.widthInPixels,this.layer.heightInPixels) +},c.TilemapLayer.prototype._fixX=function(a){return 0>a&&(a=0),1===this.scrollFactorX?a:this._x+(a-this._x/this.scrollFactorX)},c.TilemapLayer.prototype._unfixX=function(a){return 1===this.scrollFactorX?a:this._x/this.scrollFactorX+(a-this._x)},c.TilemapLayer.prototype._fixY=function(a){return 0>a&&(a=0),1===this.scrollFactorY?a:this._y+(a-this._y/this.scrollFactorY)},c.TilemapLayer.prototype._unfixY=function(a){return 1===this.scrollFactorY?a:this._y/this.scrollFactorY+(a-this._y)},c.TilemapLayer.prototype.getTileX=function(a){return this.game.math.snapToFloor(this._fixX(a),this.map.tileWidth)/this.map.tileWidth},c.TilemapLayer.prototype.getTileY=function(a){return this.game.math.snapToFloor(this._fixY(a),this.map.tileHeight)/this.map.tileHeight},c.TilemapLayer.prototype.getTileXY=function(a,b,c){return c.x=this.getTileX(a),c.y=this.getTileY(b),c},c.TilemapLayer.prototype.getTiles=function(a,b,c,d,e){"undefined"==typeof e&&(e=!1),a=this._fixX(a),b=this._fixY(b),c>this.layer.widthInPixels&&(c=this.layer.widthInPixels),d>this.layer.heightInPixels&&(d=this.layer.heightInPixels),this._tx=this.game.math.snapToFloor(a,this._cw)/this._cw,this._ty=this.game.math.snapToFloor(b,this._ch)/this._ch,this._tw=(this.game.math.snapToCeil(c,this._cw)+this._cw)/this._cw,this._th=(this.game.math.snapToCeil(d,this._ch)+this._ch)/this._ch,this._results.length=0;for(var f=null,g=this._ty;gthis.layer.width&&(this._maxX=this.layer.width),this._maxY>this.layer.height&&(this._maxY=this.layer.height)),this.dirty=!0},c.TilemapLayer.prototype.render=function(){if(this.layer.dirty&&(this.dirty=!0),this.dirty&&this.visible){this._prevX=this._dx,this._prevY=this._dy,this._dx=-(this._x-this._startX*this.map.tileWidth),this._dy=-(this._y-this._startY*this.map.tileHeight),this._tx=this._dx,this._ty=this._dy,this.context.clearRect(0,0,this.canvas.width,this.canvas.height),this.context.fillStyle=this.tileColor;var a,d;this.debug&&(this.context.globalAlpha=this.debugAlpha);for(var e=this._startY,f=this._startY+this._maxY;f>e;e++){this._column=this.layer.data[e];for(var g=this._startX,h=this._startX+this._maxX;h>g;g++)this._column[g]&&(a=this._column[g],this.map.tiles[a.index]&&(d=this.map.tilesets[this.map.tiles[a.index][2]],d.image?d.tileWidth!==this.map.tileWidth||d.tileHeight!==this.map.tileHeight?this.context.drawImage(this.map.tilesets[this.map.tiles[a.index][2]].image,this.map.tiles[a.index][0],this.map.tiles[a.index][1],d.tileWidth,d.tileHeight,Math.floor(this._tx),Math.floor(this._ty)-(d.tileHeight-this.map.tileHeight),d.tileWidth,d.tileHeight):this.context.drawImage(this.map.tilesets[this.map.tiles[a.index][2]].image,this.map.tiles[a.index][0],this.map.tiles[a.index][1],this.map.tileWidth,this.map.tileHeight,Math.floor(this._tx),Math.floor(this._ty),this.map.tileWidth,this.map.tileHeight):this.context.fillRect(Math.floor(this._tx),Math.floor(this._ty),this.map.tileWidth,this.map.tileHeight))),this._tx+=this.map.tileWidth;this._tx=this._dx,this._ty+=this.map.tileHeight}return this.debug&&(this.context.globalAlpha=1,this.renderDebug()),this.game.renderType===c.WEBGL&&b.texturesToUpdate.push(this.baseTexture),this.dirty=!1,this.layer.dirty=!1,!0}},c.TilemapLayer.prototype.renderDebug=function(){this._tx=this._dx,this._ty=this._dy,this.context.strokeStyle=this.debugColor,this.context.fillStyle=this.debugFillColor;for(var a=this._startY,b=this._startY+this._maxY;b>a;a++){this._column=this.layer.data[a];for(var c=this._startX,d=this._startX+this._maxX;d>c;c++){var e=this._column[c];e&&(e.faceTop||e.faceBottom||e.faceLeft||e.faceRight)&&(this._tx=Math.floor(this._tx),this.debugFill&&this.context.fillRect(this._tx,this._ty,this._cw,this._ch),this.context.beginPath(),e.faceTop&&(this.context.moveTo(this._tx,this._ty),this.context.lineTo(this._tx+this._cw,this._ty)),e.faceBottom&&(this.context.moveTo(this._tx,this._ty+this._ch),this.context.lineTo(this._tx+this._cw,this._ty+this._ch)),e.faceLeft&&(this.context.moveTo(this._tx,this._ty),this.context.lineTo(this._tx,this._ty+this._ch)),e.faceRight&&(this.context.moveTo(this._tx+this._cw,this._ty),this.context.lineTo(this._tx+this._cw,this._ty+this._ch)),this.context.stroke()),this._tx+=this.map.tileWidth}this._tx=this._dx,this._ty+=this.map.tileHeight}},Object.defineProperty(c.TilemapLayer.prototype,"scrollX",{get:function(){return this._x},set:function(a){a!==this._x&&a>=0&&this.layer.widthInPixels>this.width&&(this._x=a,this._x>this.layer.widthInPixels-this.width&&(this._x=this.layer.widthInPixels-this.width),this._startX=this.game.math.floor(this._x/this.map.tileWidth),this._startX<0&&(this._startX=0),this._startX+this._maxX>this.layer.width&&(this._startX=this.layer.width-this._maxX),this.dirty=!0)}}),Object.defineProperty(c.TilemapLayer.prototype,"scrollY",{get:function(){return this._y},set:function(a){a!==this._y&&a>=0&&this.layer.heightInPixels>this.height&&(this._y=a,this._y>this.layer.heightInPixels-this.height&&(this._y=this.layer.heightInPixels-this.height),this._startY=this.game.math.floor(this._y/this.map.tileHeight),this._startY<0&&(this._startY=0),this._startY+this._maxY>this.layer.height&&(this._startY=this.layer.height-this._maxY),this.dirty=!0)}}),Object.defineProperty(c.TilemapLayer.prototype,"collisionWidth",{get:function(){return this._cw},set:function(a){this._cw=a,this.dirty=!0}}),Object.defineProperty(c.TilemapLayer.prototype,"collisionHeight",{get:function(){return this._ch},set:function(a){this._ch=a,this.dirty=!0}}),c.TilemapParser={tileset:function(a,b,d,e,f,g,h,i,j){var k=a.cache.getTilesetImage(b);if(null===k)return console.warn("Phaser.TilemapParser.tileSet: Invalid image key given"),null;var l=k.width,m=k.height;return-1===h&&(h=Math.round(l/d)),-1===i&&(i=Math.round(m/e)),-1===j&&(j=h*i),0===l||0===m||d>l||e>m||0===j?(console.warn("Phaser.TilemapParser.tileSet: width/height zero or width/height < given tileWidth/tileHeight"),null):new c.Tileset(k,b,d,e,f,g,h,i,j)},parse:function(a,b){var d=a.cache.getTilemapData(b);return d?d.format===c.Tilemap.CSV?this.parseCSV(d.data):d.format===c.Tilemap.TILED_JSON?this.parseTiledJSON(d.data):void 0:{layers:[],objects:[],images:[],tilesets:[]}},parseCSV:function(a){a=a.trim();for(var b=[],c=a.split("\n"),d=c.length,e=0,f=0;fj;j++)a.layers[e].data[j]>0?h.push(new c.Tile(a.layers[e].data[j],g,i.length,a.tilewidth,a.tileheight)):h.push(null),g++,g===a.layers[e].width&&(i.push(h),g=0,h=[]);f.data=i,d.push(f)}b.layers=d;for(var l=[],e=0;eo;o++)if(a.layers[e].objects[o].gid){var p={gid:a.layers[e].objects[o].gid,name:a.layers[e].objects[o].name,x:a.layers[e].objects[o].x,y:a.layers[e].objects[o].y,visible:a.layers[e].objects[o].visible,properties:a.layers[e].objects[o].properties};n[a.layers[e].name].push(p)}}b.objects=n;for(var q=[],e=0;e0&&(b.Texture.frameUpdates.length=0)},b.CanvasRenderer.prototype.renderDisplayObject=function(a,c){var d=a.last._iNext;a=a.first;do if(a.visible||c)if(a.renderable&&0!==a.alpha){if(a instanceof b.Sprite)a.texture.frame&&(this.context.globalAlpha=a.worldAlpha,this.context.setTransform(a.worldTransform[0],a.worldTransform[3],a.worldTransform[1],a.worldTransform[4],a.worldTransform[2],a.worldTransform[5]),a.texture.trimmed&&this.context.transform(1,0,0,1,a.texture.trim.x,a.texture.trim.y),this.smoothProperty&&this.scaleMode!==a.texture.baseTexture.scaleMode&&(this.scaleMode=a.texture.baseTexture.scaleMode,this.context[this.smoothProperty]=this.scaleMode===b.BaseTexture.SCALE_MODE.LINEAR),this.context.drawImage(a.texture.baseTexture.source,a.texture.frame.x,a.texture.frame.y,a.texture.frame.width,a.texture.frame.height,Math.floor(a.anchor.x*-a.texture.frame.width),Math.floor(a.anchor.y*-a.texture.frame.height),a.texture.frame.width,a.texture.frame.height));else if(a instanceof b.Strip)this.context.setTransform(a.worldTransform[0],a.worldTransform[3],a.worldTransform[1],a.worldTransform[4],a.worldTransform[2],a.worldTransform[5]),this.renderStrip(a);else if(a instanceof b.TilingSprite)this.context.setTransform(a.worldTransform[0],a.worldTransform[3],a.worldTransform[1],a.worldTransform[4],a.worldTransform[2],a.worldTransform[5]),this.renderTilingSprite(a);else if(a instanceof b.CustomRenderable)a.renderCanvas(this);else if(a instanceof b.Graphics)this.context.setTransform(a.worldTransform[0],a.worldTransform[3],a.worldTransform[1],a.worldTransform[4],a.worldTransform[2],a.worldTransform[5]),b.CanvasGraphics.renderGraphics(a,this.context);else if(a instanceof b.FilterBlock)if(a.open){this.context.save();var e=a.mask.alpha,f=a.mask.worldTransform;this.context.setTransform(f[0],f[3],f[1],f[4],f[2],f[5]),a.mask.worldAlpha=.5,this.context.worldAlpha=0,b.CanvasGraphics.renderGraphicsMask(a.mask,this.context),this.context.clip(),a.mask.worldAlpha=e}else this.context.restore();a=a._iNext}else a=a._iNext;else a=a.last._iNext;while(a!=d)},b.WebGLBatch.prototype.update=function(){for(var a,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r=0,s=this.head;s;){if(s.vcount===b.visibleCount){if(c=s.texture.frame.width,d=s.texture.frame.height,e=s.anchor.x,f=s.anchor.y,g=c*(1-e),h=c*-e,i=d*(1-f),j=d*-f,k=8*r,a=s.worldTransform,l=a[0],m=a[3],n=a[1],o=a[4],p=a[2],q=a[5],s.texture.trimmed&&(p+=s.texture.trim.x,q+=s.texture.trim.y),this.verticies[k+0]=l*h+n*j+p,this.verticies[k+1]=o*j+m*h+q,this.verticies[k+2]=l*g+n*j+p,this.verticies[k+3]=o*j+m*g+q,this.verticies[k+4]=l*g+n*i+p,this.verticies[k+5]=o*i+m*g+q,this.verticies[k+6]=l*h+n*i+p,this.verticies[k+7]=o*i+m*h+q,s.updateFrame||s.texture.updateFrame){this.dirtyUVS=!0;var t=s.texture,u=t.frame,v=t.baseTexture.width,w=t.baseTexture.height;this.uvs[k+0]=u.x/v,this.uvs[k+1]=u.y/w,this.uvs[k+2]=(u.x+u.width)/v,this.uvs[k+3]=u.y/w,this.uvs[k+4]=(u.x+u.width)/v,this.uvs[k+5]=(u.y+u.height)/w,this.uvs[k+6]=u.x/v,this.uvs[k+7]=(u.y+u.height)/w,s.updateFrame=!1}if(s.cacheAlpha!=s.worldAlpha){s.cacheAlpha=s.worldAlpha;var x=4*r;this.colors[x]=this.colors[x+1]=this.colors[x+2]=this.colors[x+3]=s.worldAlpha,this.dirtyColors=!0}}else k=8*r,this.verticies[k+0]=0,this.verticies[k+1]=0,this.verticies[k+2]=0,this.verticies[k+3]=0,this.verticies[k+4]=0,this.verticies[k+5]=0,this.verticies[k+6]=0,this.verticies[k+7]=0;r++,s=s.__next}},c}); \ No newline at end of file