diff --git a/README.md b/README.md
index bfe3705a..d6d0ff52 100644
--- a/README.md
+++ b/README.md
@@ -42,6 +42,7 @@ Change Log
Version 1.1.3 - in build
* New: Added a .jshintrc so contributions can be run through JSHint to help retain formatting across the library (thanks kevinthompson)
+* New: The entire Phaser library has been updated to match the new JSHint configuration.
* New: Added a new in-built texture. Sprites now use __default if no texture was provided (a 32x32 transparent PNG) or __missing if one was given but not found (a 32x32 black box with a green cross through it)
* New: Added Phaser.Filter. A new way to use the new WebGL shaders/filters that the new version of Pixi supports.
* New: The object returned by Math.sinCosGenerator now contains a length property.
@@ -84,13 +85,12 @@ Version 1.1.3 - in build
* Updated: Tided up the Graphics object (thanks BorisKozo)
* Updated: If running in Canvas mode and you have a render function it will save the context and reset the transform before running your render function.
* Updated: Sprite will now check the exists property of the Group it is in, if the Group.exists = false the Sprite won't update.
-* Updated: Lots of documentation tweaks across various files such as Pointer, Sound and Color.
+* Updated: Lots of documentation fixes and updates across nearly all files.
* Updated: If you specify 'null' as a Group parent it will now revert to using the World as the parent (before only 'undefined' worked)
* Updated: Skip preupdate/update for PIXI hierarchies in which an ancestor doesn't exist (thanks cocoademon)
* Updated: Loader.audio can now accept either an array of URL strings or a single URL string (thanks crazysam + kevinthompson)
* Updated: MSPointer updated to support IE11 by dropping the prefix from the event listeners.
-
You can view the complete Change Log for all previous versions at https://github.com/photonstorm/phaser/changelog.md
How to Build
diff --git a/src/PixiPatch.js b/src/PixiPatch.js
index db56ae7b..a085f69a 100644
--- a/src/PixiPatch.js
+++ b/src/PixiPatch.js
@@ -16,238 +16,240 @@
*/
PIXI.CanvasRenderer.prototype.render = function(stage)
{
- PIXI.texturesToUpdate.length = 0;
- PIXI.texturesToDestroy.length = 0;
-
- PIXI.visibleCount++;
- stage.updateTransform();
-
- // update the background color
- // if(this.view.style.backgroundColor!=stage.backgroundColorString && !this.transparent)this.view.style.backgroundColor = stage.backgroundColorString;
+ PIXI.texturesToUpdate.length = 0;
+ PIXI.texturesToDestroy.length = 0;
+
+ 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.context.setTransform(1, 0, 0, 1, 0, 0);
+ // this.context.clearRect(0, 0, this.width, this.height)
this.renderDisplayObject(stage);
- // Remove frame updates
- if (PIXI.Texture.frameUpdates.length > 0)
- {
- PIXI.Texture.frameUpdates.length = 0;
- }
-
+ // Remove frame updates
+ if (PIXI.Texture.frameUpdates.length > 0)
+ {
+ PIXI.Texture.frameUpdates.length = 0;
+ }
+
}
PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject)
{
- // Once 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.alpha === 0)
- {
- displayObject = displayObject._iNext;
- continue;
- }
-
- if (displayObject instanceof PIXI.Sprite)
- {
- // var frame = displayObject.texture.frame;
-
- if (displayObject.texture.frame)
- {
- this.context.globalAlpha = displayObject.worldAlpha;
-
- 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);
- }
- else
- {
- this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2], displayObject.worldTransform[5]);
- }
-
- this.context.drawImage(
- displayObject.texture.baseTexture.source,
- displayObject.texture.frame.x,
- 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,
- displayObject.texture.frame.width,
- displayObject.texture.frame.height);
- }
- }
- else if (displayObject instanceof PIXI.Strip)
- {
- this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2], displayObject.worldTransform[5])
- this.renderStrip(displayObject);
- }
- else if (displayObject instanceof PIXI.TilingSprite)
- {
- this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2], displayObject.worldTransform[5])
- this.renderTilingSprite(displayObject);
- }
- else if (displayObject instanceof PIXI.CustomRenderable)
- {
- displayObject.renderCanvas(this);
- }
- else if (displayObject instanceof PIXI.Graphics)
- {
- this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2], displayObject.worldTransform[5])
- PIXI.CanvasGraphics.renderGraphics(displayObject, this.context);
- }
- else if (displayObject instanceof PIXI.FilterBlock)
- {
- if (displayObject.open)
- {
- this.context.save();
-
- var cacheAlpha = displayObject.mask.alpha;
- var maskTransform = displayObject.mask.worldTransform;
-
- this.context.setTransform(maskTransform[0], maskTransform[3], maskTransform[1], maskTransform[4], maskTransform[2], maskTransform[5])
-
- displayObject.mask.worldAlpha = 0.5;
-
- this.context.worldAlpha = 0;
-
- PIXI.CanvasGraphics.renderGraphicsMask(displayObject.mask, this.context);
- this.context.clip();
-
- displayObject.mask.worldAlpha = cacheAlpha;
- }
- else
- {
- this.context.restore();
- }
- }
- // count++
- displayObject = displayObject._iNext;
- }
- while(displayObject != testObject)
-
+ // Once 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.alpha === 0)
+ {
+ displayObject = displayObject._iNext;
+ continue;
+ }
+
+ if (displayObject instanceof PIXI.Sprite)
+ {
+ // var frame = displayObject.texture.frame;
+
+ if (displayObject.texture.frame)
+ {
+ this.context.globalAlpha = displayObject.worldAlpha;
+
+ 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);
+ }
+ else
+ {
+ this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2], displayObject.worldTransform[5]);
+ }
+
+ this.context.drawImage(
+ displayObject.texture.baseTexture.source,
+ displayObject.texture.frame.x,
+ 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,
+ displayObject.texture.frame.width,
+ displayObject.texture.frame.height);
+ }
+ }
+ else if (displayObject instanceof PIXI.Strip)
+ {
+ this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2], displayObject.worldTransform[5])
+ this.renderStrip(displayObject);
+ }
+ else if (displayObject instanceof PIXI.TilingSprite)
+ {
+ this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2], displayObject.worldTransform[5])
+ this.renderTilingSprite(displayObject);
+ }
+ else if (displayObject instanceof PIXI.CustomRenderable)
+ {
+ displayObject.renderCanvas(this);
+ }
+ else if (displayObject instanceof PIXI.Graphics)
+ {
+ this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2], displayObject.worldTransform[5])
+ PIXI.CanvasGraphics.renderGraphics(displayObject, this.context);
+ }
+ else if (displayObject instanceof PIXI.FilterBlock)
+ {
+ if (displayObject.open)
+ {
+ this.context.save();
+
+ var cacheAlpha = displayObject.mask.alpha;
+ var maskTransform = displayObject.mask.worldTransform;
+
+ this.context.setTransform(maskTransform[0], maskTransform[3], maskTransform[1], maskTransform[4], maskTransform[2], maskTransform[5])
+
+ displayObject.mask.worldAlpha = 0.5;
+
+ this.context.worldAlpha = 0;
+
+ PIXI.CanvasGraphics.renderGraphicsMask(displayObject.mask, this.context);
+ this.context.clip();
+
+ displayObject.mask.worldAlpha = cacheAlpha;
+ }
+ else
+ {
+ this.context.restore();
+ }
+ }
+ // count++
+ displayObject = displayObject._iNext;
+ }
+ while(displayObject != testObject)
+
}
PIXI.WebGLBatch.prototype.update = function()
{
- var gl = this.gl;
- var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index, index2, index3
+ // var gl = this.gl;
+ // var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index, index2, index3
- var a, b, c, d, tx, ty;
+ var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index;
- var indexRun = 0;
+ var a, b, c, d, tx, ty;
- var displayObject = this.head;
+ var indexRun = 0;
- while(displayObject)
- {
- if(displayObject.vcount === PIXI.visibleCount)
- {
- width = displayObject.texture.frame.width;
- height = displayObject.texture.frame.height;
+ var displayObject = this.head;
- // 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;
- if (displayObject.texture.trimmed)
- {
- tx += displayObject.texture.trim.x;
- ty += displayObject.texture.trim.y;
- }
+ a = worldTransform[0];
+ b = worldTransform[3];
+ c = worldTransform[1];
+ d = worldTransform[4];
+ tx = worldTransform[2];
+ ty = worldTransform[5];
- this.verticies[index + 0 ] = a * w1 + c * h1 + tx;
- this.verticies[index + 1 ] = d * h1 + b * w1 + ty;
+ if (displayObject.texture.trimmed)
+ {
+ tx += displayObject.texture.trim.x;
+ ty += displayObject.texture.trim.y;
+ }
- this.verticies[index + 2 ] = a * w0 + c * h1 + tx;
- this.verticies[index + 3 ] = d * h1 + b * w0 + ty;
+ this.verticies[index + 0 ] = a * w1 + c * h1 + tx;
+ this.verticies[index + 1 ] = d * h1 + b * w1 + ty;
- this.verticies[index + 4 ] = a * w0 + c * h0 + tx;
- this.verticies[index + 5 ] = d * h0 + b * w0 + ty;
+ this.verticies[index + 2 ] = a * w0 + c * h1 + tx;
+ this.verticies[index + 3 ] = d * h1 + b * w0 + ty;
- this.verticies[index + 6] = a * w1 + c * h0 + tx;
- this.verticies[index + 7] = d * h0 + b * w1 + ty;
+ this.verticies[index + 4 ] = a * w0 + c * h0 + tx;
+ this.verticies[index + 5 ] = d * h0 + b * w0 + ty;
- if(displayObject.updateFrame || displayObject.texture.updateFrame)
- {
- this.dirtyUVS = true;
+ this.verticies[index + 6] = a * w1 + c * h0 + tx;
+ this.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;
- this.uvs[index + 0] = frame.x / tw;
- this.uvs[index +1] = frame.y / th;
+ var frame = texture.frame;
+ var tw = texture.baseTexture.width;
+ var th = texture.baseTexture.height;
- this.uvs[index +2] = (frame.x + frame.width) / tw;
- this.uvs[index +3] = frame.y / th;
+ this.uvs[index + 0] = frame.x / tw;
+ this.uvs[index +1] = frame.y / th;
- this.uvs[index +4] = (frame.x + frame.width) / tw;
- this.uvs[index +5] = (frame.y + frame.height) / th;
+ this.uvs[index +2] = (frame.x + frame.width) / tw;
+ this.uvs[index +3] = frame.y / th;
- this.uvs[index +6] = frame.x / tw;
- this.uvs[index +7] = (frame.y + frame.height) / th;
+ this.uvs[index +4] = (frame.x + frame.width) / tw;
+ this.uvs[index +5] = (frame.y + frame.height) / th;
- displayObject.updateFrame = false;
- }
+ this.uvs[index +6] = frame.x / tw;
+ this.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;
- this.colors[colorIndex] = this.colors[colorIndex + 1] = this.colors[colorIndex + 2] = this.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;
- this.verticies[index + 0 ] = 0;
- this.verticies[index + 1 ] = 0;
+ var colorIndex = indexRun * 4;
+ this.colors[colorIndex] = this.colors[colorIndex + 1] = this.colors[colorIndex + 2] = this.colors[colorIndex + 3] = displayObject.worldAlpha;
+ this.dirtyColors = true;
+ }
+ }
+ else
+ {
+ index = indexRun * 8;
- this.verticies[index + 2 ] = 0;
- this.verticies[index + 3 ] = 0;
+ this.verticies[index + 0 ] = 0;
+ this.verticies[index + 1 ] = 0;
- this.verticies[index + 4 ] = 0;
- this.verticies[index + 5 ] = 0;
+ this.verticies[index + 2 ] = 0;
+ this.verticies[index + 3 ] = 0;
- this.verticies[index + 6] = 0;
- this.verticies[index + 7] = 0;
- }
+ this.verticies[index + 4 ] = 0;
+ this.verticies[index + 5 ] = 0;
- indexRun++;
- displayObject = displayObject.__next;
- }
+ this.verticies[index + 6] = 0;
+ this.verticies[index + 7] = 0;
+ }
+
+ indexRun++;
+ displayObject = displayObject.__next;
+ }
}
diff --git a/src/core/Group.js b/src/core/Group.js
index fb1287bd..ba0cd61c 100644
--- a/src/core/Group.js
+++ b/src/core/Group.js
@@ -571,14 +571,14 @@ Phaser.Group.prototype = {
},
/**
- * Sets the given property to the given value on the child. The operation controls the assignment of the value.
- *
- * @method Phaser.Group#setProperty
- * @param {*} child - The child to set the property value on.
- * @param {array} key - An array of strings that make up the property that will be set.
- * @param {*} value - The value that will be set.
- * @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.
- */
+ * Sets the given property to the given value on the child. The operation controls the assignment of the value.
+ *
+ * @method Phaser.Group#setProperty
+ * @param {*} child - The child to set the property value on.
+ * @param {array} key - An array of strings that make up the property that will be set.
+ * @param {*} value - The value that will be set.
+ * @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.
+ */
setProperty: function (child, key, value, operation) {
operation = operation || 0;
@@ -633,16 +633,16 @@ Phaser.Group.prototype = {
},
/**
- * 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.
- *
- * @method Phaser.Group#setAll
- * @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 only children with alive=true will be updated.
- * @param {boolean} [checkVisible=false] - If set then only children with visible=true will be updated.
- * @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.
- */
+ * 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.
+ *
+ * @method Phaser.Group#setAll
+ * @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 only children with alive=true will be updated.
+ * @param {boolean} [checkVisible=false] - If set then only children with visible=true will be updated.
+ * @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.
+ */
setAll: function (key, value, checkAlive, checkVisible, operation) {
key = key.split('.');
@@ -671,15 +671,15 @@ Phaser.Group.prototype = {
},
/**
- * Adds the amount to the given property on all children in this Group.
- * Group.addAll('x', 10) will add 10 to the child.x value.
- *
- * @method Phaser.Group#addAll
- * @param {string} property - The property to increment, for example 'body.velocity.x' or 'angle'.
- * @param {number} amount - The amount to increment the property by. If child.x = 10 then addAll('x', 40) would make child.x = 50.
- * @param {boolean} checkAlive - If true the property will only be changed if the child is alive.
- * @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
- */
+ * Adds the amount to the given property on all children in this Group.
+ * Group.addAll('x', 10) will add 10 to the child.x value.
+ *
+ * @method Phaser.Group#addAll
+ * @param {string} property - The property to increment, for example 'body.velocity.x' or 'angle'.
+ * @param {number} amount - The amount to increment the property by. If child.x = 10 then addAll('x', 40) would make child.x = 50.
+ * @param {boolean} checkAlive - If true the property will only be changed if the child is alive.
+ * @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
+ */
addAll: function (property, amount, checkAlive, checkVisible) {
this.setAll(property, amount, checkAlive, checkVisible, 1);
@@ -687,15 +687,15 @@ Phaser.Group.prototype = {
},
/**
- * Subtracts the amount from the given property on all children in this Group.
- * Group.subAll('x', 10) will minus 10 from the child.x value.
- *
- * @method Phaser.Group#subAll
- * @param {string} property - The property to decrement, for example 'body.velocity.x' or 'angle'.
- * @param {number} amount - The amount to subtract from the property. If child.x = 50 then subAll('x', 40) would make child.x = 10.
- * @param {boolean} checkAlive - If true the property will only be changed if the child is alive.
- * @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
- */
+ * Subtracts the amount from the given property on all children in this Group.
+ * Group.subAll('x', 10) will minus 10 from the child.x value.
+ *
+ * @method Phaser.Group#subAll
+ * @param {string} property - The property to decrement, for example 'body.velocity.x' or 'angle'.
+ * @param {number} amount - The amount to subtract from the property. If child.x = 50 then subAll('x', 40) would make child.x = 10.
+ * @param {boolean} checkAlive - If true the property will only be changed if the child is alive.
+ * @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
+ */
subAll: function (property, amount, checkAlive, checkVisible) {
this.setAll(property, amount, checkAlive, checkVisible, 2);
@@ -703,15 +703,15 @@ Phaser.Group.prototype = {
},
/**
- * Multiplies the given property by the amount on all children in this Group.
- * Group.multiplyAll('x', 2) will x2 the child.x value.
- *
- * @method Phaser.Group#multiplyAll
- * @param {string} property - The property to multiply, for example 'body.velocity.x' or 'angle'.
- * @param {number} amount - The amount to multiply the property by. If child.x = 10 then multiplyAll('x', 2) would make child.x = 20.
- * @param {boolean} checkAlive - If true the property will only be changed if the child is alive.
- * @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
- */
+ * Multiplies the given property by the amount on all children in this Group.
+ * Group.multiplyAll('x', 2) will x2 the child.x value.
+ *
+ * @method Phaser.Group#multiplyAll
+ * @param {string} property - The property to multiply, for example 'body.velocity.x' or 'angle'.
+ * @param {number} amount - The amount to multiply the property by. If child.x = 10 then multiplyAll('x', 2) would make child.x = 20.
+ * @param {boolean} checkAlive - If true the property will only be changed if the child is alive.
+ * @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
+ */
multiplyAll: function (property, amount, checkAlive, checkVisible) {
this.setAll(property, amount, checkAlive, checkVisible, 3);
@@ -719,15 +719,15 @@ Phaser.Group.prototype = {
},
/**
- * Divides the given property by the amount on all children in this Group.
- * Group.divideAll('x', 2) will half the child.x value.
- *
- * @method Phaser.Group#divideAll
- * @param {string} property - The property to divide, for example 'body.velocity.x' or 'angle'.
- * @param {number} amount - The amount to divide the property by. If child.x = 100 then divideAll('x', 2) would make child.x = 50.
- * @param {boolean} checkAlive - If true the property will only be changed if the child is alive.
- * @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
- */
+ * Divides the given property by the amount on all children in this Group.
+ * Group.divideAll('x', 2) will half the child.x value.
+ *
+ * @method Phaser.Group#divideAll
+ * @param {string} property - The property to divide, for example 'body.velocity.x' or 'angle'.
+ * @param {number} amount - The amount to divide the property by. If child.x = 100 then divideAll('x', 2) would make child.x = 50.
+ * @param {boolean} checkAlive - If true the property will only be changed if the child is alive.
+ * @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
+ */
divideAll: function (property, amount, checkAlive, checkVisible) {
this.setAll(property, amount, checkAlive, checkVisible, 4);
diff --git a/src/core/PluginManager.js b/src/core/PluginManager.js
index 5838e94c..1ca1f92d 100644
--- a/src/core/PluginManager.js
+++ b/src/core/PluginManager.js
@@ -127,10 +127,10 @@ Phaser.PluginManager.prototype = {
},
/**
- * Remove a Plugin from the PluginManager.
- * @method Phaser.PluginManager#remove
- * @param {Phaser.Plugin} plugin - The plugin to be removed.
- */
+ * Remove a Plugin from the PluginManager.
+ * @method Phaser.PluginManager#remove
+ * @param {Phaser.Plugin} plugin - The plugin to be removed.
+ */
remove: function (plugin) {
if (this._pluginsLength === 0)
@@ -151,9 +151,9 @@ Phaser.PluginManager.prototype = {
},
/**
- * Removes all Plugins from the PluginManager.
- * @method Phaser.PluginManager#removeAll
- */
+ * Removes all Plugins from the PluginManager.
+ * @method Phaser.PluginManager#removeAll
+ */
removeAll: function() {
for (this._p = 0; this._p < this._pluginsLength; this._p++)
diff --git a/src/core/Signal.js b/src/core/Signal.js
index 05b18376..7a3db73c 100644
--- a/src/core/Signal.js
+++ b/src/core/Signal.js
@@ -73,14 +73,14 @@ Phaser.Signal.prototype = {
},
/**
- * @method Phaser.Signal#_registerListener
- * @param {function} listener - Signal handler function.
- * @param {boolean} isOnce - Description.
- * @param {object} [listenerContext] - Description.
- * @param {number} [priority] - The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0).
- * @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
- * @private
- */
+ * @method Phaser.Signal#_registerListener
+ * @param {function} listener - Signal handler function.
+ * @param {boolean} isOnce - Description.
+ * @param {object} [listenerContext] - Description.
+ * @param {number} [priority] - The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0).
+ * @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
+ * @private
+ */
_registerListener: function (listener, isOnce, listenerContext, priority) {
var prevIndex = this._indexOfListener(listener, listenerContext),
@@ -104,10 +104,10 @@ Phaser.Signal.prototype = {
},
/**
- * @method Phaser.Signal#_addBinding
- * @param {Phaser.SignalBinding} binding - An Object representing the binding between the Signal and listener.
- * @private
- */
+ * @method Phaser.Signal#_addBinding
+ * @param {Phaser.SignalBinding} binding - An Object representing the binding between the Signal and listener.
+ * @private
+ */
_addBinding: function (binding) {
//simplified insertion sort
var n = this._bindings.length;
@@ -116,11 +116,11 @@ Phaser.Signal.prototype = {
},
/**
- * @method Phaser.Signal#_indexOfListener
- * @param {function} listener - Signal handler function.
- * @return {number} Description.
- * @private
- */
+ * @method Phaser.Signal#_indexOfListener
+ * @param {function} listener - Signal handler function.
+ * @return {number} Description.
+ * @private
+ */
_indexOfListener: function (listener, context) {
var n = this._bindings.length,
cur;
@@ -134,26 +134,26 @@ Phaser.Signal.prototype = {
},
/**
- * Check if listener was attached to Signal.
- *
- * @method Phaser.Signal#has
- * @param {Function} listener - Signal handler function.
- * @param {Object} [context] - Context on which listener will be executed (object that should represent the `this` variable inside listener function).
- * @return {boolean} If Signal has the specified listener.
- */
+ * Check if listener was attached to Signal.
+ *
+ * @method Phaser.Signal#has
+ * @param {Function} listener - Signal handler function.
+ * @param {Object} [context] - Context on which listener will be executed (object that should represent the `this` variable inside listener function).
+ * @return {boolean} If Signal has the specified listener.
+ */
has: function (listener, context) {
return this._indexOfListener(listener, context) !== -1;
},
/**
- * Add a listener to the signal.
- *
- * @method Phaser.Signal#add
- * @param {function} listener - Signal handler function.
- * @param {object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
- * @param {number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0).
- * @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
- */
+ * Add a listener to the signal.
+ *
+ * @method Phaser.Signal#add
+ * @param {function} listener - Signal handler function.
+ * @param {object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
+ * @param {number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0).
+ * @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
+ */
add: function (listener, listenerContext, priority) {
this.validateListener(listener, 'add');
return this._registerListener(listener, false, listenerContext, priority);
diff --git a/src/core/Stage.js b/src/core/Stage.js
index fdd20717..38c06883 100644
--- a/src/core/Stage.js
+++ b/src/core/Stage.js
@@ -58,8 +58,8 @@ Phaser.Stage = function (game, width, height) {
this.scale = new Phaser.StageScaleMode(this.game, width, height);
/**
- * @property {number} aspectRatio - Aspect ratio.
- */
+ * @property {number} aspectRatio - Aspect ratio.
+ */
this.aspectRatio = width / height;
/**
diff --git a/src/core/StateManager.js b/src/core/StateManager.js
index 65d08460..b5ee71b6 100644
--- a/src/core/StateManager.js
+++ b/src/core/StateManager.js
@@ -172,10 +172,10 @@ Phaser.StateManager.prototype = {
},
/**
- * Delete the given state.
- * @method Phaser.StateManager#remove
- * @param {string} key - A unique key you use to reference this state, i.e. "MainMenu", "Level1".
- */
+ * Delete the given state.
+ * @method Phaser.StateManager#remove
+ * @param {string} key - A unique key you use to reference this state, i.e. "MainMenu", "Level1".
+ */
remove: function (key) {
if (this.current == key)
diff --git a/src/gameobjects/BitmapData.js b/src/gameobjects/BitmapData.js
index d5227b90..4f3a0aee 100644
--- a/src/gameobjects/BitmapData.js
+++ b/src/gameobjects/BitmapData.js
@@ -172,7 +172,7 @@ Phaser.BitmapData.prototype = {
{
this.data32[y * this.width + x] = (red << 24) | (green << 16) | (blue << 8) | alpha;
}
- */
+ */
// this.imageData.data.set(this.data8);
@@ -229,10 +229,10 @@ Phaser.BitmapData.prototype = {
},
/**
- * Get pixels in array in a specific Rectangle.
- * @param rect {Rectangle} The specific Rectangle.
- * @return {array} CanvasPixelArray.
- */
+ * Get pixels in array in a specific Rectangle.
+ * @param rect {Rectangle} The specific Rectangle.
+ * @return {array} CanvasPixelArray.
+ */
getPixels: function (rect) {
return this.context.getImageData(rect.x, rect.y, rect.width, rect.height);
diff --git a/src/gameobjects/BitmapText.js b/src/gameobjects/BitmapText.js
index 831e1aa3..e3bd57e2 100644
--- a/src/gameobjects/BitmapText.js
+++ b/src/gameobjects/BitmapText.js
@@ -21,10 +21,14 @@ Phaser.BitmapText = function (game, x, y, text, style) {
x = x || 0;
y = y || 0;
-
text = text || '';
style = style || '';
+ /**
+ * @property {Phaser.Game} game - A reference to the currently running Game.
+ */
+ this.game = game;
+
/**
* @property {boolean} exists - If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all.
* @default
@@ -38,53 +42,51 @@ Phaser.BitmapText = function (game, x, y, text, style) {
this.alive = true;
/**
- * @property {Description} group - Description.
- * @default
+ * @property {Phaser.Group} group - The parent Group of this BitmapText.
*/
this.group = null;
/**
- * @property {string} name - Description.
+ * @property {string} name - The user defined name given to this BitmapText.
* @default
*/
this.name = '';
/**
- * @property {Phaser.Game} game - A reference to the currently running Game.
+ * @property {number} type - The const type of this object.
+ * @readonly
*/
- this.game = game;
+ this.type = Phaser.BITMAPTEXT;
PIXI.BitmapText.call(this, text, style);
/**
- * @property {Description} type - Description.
- */
- this.type = Phaser.BITMAPTEXT;
-
- /**
- * @property {number} position.x - Description.
+ * @property {number} position.x - The x position of this object.
*/
this.position.x = x;
/**
- * @property {number} position.y - Description.
+ * @property {number} position.y - The y position of this object.
*/
this.position.y = y;
- // Replaces the PIXI.Point with a slightly more flexible one
/**
- * @property {Phaser.Point} anchor - Description.
+ * The anchor sets the origin point of the texture.
+ * The default is 0,0 this means the textures origin is the top left
+ * Setting than anchor to 0.5,0.5 means the textures origin is centered
+ * Setting the anchor to 1,1 would mean the textures origin points will be the bottom right
+ *
+ * @property {Phaser.Point} anchor - The anchor around which rotation and scaling takes place.
*/
this.anchor = new Phaser.Point();
/**
- * @property {Phaser.Point} scale - Description.
+ * @property {Phaser.Point} scale - The scale of the object when rendered. By default it's set to 1 (no scale). You can modify it via scale.x or scale.y or scale.setTo(x, y). A value of 1 means no change to the scale, 0.5 means "half the size", 2 means "twice the size", etc.
*/
this.scale = new Phaser.Point(1, 1);
- // A mini cache for storing all of the calculated values
/**
- * @property {function} _cache - Description.
+ * @property {object} _cache - A mini cache for storing all of the calculated values.
* @private
*/
this._cache = {
@@ -114,15 +116,13 @@ Phaser.BitmapText = function (game, x, y, text, style) {
this._cache.y = this.y;
/**
- * @property {boolean} renderable - Description.
- * @private
+ * @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);
-// Phaser.BitmapText.prototype = Phaser.Utils.extend(true, PIXI.BitmapText.prototype);
Phaser.BitmapText.prototype.constructor = Phaser.BitmapText;
/**
@@ -180,11 +180,11 @@ Phaser.BitmapText.prototype.destroy = function() {
}
/**
-* Get
-* @returns {Description}
-*//**
-* Set
-* @param {Description} value - Description
+* Indicates the rotation of the BitmapText, 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.BitmapText#angle
+* @property {number} angle - Gets or sets the angle of rotation in degrees.
*/
Object.defineProperty(Phaser.BitmapText.prototype, 'angle', {
@@ -199,11 +199,9 @@ Object.defineProperty(Phaser.BitmapText.prototype, 'angle', {
});
/**
-* Get
-* @returns {Description}
-*//**
-* Set
-* @param {Description} value - Description
+* The x coordinate of this object in world space.
+* @name Phaser.BitmapText#x
+* @property {number} x - The x coordinate of this object in world space.
*/
Object.defineProperty(Phaser.BitmapText.prototype, 'x', {
@@ -218,11 +216,9 @@ Object.defineProperty(Phaser.BitmapText.prototype, 'x', {
});
/**
-* Get
-* @returns {Description}
-*//**
-* Set
-* @param {Description} value - Description
+* The y coordinate of this object in world space.
+* @name Phaser.BitmapText#y
+* @property {number} y - The y coordinate of this object in world space.
*/
Object.defineProperty(Phaser.BitmapText.prototype, 'y', {
diff --git a/src/gameobjects/GameObjectFactory.js b/src/gameobjects/GameObjectFactory.js
index 85ea5289..a69a7c8b 100644
--- a/src/gameobjects/GameObjectFactory.js
+++ b/src/gameobjects/GameObjectFactory.js
@@ -100,14 +100,14 @@ Phaser.GameObjectFactory.prototype = {
},
/**
- * Creates a new instance of the Sound class.
- *
+ * Creates a new instance of the Sound class.
+ *
* @method Phaser.GameObjectFactory#audio
- * @param {string} key - The Game.cache key of the sound that this object will use.
- * @param {number} volume - The volume at which the sound will be played.
- * @param {boolean} loop - Whether or not the sound will loop.
- * @return {Phaser.Sound} The newly created text object.
- */
+ * @param {string} key - The Game.cache key of the sound that this object will use.
+ * @param {number} volume - The volume at which the sound will be played.
+ * @param {boolean} loop - Whether or not the sound will loop.
+ * @return {Phaser.Sound} The newly created text object.
+ */
audio: function (key, volume, loop) {
return this.game.sound.add(key, volume, loop);
@@ -115,17 +115,17 @@ Phaser.GameObjectFactory.prototype = {
},
/**
- * Creates a new TileSprite.
- *
+ * Creates a new TileSprite.
+ *
* @method Phaser.GameObjectFactory#tileSprite
- * @param {number} x - X position of the new tileSprite.
- * @param {number} y - Y position of the new tileSprite.
- * @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.
- * @return {Phaser.TileSprite} The newly created tileSprite object.
- */
+ * @param {number} x - X position of the new tileSprite.
+ * @param {number} y - Y position of the new tileSprite.
+ * @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.
+ * @return {Phaser.TileSprite} The newly created tileSprite object.
+ */
tileSprite: function (x, y, width, height, key, frame) {
return this.world.add(new Phaser.TileSprite(this.game, x, y, width, height, key, frame));
@@ -133,15 +133,15 @@ Phaser.GameObjectFactory.prototype = {
},
/**
- * Creates a new Text.
- *
+ * Creates a new Text.
+ *
* @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.
- * @return {Phaser.Text} The newly created text object.
- */
+ * @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.
+ * @return {Phaser.Text} The newly created text object.
+ */
text: function (x, y, text, style) {
return this.world.add(new Phaser.Text(this.game, x, y, text, style));
@@ -169,13 +169,13 @@ Phaser.GameObjectFactory.prototype = {
},
/**
- * 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.
- * @return {Phaser.Graphics} The newly created graphics object.
- */
+ * @param {number} x - X position of the new graphics object.
+ * @param {number} y - Y position of the new graphics object.
+ * @return {Phaser.Graphics} The newly created graphics object.
+ */
graphics: function (x, y) {
return this.world.add(new Phaser.Graphics(this.game, x, y));
diff --git a/src/gameobjects/Sprite.js b/src/gameobjects/Sprite.js
index 88987719..1cf92f7f 100644
--- a/src/gameobjects/Sprite.js
+++ b/src/gameobjects/Sprite.js
@@ -165,17 +165,17 @@ Phaser.Sprite = function (game, x, y, key, frame) {
* Setting than anchor to 0.5,0.5 means the textures origin is centered
* Setting the anchor to 1,1 would mean the textures origin points will be the bottom right
*
- * @property {Phaser.Point} anchor - The anchor around with Sprite rotation and scaling takes place.
+ * @property {Phaser.Point} anchor - The anchor around which rotation and scaling takes place.
*/
this.anchor = new Phaser.Point();
/**
- * @property {number} x - The x coordinate (in world space) of this Sprite.
+ * @property {number} x - The x coordinate in world space of this Sprite.
*/
this.x = x;
/**
- * @property {number} y - The y coordinate (in world space) of this Sprite.
+ * @property {number} y - The y coordinate in world space of this Sprite.
*/
this.y = y;
diff --git a/src/gameobjects/Text.js b/src/gameobjects/Text.js
index be088e18..63873f3a 100644
--- a/src/gameobjects/Text.js
+++ b/src/gameobjects/Text.js
@@ -27,24 +27,24 @@ Phaser.Text = function (game, x, y, text, style) {
this.game = game;
/**
- * @property {boolean} exists - If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all.
+ * @property {boolean} exists - If exists = false then the Text isn't updated by the core game loop.
* @default
*/
this.exists = true;
/**
- * @property {boolean} alive - This is a handy little var your game can use to determine if a sprite is alive or not, it doesn't effect rendering.
+ * @property {boolean} alive - This is a handy little var your game can use to determine if an object is alive or not, it doesn't effect rendering.
* @default
*/
this.alive = true;
/**
- * @property {Phaser.Group} group - The parent Group of this Sprite. This is usually set after Sprite instantiation by the parent.
+ * @property {Phaser.Group} group - The parent Group of this Text object.
*/
this.group = null;
/**
- * @property {string} name - The user defined name given to this Sprite.
+ * @property {string} name - The user defined name given to this object.
* @default
*/
this.name = '';
@@ -70,8 +70,8 @@ Phaser.Text = function (game, x, y, text, style) {
PIXI.Text.call(this, text, style);
/**
- * @property {Phaser.Point} position - The position of this Text object in world space.
- */
+ * @property {Phaser.Point} position - The position of this Text object in world space.
+ */
this.position.x = this.x = x;
this.position.y = this.y = y;
@@ -81,7 +81,7 @@ Phaser.Text = function (game, x, y, text, style) {
* Setting than anchor to 0.5,0.5 means the textures origin is centered
* Setting the anchor to 1,1 would mean the textures origin points will be the bottom right
*
- * @property {Phaser.Point} anchor - The anchor around with Sprite rotation and scaling takes place.
+ * @property {Phaser.Point} anchor - The anchor around which rotation and scaling takes place.
*/
this.anchor = new Phaser.Point();
@@ -182,11 +182,11 @@ Phaser.Text.prototype.destroy = function() {
}
/**
-* Get
-* @returns {Description}
-*//**
-* Set
-* @param {Description} value - Description
+* Indicates the rotation of the Text, 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.Text#angle
+* @property {number} angle - Gets or sets the angle of rotation in degrees.
*/
Object.defineProperty(Phaser.Text.prototype, 'angle', {
@@ -200,6 +200,45 @@ Object.defineProperty(Phaser.Text.prototype, 'angle', {
});
+/**
+* The x coordinate of this object in world space.
+* @name Phaser.BitmapText#x
+* @property {number} x - The x coordinate of this object in world space.
+*/
+Object.defineProperty(Phaser.BitmapText.prototype, 'x', {
+
+ get: function() {
+ return this.position.x;
+ },
+
+ set: function(value) {
+ this.position.x = value;
+ }
+
+});
+
+/**
+* The y coordinate of this object in world space.
+* @name Phaser.BitmapText#y
+* @property {number} y - The y coordinate of this object in world space.
+*/
+Object.defineProperty(Phaser.BitmapText.prototype, 'y', {
+
+ get: function() {
+ return this.position.y;
+ },
+
+ set: function(value) {
+ this.position.y = value;
+ }
+
+});
+
+/**
+* The string to be rendered by this Text object.
+* @name Phaser.Text#content
+* @property {string} content - The string to be rendered by this Text object.
+*/
Object.defineProperty(Phaser.Text.prototype, 'content', {
get: function() {
@@ -219,6 +258,11 @@ Object.defineProperty(Phaser.Text.prototype, 'content', {
});
+/**
+* The font the text will be rendered in.
+* @name Phaser.Text#font
+* @property {string} font - The font the text will be rendered in.
+*/
Object.defineProperty(Phaser.Text.prototype, 'font', {
get: function() {
diff --git a/src/geom/Circle.js b/src/geom/Circle.js
index a1529cd4..78b2765c 100644
--- a/src/geom/Circle.js
+++ b/src/geom/Circle.js
@@ -39,9 +39,9 @@ Phaser.Circle = function (x, y, diameter) {
if (diameter > 0)
{
/**
- * @property {number} _radius - The radius of the circle.
- * @private
- */
+ * @property {number} _radius - The radius of the circle.
+ * @private
+ */
this._radius = diameter * 0.5;
}
else
diff --git a/src/geom/Point.js b/src/geom/Point.js
index b03ca287..3b090b5b 100644
--- a/src/geom/Point.js
+++ b/src/geom/Point.js
@@ -233,29 +233,29 @@ Phaser.Point.prototype = {
},
/**
- * Calculates the length of the vector
- * @method Phaser.Point#getMagnitude
- * @return {number} the length of the vector
- */
+ * Calculates the length of the vector
+ * @method Phaser.Point#getMagnitude
+ * @return {number} the length of the vector
+ */
getMagnitude: function() {
return Math.sqrt((this.x * this.x) + (this.y * this.y));
},
/**
- * Alters the length of the vector without changing the direction
- * @method Phaser.Point#getMagnitude
- * @param {number} magnitude the desired magnitude of the resulting vector
- * @return {Phaser.Point} the modified original vector
- */
+ * Alters the length of the vector without changing the direction
+ * @method Phaser.Point#getMagnitude
+ * @param {number} magnitude the desired magnitude of the resulting vector
+ * @return {Phaser.Point} the modified original vector
+ */
setMagnitude: function(magnitude) {
return this.normalize().multiply(magnitude, magnitude);
},
/**
- * Alters the vector so that its length is 1, but it retains the same direction
- * @method Phaser.Point#normalize
- * @return {Phaser.Point} the modified original vector
- */
+ * Alters the vector so that its length is 1, but it retains the same direction
+ * @method Phaser.Point#normalize
+ * @return {Phaser.Point} the modified original vector
+ */
normalize: function() {
if(!this.isZero()) {
@@ -269,10 +269,10 @@ Phaser.Point.prototype = {
},
/**
- * Determine if this point is at 0,0
- * @method Phaser.Point#isZero
- * @return {boolean} True if this Point is 0,0, otherwise false
- */
+ * Determine if this point is at 0,0
+ * @method Phaser.Point#isZero
+ * @return {boolean} True if this Point is 0,0, otherwise false
+ */
isZero: function() {
return (this.x === 0 && this.y === 0);
},
diff --git a/src/input/Input.js b/src/input/Input.js
index 29f3a283..42d3c0ef 100644
--- a/src/input/Input.js
+++ b/src/input/Input.js
@@ -62,10 +62,10 @@ Phaser.Input.prototype = {
pollRate: 0,
/**
- * @property {number} _pollCounter - Internal var holding the current poll counter.
- * @private
- * @default
- */
+ * @property {number} _pollCounter - Internal var holding the current poll counter.
+ * @private
+ * @default
+ */
_pollCounter: 0,
/**
diff --git a/src/input/Touch.js b/src/input/Touch.js
index 1be40ee1..65c59e8b 100644
--- a/src/input/Touch.js
+++ b/src/input/Touch.js
@@ -273,7 +273,7 @@ Phaser.Touch.prototype = {
{
//console.log('touch enter');
}
- */
+ */
},
@@ -302,7 +302,7 @@ Phaser.Touch.prototype = {
{
//console.log('touch leave');
}
- */
+ */
},
diff --git a/src/loader/Cache.js b/src/loader/Cache.js
index 0481db68..ab380a3c 100644
--- a/src/loader/Cache.js
+++ b/src/loader/Cache.js
@@ -16,44 +16,44 @@
Phaser.Cache = 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 {object} game - Canvas key-value container.
- * @private
- */
+ /**
+ * @property {object} game - Canvas key-value container.
+ * @private
+ */
this._canvases = {};
/**
- * @property {object} _images - Image key-value container.
- * @private
- */
+ * @property {object} _images - Image key-value container.
+ * @private
+ */
this._images = {};
/**
- * @property {object} _textures - RenderTexture key-value container.
- * @private
- */
+ * @property {object} _textures - RenderTexture key-value container.
+ * @private
+ */
this._textures = {};
/**
- * @property {object} _sounds - Sound key-value container.
- * @private
- */
+ * @property {object} _sounds - Sound key-value container.
+ * @private
+ */
this._sounds = {};
/**
- * @property {object} _text - Text key-value container.
- * @private
- */
+ * @property {object} _text - Text key-value container.
+ * @private
+ */
this._text = {};
/**
- * @property {object} _tilemaps - Tilemap key-value container.
- * @private
- */
+ * @property {object} _tilemaps - Tilemap key-value container.
+ * @private
+ */
this._tilemaps = {};
/**
@@ -72,9 +72,9 @@ Phaser.Cache = function (game) {
this.addMissingImage();
/**
- * @property {Phaser.Signal} onSoundUnlock - Description.
- */
- this.onSoundUnlock = new Phaser.Signal;
+ * @property {Phaser.Signal} onSoundUnlock - This event is dispatched when the sound system is unlocked via a touch event on cellular devices.
+ */
+ this.onSoundUnlock = new Phaser.Signal();
};
@@ -282,7 +282,7 @@ Phaser.Cache.prototype = {
* @param {string} key - Asset key for the text data.
* @param {string} url - URL of this text data file.
* @param {object} data - Extra text data.
- */
+ */
addText: function (key, url, data) {
this._text[key] = {
@@ -326,7 +326,6 @@ Phaser.Cache.prototype = {
webAudio = webAudio || true;
audioTag = audioTag || false;
- var locked = this.game.sound.touchLocked;
var decoded = false;
if (audioTag)
@@ -388,13 +387,13 @@ Phaser.Cache.prototype = {
},
- /**
- * Add a new decoded sound.
+ /**
+ * Add a new decoded sound.
*
* @method Phaser.Cache#decodedSound
- * @param {string} key - Asset key for the sound.
- * @param {object} data - Extra sound data.
- */
+ * @param {string} key - Asset key for the sound.
+ * @param {object} data - Extra sound data.
+ */
decodedSound: function (key, data) {
this._sounds[key].data = data;
@@ -403,13 +402,13 @@ Phaser.Cache.prototype = {
},
- /**
- * Get a canvas object from the cache by its key.
+ /**
+ * 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 you want.
+ * @return {object} The canvas you want.
+ */
getCanvas: function (key) {
if (this._canvases[key])
@@ -445,7 +444,7 @@ Phaser.Cache.prototype = {
* @method Phaser.Cache#checkImageKey
* @param {string} key - Asset key of the image you want.
* @return {boolean} True if the key exists, otherwise false.
- */
+ */
checkImageKey: function (key) {
if (this._images[key])
@@ -457,13 +456,13 @@ Phaser.Cache.prototype = {
},
- /**
- * Get image data by key.
+ /**
+ * 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 you want.
+ * @return {object} The image data you want.
+ */
getImage: function (key) {
if (this._images[key])
@@ -481,7 +480,7 @@ Phaser.Cache.prototype = {
* @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])
@@ -499,7 +498,7 @@ Phaser.Cache.prototype = {
* @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])
@@ -528,13 +527,13 @@ Phaser.Cache.prototype = {
return null;
},
- /**
- * Get frame data by key.
+ /**
+ * 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 you want.
+ * @return {Phaser.FrameData} The frame data you want.
+ */
getFrameData: function (key) {
if (this._images[key] && this._images[key].frameData)
@@ -631,13 +630,13 @@ Phaser.Cache.prototype = {
},
- /**
- * Get sound by key.
+ /**
+ * 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 you want.
+ * @return {Phaser.Sound} The sound you want.
+ */
getSound: function (key) {
if (this._sounds[key])
@@ -649,13 +648,13 @@ Phaser.Cache.prototype = {
},
- /**
- * Get sound data by key.
+ /**
+ * 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 you want.
+ * @return {object} The sound data you want.
+ */
getSoundData: function (key) {
if (this._sounds[key])
@@ -667,13 +666,13 @@ Phaser.Cache.prototype = {
},
- /**
- * Check if the given sound has finished decoding.
+ /**
+ * Check if the given sound has finished decoding.
*
* @method Phaser.Cache#isSoundDecoded
- * @param {string} key - Asset key of the sound you want.
- * @return {boolean} The decoded state of the Sound object.
- */
+ * @param {string} key - Asset key of the sound you want.
+ * @return {boolean} The decoded state of the Sound object.
+ */
isSoundDecoded: function (key) {
if (this._sounds[key])
@@ -683,26 +682,26 @@ 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.
+ /**
+ * 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.
- * @return {boolean} True if the sound is decoded and the device is not touch locked.
- */
+ * @param {string} key - Asset key of the sound you want.
+ * @return {boolean} True if the sound is decoded and the device is not touch locked.
+ */
isSoundReady: function (key) {
return (this._sounds[key] && this._sounds[key].decoded && this.game.sound.touchLocked === false);
},
- /**
- * Check whether an image asset is sprite sheet or not.
+ /**
+ * Check whether an image asset is sprite sheet or not.
*
* @method Phaser.Cache#isSpriteSheet
- * @param {string} key - Asset key of the sprite sheet you want.
- * @return {boolean} True if the image is a sprite sheet.
- */
+ * @param {string} key - Asset key of the sprite sheet you want.
+ * @return {boolean} True if the image is a sprite sheet.
+ */
isSpriteSheet: function (key) {
if (this._images[key])
@@ -714,13 +713,13 @@ Phaser.Cache.prototype = {
},
- /**
- * Get text data by key.
+ /**
+ * 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 you want.
+ * @return {object} The text data you want.
+ */
getText: function (key) {
if (this._text[key])
@@ -756,42 +755,42 @@ Phaser.Cache.prototype = {
},
- /**
- * Returns an array containing all of the keys of Images in the Cache.
+ /**
+ * Returns an array containing all of the keys of Images in the Cache.
*
* @method Phaser.Cache#getImageKeys
- * @return {Array} The string based keys in the Cache.
- */
+ * @return {Array} The string based keys in the Cache.
+ */
getImageKeys: function () {
- return this.getKeys(this._images);
+ return this.getKeys(this._images);
},
- /**
- * Returns an array containing all of the keys of Sounds in the Cache.
+ /**
+ * Returns an array containing all of the keys of Sounds in the Cache.
*
* @method Phaser.Cache#getSoundKeys
- * @return {Array} The string based keys in the Cache.
- */
+ * @return {Array} The string based keys in the Cache.
+ */
getSoundKeys: function () {
- return this.getKeys(this._sounds);
+ return this.getKeys(this._sounds);
},
- /**
- * Returns an array containing all of the keys of Text Files in the Cache.
+ /**
+ * Returns an array containing all of the keys of Text Files in the Cache.
*
* @method Phaser.Cache#getTextKeys
- * @return {Array} The string based keys in the Cache.
- */
+ * @return {Array} The string based keys in the Cache.
+ */
getTextKeys: function () {
- return this.getKeys(this._text);
+ return this.getKeys(this._text);
},
- /**
- * Removes a canvas from the cache.
+ /**
+ * Removes a canvas from the cache.
*
- * @method Phaser.Cache#removeCanvas
+ * @method Phaser.Cache#removeCanvas
* @param {string} key - Key of the asset you want to remove.
- */
+ */
removeCanvas: function (key) {
delete this._canvases[key];
},
@@ -826,11 +825,11 @@ Phaser.Cache.prototype = {
delete this._text[key];
},
- /**
- * Clears the cache. Removes every local cache object reference.
+ /**
+ * Clears the cache. Removes every local cache object reference.
*
- * @method Phaser.Cache#destroy
- */
+ * @method Phaser.Cache#destroy
+ */
destroy: function () {
for (var item in this._canvases)
diff --git a/src/loader/Loader.js b/src/loader/Loader.js
index e786415d..ec79ce9e 100644
--- a/src/loader/Loader.js
+++ b/src/loader/Loader.js
@@ -16,101 +16,101 @@
*/
Phaser.Loader = function (game) {
- /**
+ /**
* @property {Phaser.Game} game - Local reference to game.
- */
- this.game = game;
-
- /**
- * @property {array} _keys - Array stores assets keys. So you can get that asset by its unique key.
- * @private
*/
- this._keys = [];
+ this.game = game;
- /**
- * @property {Description} _fileList - Contains all the assets file infos.
- * @private
+ /**
+ * @property {array} _keys - Array stores assets keys. So you can get that asset by its unique key.
+ * @private
*/
- this._fileList = {};
+ this._keys = [];
- /**
- * @property {number} _progressChunk - Indicates assets loading progress. (from 0 to 100)
- * @private
- * @default
- */
- this._progressChunk = 0;
+ /**
+ * @property {Description} _fileList - Contains all the assets file infos.
+ * @private
+ */
+ this._fileList = {};
- /**
- * @property {XMLHttpRequest} - An XMLHttpRequest object used for loading text and audio data.
- * @private
- */
- this._xhr = new XMLHttpRequest();
+ /**
+ * @property {number} _progressChunk - Indicates assets loading progress. (from 0 to 100)
+ * @private
+ * @default
+ */
+ this._progressChunk = 0;
- /**
- * @property {number} - Length of assets queue.
- * @default
- */
- this.queueSize = 0;
+ /**
+ * @property {XMLHttpRequest} - An XMLHttpRequest object used for loading text and audio data.
+ * @private
+ */
+ this._xhr = new XMLHttpRequest();
- /**
- * @property {boolean} isLoading - True if the Loader is in the process of loading the queue.
- * @default
- */
- this.isLoading = false;
+ /**
+ * @property {number} - Length of assets queue.
+ * @default
+ */
+ this.queueSize = 0;
- /**
- * @property {boolean} hasLoaded - True if all assets in the queue have finished loading.
- * @default
- */
- this.hasLoaded = false;
+ /**
+ * @property {boolean} isLoading - True if the Loader is in the process of loading the queue.
+ * @default
+ */
+ this.isLoading = false;
- /**
- * @property {number} progress - The Load progress percentage value (from 0 to 100)
- * @default
- */
- this.progress = 0;
+ /**
+ * @property {boolean} hasLoaded - True if all assets in the queue have finished loading.
+ * @default
+ */
+ this.hasLoaded = false;
- /**
- * 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.
- * @property {Description} preloadSprite
- * @default
- */
- this.preloadSprite = null;
+ /**
+ * @property {number} progress - The Load progress percentage value (from 0 to 100)
+ * @default
+ */
+ this.progress = 0;
- /**
- * @property {string} crossOrigin - The crossOrigin value applied to loaded images
- */
- this.crossOrigin = '';
+ /**
+ * 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.
+ * @property {Description} preloadSprite
+ * @default
+ */
+ this.preloadSprite = null;
- /**
- * If you want to append a URL before the path of any asset you can set this here.
- * Useful if you need to allow an asset url to be configured outside of the game code.
- * MUST have / on the end of it!
- * @property {string} baseURL
- * @default
- */
- this.baseURL = '';
+ /**
+ * @property {string} crossOrigin - The crossOrigin value applied to loaded images
+ */
+ this.crossOrigin = '';
- /**
- * @property {Phaser.Signal} onFileComplete - Event signal.
- */
- this.onFileComplete = new Phaser.Signal;
-
- /**
- * @property {Phaser.Signal} onFileError - Event signal.
- */
- this.onFileError = new Phaser.Signal;
-
- /**
- * @property {Phaser.Signal} onLoadStart - Event signal.
- */
- this.onLoadStart = new Phaser.Signal;
-
- /**
- * @property {Phaser.Signal} onLoadComplete - Event signal.
- */
- this.onLoadComplete = new Phaser.Signal;
+ /**
+ * If you want to append a URL before the path of any asset you can set this here.
+ * Useful if you need to allow an asset url to be configured outside of the game code.
+ * MUST have / on the end of it!
+ * @property {string} baseURL
+ * @default
+ */
+ this.baseURL = '';
+
+ /**
+ * @property {Phaser.Signal} onFileComplete - Event signal.
+ */
+ this.onFileComplete = new Phaser.Signal();
+
+ /**
+ * @property {Phaser.Signal} onFileError - Event signal.
+ */
+ this.onFileError = new Phaser.Signal();
+
+ /**
+ * @property {Phaser.Signal} onLoadStart - Event signal.
+ */
+ this.onLoadStart = new Phaser.Signal();
+
+ /**
+ * @property {Phaser.Signal} onLoadComplete - Event signal.
+ */
+ this.onLoadComplete = new Phaser.Signal();
};
@@ -134,985 +134,985 @@ Phaser.Loader.TEXTURE_ATLAS_XML_STARLING = 2;
Phaser.Loader.prototype = {
- /**
- * You can set a Sprite to be a "preload" sprite by passing it to this method.
- * A "preload" sprite will have its width or height crop adjusted based on the percentage of the loader in real-time.
- * This allows you to easily make loading bars for games.
- *
- * @method Phaser.Loader#setPreloadSprite
+ /**
+ * You can set a Sprite to be a "preload" sprite by passing it to this method.
+ * A "preload" sprite will have its width or height crop adjusted based on the percentage of the loader in real-time.
+ * This allows you to easily make loading bars for games.
+ *
+ * @method Phaser.Loader#setPreloadSprite
* @param {Phaser.Sprite} sprite - The sprite that will be cropped during the load.
* @param {number} [direction=0] - A value of zero means the sprite width will be cropped, a value of 1 means its height will be cropped.
*/
- setPreloadSprite: function (sprite, direction) {
-
- direction = direction || 0;
-
- this.preloadSprite = { sprite: sprite, direction: direction, width: sprite.width, height: sprite.height, crop: null };
-
- if (direction === 0)
- {
- // Horizontal crop
- this.preloadSprite.crop = new Phaser.Rectangle(0, 0, 1, sprite.height);
- }
- else
- {
- // Vertical crop
- this.preloadSprite.crop = new Phaser.Rectangle(0, 0, sprite.width, 1);
- }
-
- sprite.crop = this.preloadSprite.crop;
- sprite.cropEnabled = true;
-
- },
-
- /**
- * Check whether asset exists with a specific key.
- *
- * @method Phaser.Loader#checkKeyExists
- * @param {string} key - Key of the asset you want to check.
- * @return {boolean} Return true if exists, otherwise return false.
- */
- checkKeyExists: function (key) {
-
- if (this._fileList[key])
- {
- return true;
- }
- else
- {
- return false;
- }
-
- },
-
- /**
- * Reset loader, this will remove all loaded assets.
- *
- * @method Phaser.Loader#reset
- */
- reset: function () {
-
- this.preloadSprite = null;
- this.queueSize = 0;
- this.isLoading = false;
-
- },
-
- /**
- * Internal function that adds a new entry to the file list. Do not call directly.
- *
- * @method Phaser.Loader#addToFileList
- * @param {Description} type - Description.
- * @param {string} key - Description.
- * @param {string} url - URL of Description.
- * @param {Description} properties - Description.
- * @protected
- */
- addToFileList: function (type, key, url, properties) {
-
- var entry = {
- type: type,
- key: key,
- url: url,
- data: null,
- error: false,
- loaded: false
- };
-
- if (typeof properties !== "undefined")
- {
- for (var prop in properties)
- {
- entry[prop] = properties[prop];
- }
- }
-
- this._fileList[key] = entry;
-
- this._keys.push(key);
-
- this.queueSize++;
-
- },
-
- /**
- * Add an image to the Loader.
- *
- * @method Phaser.Loader#image
- * @param {string} key - Unique asset key of this image file.
- * @param {string} url - URL of image file.
- * @param {boolean} overwrite - If an entry with a matching key already exists this will over-write it
- */
- image: function (key, url, overwrite) {
-
- if (typeof overwrite === "undefined") { overwrite = false; }
-
- if (overwrite || this.checkKeyExists(key) === false)
- {
- this.addToFileList('image', key, url);
- }
-
- return this;
-
- },
-
- /**
- * Add a text file to the Loader.
- *
- * @method Phaser.Loader#text
- * @param {string} key - Unique asset key of the text file.
- * @param {string} url - URL of the text file.
- * @param {boolean} overwrite - True if Description.
- */
- text: function (key, url, overwrite) {
-
- if (typeof overwrite === "undefined") { overwrite = false; }
-
- if (overwrite || this.checkKeyExists(key) === false)
- {
- this.addToFileList('text', key, url);
- }
-
- return this;
-
- },
-
- /**
- * Add a new sprite sheet to the loader.
- *
- * @method Phaser.Loader#spritesheet
- * @param {string} key - Unique asset key of the sheet file.
- * @param {string} url - URL of the sheet file.
- * @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.
- */
- spritesheet: function (key, url, frameWidth, frameHeight, frameMax) {
-
- if (typeof frameMax === "undefined") { frameMax = -1; }
-
- if (this.checkKeyExists(key) === false)
- {
- 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.
- */
- 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; }
-
- if (this.checkKeyExists(key) === false)
- {
- this.addToFileList('tileset', key, url, { tileWidth: tileWidth, tileHeight: tileHeight, tileMax: tileMax, tileMargin: tileMargin, tileSpacing: tileSpacing });
- }
-
- return this;
-
- },
-
- /**
- * Add a new audio file to the loader.
- *
- * @method Phaser.Loader#audio
- * @param {string} key - Unique asset key of the audio file.
- * @param {Array|string} urls - An array containing the URLs of the audio files, i.e.: [ 'jump.mp3', 'jump.ogg', 'jump.m4a' ] or a single string containing just one URL.
- * @param {boolean} autoDecode - When using Web Audio the audio files can either be decoded at load time or run-time. They can't be played until they are decoded, but this let's you control when that happens. Decoding is a non-blocking async process.
- */
- audio: function (key, urls, autoDecode) {
-
- if (typeof autoDecode === "undefined") { autoDecode = true; }
-
- if (this.checkKeyExists(key) === false)
- {
- this.addToFileList('audio', key, urls, { buffer: null, autoDecode: autoDecode });
- }
-
- return this;
-
- },
-
- /**
- * Add a new tilemap loading request.
- *
- * @method Phaser.Loader#tilemap
- * @param {string} key - Unique asset key of the tilemap data.
- * @param {string} tilesetURL - The url of the tile set image file.
- * @param {string} [mapDataURL] - The url of the map data file (csv/json)
- * @param {object} [mapData] - An optional JSON data object (can be given in place of a URL).
- * @param {string} [format] - The format of the map data.
- */
- tilemap: function (key, mapDataURL, mapData, format) {
-
- if (typeof mapDataURL === "undefined") { mapDataURL = null; }
- if (typeof mapData === "undefined") { mapData = null; }
- if (typeof format === "undefined") { format = Phaser.Tilemap.CSV; }
-
- if (mapDataURL == null && mapData == null)
- {
- console.warn('Phaser.Loader.tilemap - Both mapDataURL and mapData are null. One must be set.');
-
- return this;
- }
-
- if (this.checkKeyExists(key) === false)
- {
- // A URL to a json/csv file has been given
- if (mapDataURL)
- {
- this.addToFileList('tilemap', key, mapDataURL, { format: format });
- }
- else
- {
- switch (format)
- {
- // A csv string or object has been given
- case Phaser.Tilemap.CSV:
- break;
-
- // An xml string or object has been given
- case Phaser.Tilemap.TILED_JSON:
-
- if (typeof mapData === 'string')
- {
- mapData = JSON.parse(mapData);
- }
- break;
- }
-
- this.game.cache.addTilemap(key, null, mapData, format);
-
- }
- }
-
- return this;
-
- },
-
- /**
- * Add a new bitmap font loading request.
- *
- * @method Phaser.Loader#bitmapFont
- * @param {string} key - Unique asset key of the bitmap font.
- * @param {string} textureURL - The url of the font image file.
- * @param {string} [xmlURL] - The url of the font data file (xml/fnt)
- * @param {object} [xmlData] - An optional XML data object.
- */
- bitmapFont: function (key, textureURL, xmlURL, xmlData) {
-
- if (typeof xmlURL === "undefined") { xmlURL = null; }
- if (typeof xmlData === "undefined") { xmlData = null; }
-
- if (this.checkKeyExists(key) === false)
- {
- // A URL to a json/xml file has been given
- if (xmlURL)
- {
- this.addToFileList('bitmapfont', key, textureURL, { xmlURL: xmlURL });
- }
- else
- {
- // An xml string or object has been given
- if (typeof xmlData === 'string')
- {
- var xml;
-
- try {
- if (window['DOMParser'])
- {
- var domparser = new DOMParser();
- xml = domparser.parseFromString(xmlData, "text/xml");
- }
- else
- {
- xml = new ActiveXObject("Microsoft.XMLDOM");
- xml.async = 'false';
- xml.loadXML(xmlData);
- }
- }
- catch (e)
- {
- xml = undefined;
- }
-
- if (!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length)
- {
- throw new Error("Phaser.Loader. Invalid Bitmap Font XML given");
- }
- else
- {
- this.addToFileList('bitmapfont', key, textureURL, { xmlURL: null, xmlData: xml });
- }
- }
- }
- }
-
- return this;
-
- },
-
- /**
- * Add a new texture atlas to the loader. This atlas uses the JSON Array data format.
- *
- * @method Phaser.Loader#atlasJSONArray
- * @param {string} key - Unique asset key of the bitmap font.
- * @param {Description} atlasURL - The url of the Description.
- * @param {Description} atlasData - Description.
- */
- atlasJSONArray: function (key, textureURL, atlasURL, atlasData) {
-
- return this.atlas(key, textureURL, atlasURL, atlasData, Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY);
-
- },
-
- /**
- * Add a new texture atlas to the loader. This atlas uses the JSON Hash data format.
- *
- * @method Phaser.Loader#atlasJSONHash
- * @param {string} key - Unique asset key of the bitmap font.
- * @param {Description} atlasURL - The url of the Description.
- * @param {Description} atlasData - Description.
- */
- atlasJSONHash: function (key, textureURL, atlasURL, atlasData) {
-
- return this.atlas(key, textureURL, atlasURL, atlasData, Phaser.Loader.TEXTURE_ATLAS_JSON_HASH);
-
- },
-
- /**
- * Add a new texture atlas to the loader. This atlas uses the Starling XML data format.
- *
- * @method Phaser.Loader#atlasXML
- * @param {string} key - Unique asset key of the bitmap font.
- * @param {Description} atlasURL - The url of the Description.
- * @param {Description} atlasData - Description.
- */
- atlasXML: function (key, textureURL, atlasURL, atlasData) {
-
- return this.atlas(key, textureURL, atlasURL, atlasData, Phaser.Loader.TEXTURE_ATLAS_XML_STARLING);
-
- },
-
- /**
- * Add a new texture atlas to the loader.
- *
- * @method Phaser.Loader#atlas
- * @param {string} key - Unique asset key of the texture atlas file.
- * @param {string} textureURL - The url of the texture atlas image file.
- * @param {string} [atlasURL] - The url of the texture atlas data file (json/xml). You don't need this if you are passing an atlasData object instead.
- * @param {object} [atlasData] - A JSON or XML data object. You don't need this if the data is being loaded from a URL.
- * @param {number} [format] - A value describing the format of the data, the default is Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY.
- */
- atlas: function (key, textureURL, atlasURL, atlasData, format) {
-
- if (typeof atlasURL === "undefined") { atlasURL = null; }
- if (typeof atlasData === "undefined") { atlasData = null; }
- if (typeof format === "undefined") { format = Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY; }
-
- if (this.checkKeyExists(key) === false)
- {
- // A URL to a json/xml file has been given
- if (atlasURL)
- {
- this.addToFileList('textureatlas', key, textureURL, { atlasURL: atlasURL, format: format });
- }
- else
- {
- switch (format)
- {
- // A json string or object has been given
- case Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY:
-
- if (typeof atlasData === 'string')
- {
- atlasData = JSON.parse(atlasData);
- }
- break;
-
- // An xml string or object has been given
- case Phaser.Loader.TEXTURE_ATLAS_XML_STARLING:
-
- if (typeof atlasData === 'string')
- {
- var xml;
-
- try {
- if (window['DOMParser'])
- {
- var domparser = new DOMParser();
- xml = domparser.parseFromString(atlasData, "text/xml");
- }
- else
- {
- xml = new ActiveXObject("Microsoft.XMLDOM");
- xml.async = 'false';
- xml.loadXML(atlasData);
- }
- }
- catch (e)
- {
- xml = undefined;
- }
-
- if (!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length)
- {
- throw new Error("Phaser.Loader. Invalid Texture Atlas XML given");
- }
- else
- {
- atlasData = xml;
- }
- }
- break;
- }
-
- this.addToFileList('textureatlas', key, textureURL, { atlasURL: null, atlasData: atlasData, format: format });
-
- }
-
- }
-
- return this;
-
- },
-
- /**
- * Remove loading request of a file.
- *
- * @method Phaser.Loader#removeFile
- * @param key {string} Key of the file you want to remove.
- */
- removeFile: function (key) {
-
- delete this._fileList[key];
-
- },
-
- /**
- * Remove all file loading requests.
- *
- * @method Phaser.Loader#removeAll
- */
- removeAll: function () {
-
- this._fileList = {};
-
- },
-
- /**
- * Start loading the assets. Normally you don't need to call this yourself as the StateManager will do so.
- *
- * @method Phaser.Loader#start
- */
- start: function () {
-
- if (this.isLoading)
- {
- return;
- }
-
- this.progress = 0;
- this.hasLoaded = false;
- this.isLoading = true;
-
- this.onLoadStart.dispatch(this.queueSize);
-
- if (this._keys.length > 0)
- {
- this._progressChunk = 100 / this._keys.length;
- this.loadFile();
- }
- else
- {
- this.progress = 100;
- this.hasLoaded = true;
- this.onLoadComplete.dispatch();
- }
-
- },
-
- /**
- * Load files. Private method ONLY used by loader.
- *
- * @method Phaser.Loader#loadFile
- * @private
- */
- loadFile: function () {
-
- var file = this._fileList[this._keys.shift()];
- var _this = this;
-
- // Image or Data?
- switch (file.type)
- {
- case 'image':
- case 'spritesheet':
- case 'textureatlas':
- case 'bitmapfont':
- case 'tileset':
- file.data = new Image();
- file.data.name = file.key;
- file.data.onload = function () {
- return _this.fileComplete(file.key);
- };
- file.data.onerror = function () {
- return _this.fileError(file.key);
- };
- file.data.crossOrigin = this.crossOrigin;
- file.data.src = this.baseURL + file.url;
- break;
-
- case 'audio':
- file.url = this.getAudioURL(file.url);
-
- if (file.url !== null)
- {
- // WebAudio or Audio Tag?
- if (this.game.sound.usingWebAudio)
- {
- this._xhr.open("GET", this.baseURL + file.url, true);
- this._xhr.responseType = "arraybuffer";
- this._xhr.onload = function () {
- return _this.fileComplete(file.key);
- };
- this._xhr.onerror = function () {
- return _this.fileError(file.key);
- };
- this._xhr.send();
- }
- else if (this.game.sound.usingAudioTag)
- {
- if (this.game.sound.touchLocked)
- {
- // If audio is locked we can't do this yet, so need to queue this load request. Bum.
- file.data = new Audio();
- file.data.name = file.key;
- file.data.preload = 'auto';
- file.data.src = this.baseURL + file.url;
- this.fileComplete(file.key);
- }
- else
- {
- file.data = new Audio();
- file.data.name = file.key;
- file.data.onerror = function () {
- return _this.fileError(file.key);
- };
- file.data.preload = 'auto';
- file.data.src = this.baseURL + file.url;
- file.data.addEventListener('canplaythrough', Phaser.GAMES[this.game.id].load.fileComplete(file.key), false);
- file.data.load();
- }
- }
- }
- else
- {
- this.fileError(file.key);
- }
-
- break;
-
- case 'tilemap':
- this._xhr.open("GET", this.baseURL + file.url, true);
- this._xhr.responseType = "text";
-
- if (file.format == Phaser.Tilemap.TILED_JSON)
- {
- this._xhr.onload = function () {
- return _this.jsonLoadComplete(file.key);
- };
- }
- else if (file.format == Phaser.Tilemap.CSV)
- {
- this._xhr.onload = function () {
- return _this.csvLoadComplete(file.key);
- };
- }
- else
- {
- throw new Error("Phaser.Loader. Invalid Tilemap format: " + file.format);
- }
-
- this._xhr.onerror = function () {
- return _this.dataLoadError(file.key);
- };
- this._xhr.send();
- break;
-
- case 'text':
- this._xhr.open("GET", this.baseURL + file.url, true);
- this._xhr.responseType = "text";
- this._xhr.onload = function () {
- return _this.fileComplete(file.key);
- };
- this._xhr.onerror = function () {
- return _this.fileError(file.key);
- };
- this._xhr.send();
- break;
- }
-
- },
-
- /**
- * Private method ONLY used by loader.
- * @method Phaser.Loader#getAudioURL
- * @param {array|string} urls - Either an array of audio file URLs or a string containing a single URL path.
- * @private
- */
- getAudioURL: function (urls) {
-
- var extension;
-
- if (typeof urls === 'string') { urls = [urls]; }
-
- for (var i = 0; i < urls.length; i++)
- {
- extension = urls[i].toLowerCase();
- extension = extension.substr((Math.max(0, extension.lastIndexOf(".")) || Infinity) + 1);
-
- if (this.game.device.canPlayAudio(extension))
- {
- return urls[i];
- }
-
- }
-
- return null;
-
- },
-
- /**
- * Error occured when load a file.
- *
- * @method Phaser.Loader#fileError
- * @param {string} key - Key of the error loading file.
- */
- fileError: function (key) {
-
- this._fileList[key].loaded = true;
- this._fileList[key].error = true;
-
- this.onFileError.dispatch(key);
-
- console.warn("Phaser.Loader error loading file: " + key + ' from URL ' + this._fileList[key].url);
-
- this.nextFile(key, false);
-
- },
-
- /**
- * Called when a file is successfully loaded.
- *
- * @method Phaser.Loader#fileComplete
- * @param {string} key - Key of the successfully loaded file.
- */
- fileComplete: function (key) {
-
- if (!this._fileList[key])
- {
- console.warn('Phaser.Loader fileComplete invalid key ' + key);
- return;
- }
-
- this._fileList[key].loaded = true;
-
- var file = this._fileList[key];
- var loadNext = true;
- var _this = this;
-
- switch (file.type)
- {
- case 'image':
-
- this.game.cache.addImage(file.key, file.url, file.data);
- break;
-
- 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);
- break;
-
- case 'textureatlas':
-
- if (file.atlasURL == null)
- {
- this.game.cache.addTextureAtlas(file.key, file.url, file.data, file.atlasData, file.format);
- }
- else
- {
- // Load the JSON or XML before carrying on with the next file
- loadNext = false;
- this._xhr.open("GET", this.baseURL + file.atlasURL, true);
- this._xhr.responseType = "text";
-
- if (file.format == Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY || file.format == Phaser.Loader.TEXTURE_ATLAS_JSON_HASH)
- {
- this._xhr.onload = function () {
- return _this.jsonLoadComplete(file.key);
- };
- }
- else if (file.format == Phaser.Loader.TEXTURE_ATLAS_XML_STARLING)
- {
- this._xhr.onload = function () {
- return _this.xmlLoadComplete(file.key);
- };
- }
- else
- {
- throw new Error("Phaser.Loader. Invalid Texture Atlas format: " + file.format);
- }
-
- this._xhr.onerror = function () {
- return _this.dataLoadError(file.key);
- };
- this._xhr.send();
- }
- break;
-
- case 'bitmapfont':
-
- if (file.xmlURL == null)
- {
- this.game.cache.addBitmapFont(file.key, file.url, file.data, file.xmlData);
- }
- else
- {
- // Load the XML before carrying on with the next file
- loadNext = false;
- this._xhr.open("GET", this.baseURL + file.xmlURL, true);
- this._xhr.responseType = "text";
-
- this._xhr.onload = function () {
- return _this.xmlLoadComplete(file.key);
- };
-
- this._xhr.onerror = function () {
- return _this.dataLoadError(file.key);
- };
- this._xhr.send();
- }
- break;
-
- case 'audio':
-
- if (this.game.sound.usingWebAudio)
- {
- file.data = this._xhr.response;
-
- this.game.cache.addSound(file.key, file.url, file.data, true, false);
-
- if (file.autoDecode)
- {
- this.game.cache.updateSound(key, 'isDecoding', true);
-
- var that = this;
- var key = file.key;
-
- this.game.sound.context.decodeAudioData(file.data, function (buffer) {
- if (buffer)
- {
- that.game.cache.decodedSound(key, buffer);
- }
- });
- }
- }
- else
- {
- file.data.removeEventListener('canplaythrough', Phaser.GAMES[this.game.id].load.fileComplete);
- this.game.cache.addSound(file.key, file.url, file.data, false, true);
- }
- break;
-
- case 'text':
- file.data = this._xhr.responseText;
- this.game.cache.addText(file.key, file.url, file.data);
- break;
- }
-
- if (loadNext)
- {
- this.nextFile(key, true);
- }
-
- },
-
- /**
- * Successfully loaded a JSON file.
- *
- * @method Phaser.Loader#jsonLoadComplete
- * @param {string} key - Key of the loaded JSON file.
- */
- jsonLoadComplete: function (key) {
-
- var data = JSON.parse(this._xhr.responseText);
- var file = this._fileList[key];
-
- if (file.type == 'tilemap')
- {
- this.game.cache.addTilemap(file.key, file.url, data, file.format);
- }
- else
- {
- this.game.cache.addTextureAtlas(file.key, file.url, file.data, data, file.format);
- }
-
- this.nextFile(key, true);
-
- },
-
- /**
- * Successfully loaded a CSV file.
- *
- * @method Phaser.Loader#csvLoadComplete
- * @param {string} key - Key of the loaded CSV file.
- */
- csvLoadComplete: function (key) {
-
- var data = this._xhr.responseText;
- var file = this._fileList[key];
-
- this.game.cache.addTilemap(file.key, file.url, data, file.format);
-
- this.nextFile(key, true);
-
- },
-
- /**
- * Error occured when load a JSON.
- *
- * @method Phaser.Loader#dataLoadError
- * @param {string} key - Key of the error loading JSON file.
- */
- dataLoadError: function (key) {
-
- var file = this._fileList[key];
-
- file.error = true;
-
- console.warn("Phaser.Loader dataLoadError: " + key);
-
- this.nextFile(key, true);
-
- },
-
- /**
- * Successfully loaded an XML file.
- *
- * @method Phaser.Loader#xmlLoadComplete
- * @param {string} key - Key of the loaded XML file.
- */
- xmlLoadComplete: function (key) {
-
- var data = this._xhr.responseText;
- var xml;
-
- try
- {
- if (window['DOMParser'])
- {
- var domparser = new DOMParser();
- xml = domparser.parseFromString(data, "text/xml");
- }
- else
- {
- xml = new ActiveXObject("Microsoft.XMLDOM");
- xml.async = 'false';
- xml.loadXML(data);
- }
- }
- catch (e)
- {
- xml = undefined;
- }
-
- if (!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length)
- {
- throw new Error("Phaser.Loader. Invalid XML given");
- }
-
- var file = this._fileList[key];
-
- if (file.type == 'bitmapfont')
- {
- this.game.cache.addBitmapFont(file.key, file.url, file.data, xml);
- }
- else if (file.type == 'textureatlas')
- {
- this.game.cache.addTextureAtlas(file.key, file.url, file.data, xml, file.format);
- }
-
- this.nextFile(key, true);
-
- },
-
- /**
- * Handle loading next file.
- *
- * @param previousKey {string} Key of previous loaded asset.
- * @param success {boolean} Whether the previous asset loaded successfully or not.
- * @private
- */
- nextFile: function (previousKey, success) {
-
- this.progress = Math.round(this.progress + this._progressChunk);
-
- if (this.progress > 100)
- {
- this.progress = 100;
- }
-
- if (this.preloadSprite !== null)
- {
- if (this.preloadSprite.direction === 0)
- {
- this.preloadSprite.crop.width = Math.floor((this.preloadSprite.width / 100) * this.progress);
- }
- else
- {
- this.preloadSprite.crop.height = Math.floor((this.preloadSprite.height / 100) * this.progress);
- }
-
- this.preloadSprite.sprite.crop = this.preloadSprite.crop;
- }
-
- this.onFileComplete.dispatch(this.progress, previousKey, success, this.queueSize - this._keys.length, this.queueSize);
-
- if (this._keys.length > 0)
- {
- this.loadFile();
- }
- else
- {
- this.hasLoaded = true;
- this.isLoading = false;
-
- this.removeAll();
-
- this.onLoadComplete.dispatch();
- }
-
- }
+ setPreloadSprite: function (sprite, direction) {
+
+ direction = direction || 0;
+
+ this.preloadSprite = { sprite: sprite, direction: direction, width: sprite.width, height: sprite.height, crop: null };
+
+ if (direction === 0)
+ {
+ // Horizontal crop
+ this.preloadSprite.crop = new Phaser.Rectangle(0, 0, 1, sprite.height);
+ }
+ else
+ {
+ // Vertical crop
+ this.preloadSprite.crop = new Phaser.Rectangle(0, 0, sprite.width, 1);
+ }
+
+ sprite.crop = this.preloadSprite.crop;
+ sprite.cropEnabled = true;
+
+ },
+
+ /**
+ * Check whether asset exists with a specific key.
+ *
+ * @method Phaser.Loader#checkKeyExists
+ * @param {string} key - Key of the asset you want to check.
+ * @return {boolean} Return true if exists, otherwise return false.
+ */
+ checkKeyExists: function (key) {
+
+ if (this._fileList[key])
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+
+ },
+
+ /**
+ * Reset loader, this will remove all loaded assets.
+ *
+ * @method Phaser.Loader#reset
+ */
+ reset: function () {
+
+ this.preloadSprite = null;
+ this.queueSize = 0;
+ this.isLoading = false;
+
+ },
+
+ /**
+ * Internal function that adds a new entry to the file list. Do not call directly.
+ *
+ * @method Phaser.Loader#addToFileList
+ * @param {Description} type - Description.
+ * @param {string} key - Description.
+ * @param {string} url - URL of Description.
+ * @param {Description} properties - Description.
+ * @protected
+ */
+ addToFileList: function (type, key, url, properties) {
+
+ var entry = {
+ type: type,
+ key: key,
+ url: url,
+ data: null,
+ error: false,
+ loaded: false
+ };
+
+ if (typeof properties !== "undefined")
+ {
+ for (var prop in properties)
+ {
+ entry[prop] = properties[prop];
+ }
+ }
+
+ this._fileList[key] = entry;
+
+ this._keys.push(key);
+
+ this.queueSize++;
+
+ },
+
+ /**
+ * Add an image to the Loader.
+ *
+ * @method Phaser.Loader#image
+ * @param {string} key - Unique asset key of this image file.
+ * @param {string} url - URL of image file.
+ * @param {boolean} overwrite - If an entry with a matching key already exists this will over-write it
+ */
+ image: function (key, url, overwrite) {
+
+ if (typeof overwrite === "undefined") { overwrite = false; }
+
+ if (overwrite || this.checkKeyExists(key) === false)
+ {
+ this.addToFileList('image', key, url);
+ }
+
+ return this;
+
+ },
+
+ /**
+ * Add a text file to the Loader.
+ *
+ * @method Phaser.Loader#text
+ * @param {string} key - Unique asset key of the text file.
+ * @param {string} url - URL of the text file.
+ * @param {boolean} overwrite - True if Description.
+ */
+ text: function (key, url, overwrite) {
+
+ if (typeof overwrite === "undefined") { overwrite = false; }
+
+ if (overwrite || this.checkKeyExists(key) === false)
+ {
+ this.addToFileList('text', key, url);
+ }
+
+ return this;
+
+ },
+
+ /**
+ * Add a new sprite sheet to the loader.
+ *
+ * @method Phaser.Loader#spritesheet
+ * @param {string} key - Unique asset key of the sheet file.
+ * @param {string} url - URL of the sheet file.
+ * @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.
+ */
+ spritesheet: function (key, url, frameWidth, frameHeight, frameMax) {
+
+ if (typeof frameMax === "undefined") { frameMax = -1; }
+
+ if (this.checkKeyExists(key) === false)
+ {
+ 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.
+ */
+ 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; }
+
+ if (this.checkKeyExists(key) === false)
+ {
+ this.addToFileList('tileset', key, url, { tileWidth: tileWidth, tileHeight: tileHeight, tileMax: tileMax, tileMargin: tileMargin, tileSpacing: tileSpacing });
+ }
+
+ return this;
+
+ },
+
+ /**
+ * Add a new audio file to the loader.
+ *
+ * @method Phaser.Loader#audio
+ * @param {string} key - Unique asset key of the audio file.
+ * @param {Array|string} urls - An array containing the URLs of the audio files, i.e.: [ 'jump.mp3', 'jump.ogg', 'jump.m4a' ] or a single string containing just one URL.
+ * @param {boolean} autoDecode - When using Web Audio the audio files can either be decoded at load time or run-time. They can't be played until they are decoded, but this let's you control when that happens. Decoding is a non-blocking async process.
+ */
+ audio: function (key, urls, autoDecode) {
+
+ if (typeof autoDecode === "undefined") { autoDecode = true; }
+
+ if (this.checkKeyExists(key) === false)
+ {
+ this.addToFileList('audio', key, urls, { buffer: null, autoDecode: autoDecode });
+ }
+
+ return this;
+
+ },
+
+ /**
+ * Add a new tilemap loading request.
+ *
+ * @method Phaser.Loader#tilemap
+ * @param {string} key - Unique asset key of the tilemap data.
+ * @param {string} tilesetURL - The url of the tile set image file.
+ * @param {string} [mapDataURL] - The url of the map data file (csv/json)
+ * @param {object} [mapData] - An optional JSON data object (can be given in place of a URL).
+ * @param {string} [format] - The format of the map data.
+ */
+ tilemap: function (key, mapDataURL, mapData, format) {
+
+ if (typeof mapDataURL === "undefined") { mapDataURL = null; }
+ if (typeof mapData === "undefined") { mapData = null; }
+ if (typeof format === "undefined") { format = Phaser.Tilemap.CSV; }
+
+ if (mapDataURL == null && mapData == null)
+ {
+ console.warn('Phaser.Loader.tilemap - Both mapDataURL and mapData are null. One must be set.');
+
+ return this;
+ }
+
+ if (this.checkKeyExists(key) === false)
+ {
+ // A URL to a json/csv file has been given
+ if (mapDataURL)
+ {
+ this.addToFileList('tilemap', key, mapDataURL, { format: format });
+ }
+ else
+ {
+ switch (format)
+ {
+ // A csv string or object has been given
+ case Phaser.Tilemap.CSV:
+ break;
+
+ // An xml string or object has been given
+ case Phaser.Tilemap.TILED_JSON:
+
+ if (typeof mapData === 'string')
+ {
+ mapData = JSON.parse(mapData);
+ }
+ break;
+ }
+
+ this.game.cache.addTilemap(key, null, mapData, format);
+
+ }
+ }
+
+ return this;
+
+ },
+
+ /**
+ * Add a new bitmap font loading request.
+ *
+ * @method Phaser.Loader#bitmapFont
+ * @param {string} key - Unique asset key of the bitmap font.
+ * @param {string} textureURL - The url of the font image file.
+ * @param {string} [xmlURL] - The url of the font data file (xml/fnt)
+ * @param {object} [xmlData] - An optional XML data object.
+ */
+ bitmapFont: function (key, textureURL, xmlURL, xmlData) {
+
+ if (typeof xmlURL === "undefined") { xmlURL = null; }
+ if (typeof xmlData === "undefined") { xmlData = null; }
+
+ if (this.checkKeyExists(key) === false)
+ {
+ // A URL to a json/xml file has been given
+ if (xmlURL)
+ {
+ this.addToFileList('bitmapfont', key, textureURL, { xmlURL: xmlURL });
+ }
+ else
+ {
+ // An xml string or object has been given
+ if (typeof xmlData === 'string')
+ {
+ var xml;
+
+ try {
+ if (window['DOMParser'])
+ {
+ var domparser = new DOMParser();
+ xml = domparser.parseFromString(xmlData, "text/xml");
+ }
+ else
+ {
+ xml = new ActiveXObject("Microsoft.XMLDOM");
+ xml.async = 'false';
+ xml.loadXML(xmlData);
+ }
+ }
+ catch (e)
+ {
+ xml = undefined;
+ }
+
+ if (!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length)
+ {
+ throw new Error("Phaser.Loader. Invalid Bitmap Font XML given");
+ }
+ else
+ {
+ this.addToFileList('bitmapfont', key, textureURL, { xmlURL: null, xmlData: xml });
+ }
+ }
+ }
+ }
+
+ return this;
+
+ },
+
+ /**
+ * Add a new texture atlas to the loader. This atlas uses the JSON Array data format.
+ *
+ * @method Phaser.Loader#atlasJSONArray
+ * @param {string} key - Unique asset key of the bitmap font.
+ * @param {Description} atlasURL - The url of the Description.
+ * @param {Description} atlasData - Description.
+ */
+ atlasJSONArray: function (key, textureURL, atlasURL, atlasData) {
+
+ return this.atlas(key, textureURL, atlasURL, atlasData, Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY);
+
+ },
+
+ /**
+ * Add a new texture atlas to the loader. This atlas uses the JSON Hash data format.
+ *
+ * @method Phaser.Loader#atlasJSONHash
+ * @param {string} key - Unique asset key of the bitmap font.
+ * @param {Description} atlasURL - The url of the Description.
+ * @param {Description} atlasData - Description.
+ */
+ atlasJSONHash: function (key, textureURL, atlasURL, atlasData) {
+
+ return this.atlas(key, textureURL, atlasURL, atlasData, Phaser.Loader.TEXTURE_ATLAS_JSON_HASH);
+
+ },
+
+ /**
+ * Add a new texture atlas to the loader. This atlas uses the Starling XML data format.
+ *
+ * @method Phaser.Loader#atlasXML
+ * @param {string} key - Unique asset key of the bitmap font.
+ * @param {Description} atlasURL - The url of the Description.
+ * @param {Description} atlasData - Description.
+ */
+ atlasXML: function (key, textureURL, atlasURL, atlasData) {
+
+ return this.atlas(key, textureURL, atlasURL, atlasData, Phaser.Loader.TEXTURE_ATLAS_XML_STARLING);
+
+ },
+
+ /**
+ * Add a new texture atlas to the loader.
+ *
+ * @method Phaser.Loader#atlas
+ * @param {string} key - Unique asset key of the texture atlas file.
+ * @param {string} textureURL - The url of the texture atlas image file.
+ * @param {string} [atlasURL] - The url of the texture atlas data file (json/xml). You don't need this if you are passing an atlasData object instead.
+ * @param {object} [atlasData] - A JSON or XML data object. You don't need this if the data is being loaded from a URL.
+ * @param {number} [format] - A value describing the format of the data, the default is Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY.
+ */
+ atlas: function (key, textureURL, atlasURL, atlasData, format) {
+
+ if (typeof atlasURL === "undefined") { atlasURL = null; }
+ if (typeof atlasData === "undefined") { atlasData = null; }
+ if (typeof format === "undefined") { format = Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY; }
+
+ if (this.checkKeyExists(key) === false)
+ {
+ // A URL to a json/xml file has been given
+ if (atlasURL)
+ {
+ this.addToFileList('textureatlas', key, textureURL, { atlasURL: atlasURL, format: format });
+ }
+ else
+ {
+ switch (format)
+ {
+ // A json string or object has been given
+ case Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY:
+
+ if (typeof atlasData === 'string')
+ {
+ atlasData = JSON.parse(atlasData);
+ }
+ break;
+
+ // An xml string or object has been given
+ case Phaser.Loader.TEXTURE_ATLAS_XML_STARLING:
+
+ if (typeof atlasData === 'string')
+ {
+ var xml;
+
+ try {
+ if (window['DOMParser'])
+ {
+ var domparser = new DOMParser();
+ xml = domparser.parseFromString(atlasData, "text/xml");
+ }
+ else
+ {
+ xml = new ActiveXObject("Microsoft.XMLDOM");
+ xml.async = 'false';
+ xml.loadXML(atlasData);
+ }
+ }
+ catch (e)
+ {
+ xml = undefined;
+ }
+
+ if (!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length)
+ {
+ throw new Error("Phaser.Loader. Invalid Texture Atlas XML given");
+ }
+ else
+ {
+ atlasData = xml;
+ }
+ }
+ break;
+ }
+
+ this.addToFileList('textureatlas', key, textureURL, { atlasURL: null, atlasData: atlasData, format: format });
+
+ }
+
+ }
+
+ return this;
+
+ },
+
+ /**
+ * Remove loading request of a file.
+ *
+ * @method Phaser.Loader#removeFile
+ * @param key {string} Key of the file you want to remove.
+ */
+ removeFile: function (key) {
+
+ delete this._fileList[key];
+
+ },
+
+ /**
+ * Remove all file loading requests.
+ *
+ * @method Phaser.Loader#removeAll
+ */
+ removeAll: function () {
+
+ this._fileList = {};
+
+ },
+
+ /**
+ * Start loading the assets. Normally you don't need to call this yourself as the StateManager will do so.
+ *
+ * @method Phaser.Loader#start
+ */
+ start: function () {
+
+ if (this.isLoading)
+ {
+ return;
+ }
+
+ this.progress = 0;
+ this.hasLoaded = false;
+ this.isLoading = true;
+
+ this.onLoadStart.dispatch(this.queueSize);
+
+ if (this._keys.length > 0)
+ {
+ this._progressChunk = 100 / this._keys.length;
+ this.loadFile();
+ }
+ else
+ {
+ this.progress = 100;
+ this.hasLoaded = true;
+ this.onLoadComplete.dispatch();
+ }
+
+ },
+
+ /**
+ * Load files. Private method ONLY used by loader.
+ *
+ * @method Phaser.Loader#loadFile
+ * @private
+ */
+ loadFile: function () {
+
+ var file = this._fileList[this._keys.shift()];
+ var _this = this;
+
+ // Image or Data?
+ switch (file.type)
+ {
+ case 'image':
+ case 'spritesheet':
+ case 'textureatlas':
+ case 'bitmapfont':
+ case 'tileset':
+ file.data = new Image();
+ file.data.name = file.key;
+ file.data.onload = function () {
+ return _this.fileComplete(file.key);
+ };
+ file.data.onerror = function () {
+ return _this.fileError(file.key);
+ };
+ file.data.crossOrigin = this.crossOrigin;
+ file.data.src = this.baseURL + file.url;
+ break;
+
+ case 'audio':
+ file.url = this.getAudioURL(file.url);
+
+ if (file.url !== null)
+ {
+ // WebAudio or Audio Tag?
+ if (this.game.sound.usingWebAudio)
+ {
+ this._xhr.open("GET", this.baseURL + file.url, true);
+ this._xhr.responseType = "arraybuffer";
+ this._xhr.onload = function () {
+ return _this.fileComplete(file.key);
+ };
+ this._xhr.onerror = function () {
+ return _this.fileError(file.key);
+ };
+ this._xhr.send();
+ }
+ else if (this.game.sound.usingAudioTag)
+ {
+ if (this.game.sound.touchLocked)
+ {
+ // If audio is locked we can't do this yet, so need to queue this load request. Bum.
+ file.data = new Audio();
+ file.data.name = file.key;
+ file.data.preload = 'auto';
+ file.data.src = this.baseURL + file.url;
+ this.fileComplete(file.key);
+ }
+ else
+ {
+ file.data = new Audio();
+ file.data.name = file.key;
+ file.data.onerror = function () {
+ return _this.fileError(file.key);
+ };
+ file.data.preload = 'auto';
+ file.data.src = this.baseURL + file.url;
+ file.data.addEventListener('canplaythrough', Phaser.GAMES[this.game.id].load.fileComplete(file.key), false);
+ file.data.load();
+ }
+ }
+ }
+ else
+ {
+ this.fileError(file.key);
+ }
+
+ break;
+
+ case 'tilemap':
+ this._xhr.open("GET", this.baseURL + file.url, true);
+ this._xhr.responseType = "text";
+
+ if (file.format == Phaser.Tilemap.TILED_JSON)
+ {
+ this._xhr.onload = function () {
+ return _this.jsonLoadComplete(file.key);
+ };
+ }
+ else if (file.format == Phaser.Tilemap.CSV)
+ {
+ this._xhr.onload = function () {
+ return _this.csvLoadComplete(file.key);
+ };
+ }
+ else
+ {
+ throw new Error("Phaser.Loader. Invalid Tilemap format: " + file.format);
+ }
+
+ this._xhr.onerror = function () {
+ return _this.dataLoadError(file.key);
+ };
+ this._xhr.send();
+ break;
+
+ case 'text':
+ this._xhr.open("GET", this.baseURL + file.url, true);
+ this._xhr.responseType = "text";
+ this._xhr.onload = function () {
+ return _this.fileComplete(file.key);
+ };
+ this._xhr.onerror = function () {
+ return _this.fileError(file.key);
+ };
+ this._xhr.send();
+ break;
+ }
+
+ },
+
+ /**
+ * Private method ONLY used by loader.
+ * @method Phaser.Loader#getAudioURL
+ * @param {array|string} urls - Either an array of audio file URLs or a string containing a single URL path.
+ * @private
+ */
+ getAudioURL: function (urls) {
+
+ var extension;
+
+ if (typeof urls === 'string') { urls = [urls]; }
+
+ for (var i = 0; i < urls.length; i++)
+ {
+ extension = urls[i].toLowerCase();
+ extension = extension.substr((Math.max(0, extension.lastIndexOf(".")) || Infinity) + 1);
+
+ if (this.game.device.canPlayAudio(extension))
+ {
+ return urls[i];
+ }
+
+ }
+
+ return null;
+
+ },
+
+ /**
+ * Error occured when load a file.
+ *
+ * @method Phaser.Loader#fileError
+ * @param {string} key - Key of the error loading file.
+ */
+ fileError: function (key) {
+
+ this._fileList[key].loaded = true;
+ this._fileList[key].error = true;
+
+ this.onFileError.dispatch(key);
+
+ console.warn("Phaser.Loader error loading file: " + key + ' from URL ' + this._fileList[key].url);
+
+ this.nextFile(key, false);
+
+ },
+
+ /**
+ * Called when a file is successfully loaded.
+ *
+ * @method Phaser.Loader#fileComplete
+ * @param {string} key - Key of the successfully loaded file.
+ */
+ fileComplete: function (key) {
+
+ if (!this._fileList[key])
+ {
+ console.warn('Phaser.Loader fileComplete invalid key ' + key);
+ return;
+ }
+
+ this._fileList[key].loaded = true;
+
+ var file = this._fileList[key];
+ var loadNext = true;
+ var _this = this;
+
+ switch (file.type)
+ {
+ case 'image':
+
+ this.game.cache.addImage(file.key, file.url, file.data);
+ break;
+
+ 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);
+ break;
+
+ case 'textureatlas':
+
+ if (file.atlasURL == null)
+ {
+ this.game.cache.addTextureAtlas(file.key, file.url, file.data, file.atlasData, file.format);
+ }
+ else
+ {
+ // Load the JSON or XML before carrying on with the next file
+ loadNext = false;
+ this._xhr.open("GET", this.baseURL + file.atlasURL, true);
+ this._xhr.responseType = "text";
+
+ if (file.format == Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY || file.format == Phaser.Loader.TEXTURE_ATLAS_JSON_HASH)
+ {
+ this._xhr.onload = function () {
+ return _this.jsonLoadComplete(file.key);
+ };
+ }
+ else if (file.format == Phaser.Loader.TEXTURE_ATLAS_XML_STARLING)
+ {
+ this._xhr.onload = function () {
+ return _this.xmlLoadComplete(file.key);
+ };
+ }
+ else
+ {
+ throw new Error("Phaser.Loader. Invalid Texture Atlas format: " + file.format);
+ }
+
+ this._xhr.onerror = function () {
+ return _this.dataLoadError(file.key);
+ };
+ this._xhr.send();
+ }
+ break;
+
+ case 'bitmapfont':
+
+ if (file.xmlURL == null)
+ {
+ this.game.cache.addBitmapFont(file.key, file.url, file.data, file.xmlData);
+ }
+ else
+ {
+ // Load the XML before carrying on with the next file
+ loadNext = false;
+ this._xhr.open("GET", this.baseURL + file.xmlURL, true);
+ this._xhr.responseType = "text";
+
+ this._xhr.onload = function () {
+ return _this.xmlLoadComplete(file.key);
+ };
+
+ this._xhr.onerror = function () {
+ return _this.dataLoadError(file.key);
+ };
+ this._xhr.send();
+ }
+ break;
+
+ case 'audio':
+
+ if (this.game.sound.usingWebAudio)
+ {
+ file.data = this._xhr.response;
+
+ this.game.cache.addSound(file.key, file.url, file.data, true, false);
+
+ if (file.autoDecode)
+ {
+ this.game.cache.updateSound(key, 'isDecoding', true);
+
+ var that = this;
+ var key = file.key;
+
+ this.game.sound.context.decodeAudioData(file.data, function (buffer) {
+ if (buffer)
+ {
+ that.game.cache.decodedSound(key, buffer);
+ }
+ });
+ }
+ }
+ else
+ {
+ file.data.removeEventListener('canplaythrough', Phaser.GAMES[this.game.id].load.fileComplete);
+ this.game.cache.addSound(file.key, file.url, file.data, false, true);
+ }
+ break;
+
+ case 'text':
+ file.data = this._xhr.responseText;
+ this.game.cache.addText(file.key, file.url, file.data);
+ break;
+ }
+
+ if (loadNext)
+ {
+ this.nextFile(key, true);
+ }
+
+ },
+
+ /**
+ * Successfully loaded a JSON file.
+ *
+ * @method Phaser.Loader#jsonLoadComplete
+ * @param {string} key - Key of the loaded JSON file.
+ */
+ jsonLoadComplete: function (key) {
+
+ var data = JSON.parse(this._xhr.responseText);
+ var file = this._fileList[key];
+
+ if (file.type == 'tilemap')
+ {
+ this.game.cache.addTilemap(file.key, file.url, data, file.format);
+ }
+ else
+ {
+ this.game.cache.addTextureAtlas(file.key, file.url, file.data, data, file.format);
+ }
+
+ this.nextFile(key, true);
+
+ },
+
+ /**
+ * Successfully loaded a CSV file.
+ *
+ * @method Phaser.Loader#csvLoadComplete
+ * @param {string} key - Key of the loaded CSV file.
+ */
+ csvLoadComplete: function (key) {
+
+ var data = this._xhr.responseText;
+ var file = this._fileList[key];
+
+ this.game.cache.addTilemap(file.key, file.url, data, file.format);
+
+ this.nextFile(key, true);
+
+ },
+
+ /**
+ * Error occured when load a JSON.
+ *
+ * @method Phaser.Loader#dataLoadError
+ * @param {string} key - Key of the error loading JSON file.
+ */
+ dataLoadError: function (key) {
+
+ var file = this._fileList[key];
+
+ file.error = true;
+
+ console.warn("Phaser.Loader dataLoadError: " + key);
+
+ this.nextFile(key, true);
+
+ },
+
+ /**
+ * Successfully loaded an XML file.
+ *
+ * @method Phaser.Loader#xmlLoadComplete
+ * @param {string} key - Key of the loaded XML file.
+ */
+ xmlLoadComplete: function (key) {
+
+ var data = this._xhr.responseText;
+ var xml;
+
+ try
+ {
+ if (window['DOMParser'])
+ {
+ var domparser = new DOMParser();
+ xml = domparser.parseFromString(data, "text/xml");
+ }
+ else
+ {
+ xml = new ActiveXObject("Microsoft.XMLDOM");
+ xml.async = 'false';
+ xml.loadXML(data);
+ }
+ }
+ catch (e)
+ {
+ xml = undefined;
+ }
+
+ if (!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length)
+ {
+ throw new Error("Phaser.Loader. Invalid XML given");
+ }
+
+ var file = this._fileList[key];
+
+ if (file.type == 'bitmapfont')
+ {
+ this.game.cache.addBitmapFont(file.key, file.url, file.data, xml);
+ }
+ else if (file.type == 'textureatlas')
+ {
+ this.game.cache.addTextureAtlas(file.key, file.url, file.data, xml, file.format);
+ }
+
+ this.nextFile(key, true);
+
+ },
+
+ /**
+ * Handle loading next file.
+ *
+ * @param previousKey {string} Key of previous loaded asset.
+ * @param success {boolean} Whether the previous asset loaded successfully or not.
+ * @private
+ */
+ nextFile: function (previousKey, success) {
+
+ this.progress = Math.round(this.progress + this._progressChunk);
+
+ if (this.progress > 100)
+ {
+ this.progress = 100;
+ }
+
+ if (this.preloadSprite !== null)
+ {
+ if (this.preloadSprite.direction === 0)
+ {
+ this.preloadSprite.crop.width = Math.floor((this.preloadSprite.width / 100) * this.progress);
+ }
+ else
+ {
+ this.preloadSprite.crop.height = Math.floor((this.preloadSprite.height / 100) * this.progress);
+ }
+
+ this.preloadSprite.sprite.crop = this.preloadSprite.crop;
+ }
+
+ this.onFileComplete.dispatch(this.progress, previousKey, success, this.queueSize - this._keys.length, this.queueSize);
+
+ if (this._keys.length > 0)
+ {
+ this.loadFile();
+ }
+ else
+ {
+ this.hasLoaded = true;
+ this.isLoading = false;
+
+ this.removeAll();
+
+ this.onLoadComplete.dispatch();
+ }
+
+ }
};
diff --git a/src/loader/LoaderParser.js b/src/loader/LoaderParser.js
index 3cae9348..0f91830c 100644
--- a/src/loader/LoaderParser.js
+++ b/src/loader/LoaderParser.js
@@ -10,14 +10,14 @@
* @class Phaser.LoaderParser
*/
Phaser.LoaderParser = {
-
+
/**
* Parse frame data from an XML file.
* @method Phaser.LoaderParser.bitmapFont
* @param {object} xml - XML data you want to parse.
* @return {FrameData} Generated FrameData object.
*/
- bitmapFont: function (game, xml, cacheKey) {
+ bitmapFont: function (game, xml, cacheKey) {
// Malformed?
if (!xml.getElementsByTagName('font'))
@@ -50,8 +50,8 @@ Phaser.LoaderParser = {
height: parseInt(letters[i].attributes.getNamedItem("height").nodeValue, 10)
};
- // Note: This means you can only have 1 BitmapFont loaded at once!
- // Need to replace this with our own handler soon.
+ // Note: This means you can only have 1 BitmapFont loaded at once!
+ // Need to replace this with our own handler soon.
PIXI.TextureCache[charCode] = new PIXI.Texture(texture, textureRect);
data.chars[charCode] = {
@@ -69,9 +69,9 @@ Phaser.LoaderParser = {
for (i = 0; i < kernings.length; i++)
{
- var first = parseInt(kernings[i].attributes.getNamedItem("first").nodeValue, 10);
- var second = parseInt(kernings[i].attributes.getNamedItem("second").nodeValue, 10);
- var amount = parseInt(kernings[i].attributes.getNamedItem("amount").nodeValue, 10);
+ var first = parseInt(kernings[i].attributes.getNamedItem("first").nodeValue, 10);
+ var second = parseInt(kernings[i].attributes.getNamedItem("second").nodeValue, 10);
+ var amount = parseInt(kernings[i].attributes.getNamedItem("amount").nodeValue, 10);
data.chars[second].kerning[first] = amount;
}
diff --git a/src/math/Math.js b/src/math/Math.js
index 13962e74..c0344090 100644
--- a/src/math/Math.js
+++ b/src/math/Math.js
@@ -11,78 +11,78 @@
*/
Phaser.Math = {
- /**
- * = 2 π
- * @method Phaser.Math#PI2
- */
- PI2: Math.PI * 2,
+ /**
+ * = 2 π
+ * @method Phaser.Math#PI2
+ */
+ PI2: Math.PI * 2,
- /**
- * Two number are fuzzyEqual if their difference is less than ε.
- * @method Phaser.Math#fuzzyEqual
- * @param {number} a
- * @param {number} b
- * @param {number} epsilon
- * @return {boolean} True if |a-b|<ε
- */
+ /**
+ * Two number are fuzzyEqual if their difference is less than ε.
+ * @method Phaser.Math#fuzzyEqual
+ * @param {number} a
+ * @param {number} b
+ * @param {number} epsilon
+ * @return {boolean} True if |a-b|<ε
+ */
fuzzyEqual: function (a, b, epsilon) {
if (typeof epsilon === "undefined") { epsilon = 0.0001; }
return Math.abs(a - b) < epsilon;
},
- /**
- * a is fuzzyLessThan b if it is less than b + ε.
- * @method Phaser.Math#fuzzyEqual
- * @param {number} a
- * @param {number} b
- * @param {number} epsilon
- * @return {boolean} True if ab+ε
- */
+ /**
+ * a is fuzzyGreaterThan b if it is more than b - ε.
+ * @method Phaser.Math#fuzzyGreaterThan
+ * @param {number} a
+ * @param {number} b
+ * @param {number} epsilon
+ * @return {boolean} True if a>b+ε
+ */
fuzzyGreaterThan: function (a, b, epsilon) {
if (typeof epsilon === "undefined") { epsilon = 0.0001; }
return a > b - epsilon;
},
- /**
- * @method Phaser.Math#fuzzyCeil
- * @param {number} val
- * @param {number} epsilon
- * @return {boolean} ceiling(val-ε)
- */
+ /**
+ * @method Phaser.Math#fuzzyCeil
+ * @param {number} val
+ * @param {number} epsilon
+ * @return {boolean} ceiling(val-ε)
+ */
fuzzyCeil: function (val, epsilon) {
if (typeof epsilon === "undefined") { epsilon = 0.0001; }
return Math.ceil(val - epsilon);
},
- /**
- * @method Phaser.Math#fuzzyFloor
- * @param {number} val
- * @param {number} epsilon
- * @return {boolean} floor(val-ε)
- */
+ /**
+ * @method Phaser.Math#fuzzyFloor
+ * @param {number} val
+ * @param {number} epsilon
+ * @return {boolean} floor(val-ε)
+ */
fuzzyFloor: function (val, epsilon) {
if (typeof epsilon === "undefined") { epsilon = 0.0001; }
return Math.floor(val + epsilon);
},
- /**
+ /**
* Averages all values passed to the function and returns the result. You can pass as many parameters as you like.
- * @method Phaser.Math#average
+ * @method Phaser.Math#average
* @return {number} The average of all given values.
- */
+ */
average: function () {
var args = [];
@@ -101,35 +101,35 @@ Phaser.Math = {
},
- /**
- * @method Phaser.Math#truncate
+ /**
+ * @method Phaser.Math#truncate
* @param {number} n
* @return {number}
- */
+ */
truncate: function (n) {
return (n > 0) ? Math.floor(n) : Math.ceil(n);
},
- /**
- * @method Phaser.Math#shear
- * @param {number} n
- * @return {number} n mod 1
- */
+ /**
+ * @method Phaser.Math#shear
+ * @param {number} n
+ * @return {number} n mod 1
+ */
shear: function (n) {
return n % 1;
},
- /**
- * Snap a value to nearest grid slice, using rounding.
- *
- * Example: if you have an interval gap of 5 and a position of 12... you will snap to 10 whereas 14 will snap to 15.
- *
- * @method Phaser.Math#snapTo
- * @param {number} input - The value to snap.
- * @param {number} gap - The interval gap of the grid.
- * @param {number} [start] - Optional starting offset for gap.
+ /**
+ * Snap a value to nearest grid slice, using rounding.
+ *
+ * Example: if you have an interval gap of 5 and a position of 12... you will snap to 10 whereas 14 will snap to 15.
+ *
+ * @method Phaser.Math#snapTo
+ * @param {number} input - The value to snap.
+ * @param {number} gap - The interval gap of the grid.
+ * @param {number} [start] - Optional starting offset for gap.
* @return {number}
- */
+ */
snapTo: function (input, gap, start) {
if (typeof start === "undefined") { start = 0; }
@@ -145,7 +145,7 @@ Phaser.Math = {
},
- /**
+ /**
* Snap a value to nearest grid slice, using floor.
*
* Example: if you have an interval gap of 5 and a position of 12... you will snap to 10. As will 14 snap to 10... but 16 will snap to 15
@@ -171,17 +171,17 @@ Phaser.Math = {
},
- /**
- * Snap a value to nearest grid slice, using ceil.
- *
- * Example: if you have an interval gap of 5 and a position of 12... you will snap to 15. As will 14 will snap to 15... but 16 will snap to 20.
- *
+ /**
+ * Snap a value to nearest grid slice, using ceil.
+ *
+ * Example: if you have an interval gap of 5 and a position of 12... you will snap to 15. As will 14 will snap to 15... but 16 will snap to 20.
+ *
* @method Phaser.Math#snapToCeil
* @param {number} input - The value to snap.
* @param {number} gap - The interval gap of the grid.
* @param {number} [start] - Optional starting offset for gap.
* @return {number}
- */
+ */
snapToCeil: function (input, gap, start) {
if (typeof start === "undefined") { start = 0; }
@@ -198,14 +198,14 @@ Phaser.Math = {
},
- /**
- * Snaps a value to the nearest value in an array.
- * @method Phaser.Math#snapToInArray
- * @param {number} input
- * @param {array} arr
- * @param {boolean} sort - True if the array needs to be sorted.
+ /**
+ * Snaps a value to the nearest value in an array.
+ * @method Phaser.Math#snapToInArray
+ * @param {number} input
+ * @param {array} arr
+ * @param {boolean} sort - True if the array needs to be sorted.
* @return {number}
- */
+ */
snapToInArray: function (input, arr, sort) {
if (typeof sort === "undefined") { sort = true; }
@@ -231,42 +231,42 @@ Phaser.Math = {
},
- /**
- * Round to some place comparative to a 'base', default is 10 for decimal place.
- *
- * 'place' is represented by the power applied to 'base' to get that place
- * e.g.
- * 2000/7 ~= 285.714285714285714285714 ~= (bin)100011101.1011011011011011
- *
- * roundTo(2000/7,3) === 0
- * roundTo(2000/7,2) == 300
- * roundTo(2000/7,1) == 290
- * roundTo(2000/7,0) == 286
- * roundTo(2000/7,-1) == 285.7
- * roundTo(2000/7,-2) == 285.71
- * roundTo(2000/7,-3) == 285.714
- * roundTo(2000/7,-4) == 285.7143
- * roundTo(2000/7,-5) == 285.71429
- *
- * roundTo(2000/7,3,2) == 288 -- 100100000
- * roundTo(2000/7,2,2) == 284 -- 100011100
- * roundTo(2000/7,1,2) == 286 -- 100011110
- * roundTo(2000/7,0,2) == 286 -- 100011110
- * roundTo(2000/7,-1,2) == 285.5 -- 100011101.1
- * roundTo(2000/7,-2,2) == 285.75 -- 100011101.11
- * roundTo(2000/7,-3,2) == 285.75 -- 100011101.11
- * roundTo(2000/7,-4,2) == 285.6875 -- 100011101.1011
- * roundTo(2000/7,-5,2) == 285.71875 -- 100011101.10111
- *
- * Note what occurs when we round to the 3rd space (8ths place), 100100000, this is to be assumed
- * because we are rounding 100011.1011011011011011 which rounds up.
- *
- * @method Phaser.Math#roundTo
- * @param {number} value - The value to round.
- * @param {number} place - The place to round to.
- * @param {number} base - The base to round in... default is 10 for decimal.
+ /**
+ * Round to some place comparative to a 'base', default is 10 for decimal place.
+ *
+ * 'place' is represented by the power applied to 'base' to get that place
+ * e.g.
+ * 2000/7 ~= 285.714285714285714285714 ~= (bin)100011101.1011011011011011
+ *
+ * roundTo(2000/7,3) === 0
+ * roundTo(2000/7,2) == 300
+ * roundTo(2000/7,1) == 290
+ * roundTo(2000/7,0) == 286
+ * roundTo(2000/7,-1) == 285.7
+ * roundTo(2000/7,-2) == 285.71
+ * roundTo(2000/7,-3) == 285.714
+ * roundTo(2000/7,-4) == 285.7143
+ * roundTo(2000/7,-5) == 285.71429
+ *
+ * roundTo(2000/7,3,2) == 288 -- 100100000
+ * roundTo(2000/7,2,2) == 284 -- 100011100
+ * roundTo(2000/7,1,2) == 286 -- 100011110
+ * roundTo(2000/7,0,2) == 286 -- 100011110
+ * roundTo(2000/7,-1,2) == 285.5 -- 100011101.1
+ * roundTo(2000/7,-2,2) == 285.75 -- 100011101.11
+ * roundTo(2000/7,-3,2) == 285.75 -- 100011101.11
+ * roundTo(2000/7,-4,2) == 285.6875 -- 100011101.1011
+ * roundTo(2000/7,-5,2) == 285.71875 -- 100011101.10111
+ *
+ * Note what occurs when we round to the 3rd space (8ths place), 100100000, this is to be assumed
+ * because we are rounding 100011.1011011011011011 which rounds up.
+ *
+ * @method Phaser.Math#roundTo
+ * @param {number} value - The value to round.
+ * @param {number} place - The place to round to.
+ * @param {number} base - The base to round in... default is 10 for decimal.
* @return {number}
- */
+ */
roundTo: function (value, place, base) {
if (typeof place === "undefined") { place = 0; }
@@ -279,12 +279,12 @@ Phaser.Math = {
},
/**
- * @method Phaser.Math#floorTo
- * @param {number} value - The value to round.
- * @param {number} place - The place to round to.
- * @param {number} base - The base to round in... default is 10 for decimal.
+ * @method Phaser.Math#floorTo
+ * @param {number} value - The value to round.
+ * @param {number} place - The place to round to.
+ * @param {number} base - The base to round in... default is 10 for decimal.
* @return {number}
- */
+ */
floorTo: function (value, place, base) {
if (typeof place === "undefined") { place = 0; }
@@ -297,12 +297,12 @@ Phaser.Math = {
},
/**
- * @method Phaser.Math#ceilTo
- * @param {number} value - The value to round.
- * @param {number} place - The place to round to.
- * @param {number} base - The base to round in... default is 10 for decimal.
+ * @method Phaser.Math#ceilTo
+ * @param {number} value - The value to round.
+ * @param {number} place - The place to round to.
+ * @param {number} base - The base to round in... default is 10 for decimal.
* @return {number}
- */
+ */
ceilTo: function (value, place, base) {
if (typeof place === "undefined") { place = 0; }
@@ -314,38 +314,38 @@ Phaser.Math = {
},
- /**
- * A one dimensional linear interpolation of a value.
- * @method Phaser.Math#interpolateFloat
- * @param {number} a
- * @param {number} b
- * @param {number} weight
+ /**
+ * A one dimensional linear interpolation of a value.
+ * @method Phaser.Math#interpolateFloat
+ * @param {number} a
+ * @param {number} b
+ * @param {number} weight
* @return {number}
- */
+ */
interpolateFloat: function (a, b, weight) {
return (b - a) * weight + a;
},
- /**
- * Find the angle of a segment from (x1, y1) -> (x2, y2 ).
- * @method Phaser.Math#angleBetween
- * @param {number} x1
- * @param {number} y1
- * @param {number} x2
- * @param {number} y2
+ /**
+ * Find the angle of a segment from (x1, y1) -> (x2, y2 ).
+ * @method Phaser.Math#angleBetween
+ * @param {number} x1
+ * @param {number} y1
+ * @param {number} x2
+ * @param {number} y2
* @return {number}
- */
+ */
angleBetween: function (x1, y1, x2, y2) {
return Math.atan2(y2 - y1, x2 - x1);
},
- /**
- * Set an angle within the bounds of -π toπ.
- * @method Phaser.Math#normalizeAngle
- * @param {number} angle
- * @param {boolean} radians - True if angle size is expressed in radians.
+ /**
+ * Set an angle within the bounds of -π toπ.
+ * @method Phaser.Math#normalizeAngle
+ * @param {number} angle
+ * @param {boolean} radians - True if angle size is expressed in radians.
* @return {number}
- */
+ */
normalizeAngle: function (angle, radians) {
if (typeof radians === "undefined") { radians = true; }
@@ -355,15 +355,15 @@ Phaser.Math = {
},
- /**
- * Closest angle between two angles from a1 to a2
- * absolute value the return for exact angle
- * @method Phaser.Math#nearestAngleBetween
- * @param {number} a1
- * @param {number} a2
- * @param {boolean} radians - True if angle sizes are expressed in radians.
+ /**
+ * Closest angle between two angles from a1 to a2
+ * absolute value the return for exact angle
+ * @method Phaser.Math#nearestAngleBetween
+ * @param {number} a1
+ * @param {number} a2
+ * @param {boolean} radians - True if angle sizes are expressed in radians.
* @return {number}
- */
+ */
nearestAngleBetween: function (a1, a2, radians) {
if (typeof radians === "undefined") { radians = true; }
@@ -386,16 +386,16 @@ Phaser.Math = {
},
- /**
- * Interpolate across the shortest arc between two angles.
- * @method Phaser.Math#interpolateAngles
- * @param {number} a1 - Description.
- * @param {number} a2 - Description.
- * @param {number} weight - Description.
- * @param {boolean} radians - True if angle sizes are expressed in radians.
- * @param {Description} ease - Description.
+ /**
+ * Interpolate across the shortest arc between two angles.
+ * @method Phaser.Math#interpolateAngles
+ * @param {number} a1 - Description.
+ * @param {number} a2 - Description.
+ * @param {number} weight - Description.
+ * @param {boolean} radians - True if angle sizes are expressed in radians.
+ * @param {Description} ease - Description.
* @return {number}
- */
+ */
interpolateAngles: function (a1, a2, weight, radians, ease) {
if (typeof radians === "undefined") { radians = true; }
@@ -408,16 +408,16 @@ Phaser.Math = {
},
- /**
- * Generate a random bool result based on the chance value.
- *
- * Returns true or false based on the chance value (default 50%). For example if you wanted a player to have a 30% chance - * of getting a bonus, call chanceRoll(30) - true means the chance passed, false means it failed. - *
- * @method Phaser.Math#chanceRoll - * @param {number} chance - The chance of receiving the value. A number between 0 and 100 (effectively 0% to 100%). - * @return {boolean} True if the roll passed, or false otherwise. - */ + /** + * Generate a random bool result based on the chance value. + *+ * Returns true or false based on the chance value (default 50%). For example if you wanted a player to have a 30% chance + * of getting a bonus, call chanceRoll(30) - true means the chance passed, false means it failed. + *
+ * @method Phaser.Math#chanceRoll + * @param {number} chance - The chance of receiving the value. A number between 0 and 100 (effectively 0% to 100%). + * @return {boolean} True if the roll passed, or false otherwise. + */ chanceRoll: function (chance) { if (typeof chance === "undefined") { chance = 50; } @@ -465,15 +465,15 @@ Phaser.Math = { }, - /** - * Adds the given amount to the value, but never lets the value go over the specified maximum. - * - * @method Phaser.Math#maxAdd - * @param {number} value - The value to add the amount to. - * @param {number} amount - The amount to add to the value. - * @param {number} max- The maximum the value is allowed to be. + /** + * Adds the given amount to the value, but never lets the value go over the specified maximum. + * + * @method Phaser.Math#maxAdd + * @param {number} value - The value to add the amount to. + * @param {number} amount - The amount to add to the value. + * @param {number} max- The maximum the value is allowed to be. * @return {number} - */ + */ maxAdd: function (value, amount, max) { value += amount; @@ -487,15 +487,15 @@ Phaser.Math = { }, - /** - * Subtracts the given amount from the value, but never lets the value go below the specified minimum. - * - * @method Phaser.Math#minSub - * @param {number} value - The base value. - * @param {number} amount - The amount to subtract from the base value. - * @param {number} min - The minimum the value is allowed to be. - * @return {number} The new value. - */ + /** + * Subtracts the given amount from the value, but never lets the value go below the specified minimum. + * + * @method Phaser.Math#minSub + * @param {number} value - The base value. + * @param {number} amount - The amount to subtract from the base value. + * @param {number} min - The minimum the value is allowed to be. + * @return {number} The new value. + */ minSub: function (value, amount, min) { value -= amount; @@ -543,11 +543,11 @@ Phaser.Math = { * Adds value to amount and ensures that the result always stays between 0 and max, by wrapping the value around. *Values must be positive integers, and are passed through Math.abs
* - * @method Phaser.Math#wrapValue - * @param {number} value - The value to add the amount to. - * @param {number} amount - The amount to add to the value. - * @param {number} max - The maximum the value is allowed to be. - * @return {number} The wrapped value. + * @method Phaser.Math#wrapValue + * @param {number} value - The value to add the amount to. + * @param {number} amount - The amount to add to the value. + * @param {number} max - The maximum the value is allowed to be. + * @return {number} The wrapped value. */ wrapValue: function (value, amount, max) { @@ -561,36 +561,36 @@ Phaser.Math = { }, - /** - * Randomly returns either a 1 or -1. - * - * @method Phaser.Math#randomSign - * @return {number} 1 or -1 - */ + /** + * Randomly returns either a 1 or -1. + * + * @method Phaser.Math#randomSign + * @return {number} 1 or -1 + */ randomSign: function () { return (Math.random() > 0.5) ? 1 : -1; }, - /** - * Returns true if the number given is odd. - * - * @method Phaser.Math#isOdd - * @param {number} n - The number to check. - * @return {boolean} True if the given number is odd. False if the given number is even. - */ + /** + * Returns true if the number given is odd. + * + * @method Phaser.Math#isOdd + * @param {number} n - The number to check. + * @return {boolean} True if the given number is odd. False if the given number is even. + */ isOdd: function (n) { return (n & 1); }, - /** - * Returns true if the number given is even. - * - * @method Phaser.Math#isEven - * @param {number} n - The number to check. - * @return {boolean} True if the given number is even. False if the given number is odd. - */ + /** + * Returns true if the number given is even. + * + * @method Phaser.Math#isEven + * @param {number} n - The number to check. + * @return {boolean} True if the given number is even. False if the given number is odd. + */ isEven: function (n) { if (n & 1) @@ -646,30 +646,30 @@ Phaser.Math = { }, - /** - * Keeps an angle value between -180 and +180
* The parameters allow you to specify the length, amplitude and frequency of the wave. Once you have called this function
@@ -926,9 +926,9 @@ Phaser.Math = {
},
- /**
- * Removes the top element from the stack and re-inserts it onto the bottom, then returns it.
- * The original stack is modified in the process. This effectively moves the position of the data from the start to the end of the table.
+ /**
+ * Removes the top element from the stack and re-inserts it onto the bottom, then returns it.
+ * The original stack is modified in the process. This effectively moves the position of the data from the start to the end of the table.
*
* @method Phaser.Math#shift
* @param {array} stack - The array to shift.
@@ -936,14 +936,14 @@ Phaser.Math = {
*/
shift: function (stack) {
- var s = stack.shift();
- stack.push(s);
+ var s = stack.shift();
+ stack.push(s);
- return s;
+ return s;
},
- /**
+ /**
* Shuffles the data in the given array into a new order
* @method Phaser.Math#shuffleArray
* @param {array} array - The array to shuffle
@@ -963,7 +963,7 @@ Phaser.Math = {
},
- /**
+ /**
* Returns the distance between the two given set of coordinates.
*
* @method Phaser.Math#distance
@@ -994,39 +994,39 @@ Phaser.Math = {
*/
distanceRounded: function (x1, y1, x2, y2) {
- return Math.round(Phaser.Math.distance(x1, y1, x2, y2));
+ return Math.round(Phaser.Math.distance(x1, y1, x2, y2));
},
- /**
- * Force a value within the boundaries of two values.
- * Clamp value to range
- *
- * @method Phaser.Math#clamp
- * @param {number} x
- * @param {number} a
- * @param {number} b
+ /**
+ * Force a value within the boundaries of two values.
+ * Clamp value to range
+ *
+ * @method Phaser.Math#clamp
+ * @param {number} x
+ * @param {number} a
+ * @param {number} b
* @return {number}
- */
- clamp: function ( x, a, b ) {
+ */
+ clamp: function ( x, a, b ) {
- return ( x < a ) ? a : ( ( x > b ) ? b : x );
+ return ( x < a ) ? a : ( ( x > b ) ? b : x );
- },
+ },
- /**
- * Clamp value to range to range gravity.y of each particle to this value on launch.
- * @property {number} gravity
- * @default
- */
+ * Sets the gravity.y of each particle to this value on launch.
+ * @property {number} gravity
+ * @default
+ */
this.gravity = 2;
/**
- * Set your own particle class type here.
- * @property {Description} particleClass
- * @default
- */
+ * Set your own particle class type here.
+ * @property {Description} particleClass
+ * @default
+ */
this.particleClass = null;
/**
- * The X and Y drag component of particles launched from the emitter.
- * @property {Phaser.Point} particleDrag
- */
+ * The X and Y drag component of particles launched from the emitter.
+ * @property {Phaser.Point} particleDrag
+ */
this.particleDrag = new Phaser.Point();
/**
- * The angular drag component of particles launched from the emitter if they are rotating.
- * @property {number} angularDrag
- * @default
- */
+ * The angular drag component of particles launched from the emitter if they are rotating.
+ * @property {number} angularDrag
+ * @default
+ */
this.angularDrag = 0;
/**
- * How often a particle is emitted in ms (if emitter is started with Explode === false).
- * @property {boolean} frequency
- * @default
- */
+ * How often a particle is emitted in ms (if emitter is started with Explode === false).
+ * @property {boolean} frequency
+ * @default
+ */
this.frequency = 100;
/**
- * How long each particle lives once it is emitted in ms. Default is 2 seconds.
- * Set lifespan to 'zero' for particles to live forever.
- * @property {number} lifespan
- * @default
- */
+ * How long each particle lives once it is emitted in ms. Default is 2 seconds.
+ * Set lifespan to 'zero' for particles to live forever.
+ * @property {number} lifespan
+ * @default
+ */
this.lifespan = 2000;
/**
- * How much each particle should bounce on each axis. 1 = full bounce, 0 = no bounce.
- * @property {Phaser.Point} bounce
- */
+ * How much each particle should bounce on each axis. 1 = full bounce, 0 = no bounce.
+ * @property {Phaser.Point} bounce
+ */
this.bounce = new Phaser.Point();
/**
- * Internal helper for deciding how many particles to launch.
- * @property {number} _quantity
- * @private
- * @default
- */
+ * Internal helper for deciding how many particles to launch.
+ * @property {number} _quantity
+ * @private
+ * @default
+ */
this._quantity = 0;
- /**
- * Internal helper for deciding when to launch particles or kill them.
- * @property {number} _timer
- * @private
- * @default
- */
+ /**
+ * Internal helper for deciding when to launch particles or kill them.
+ * @property {number} _timer
+ * @private
+ * @default
+ */
this._timer = 0;
/**
- * Internal counter for figuring out how many particles to launch.
- * @property {number} _counter
- * @private
- * @default
- */
+ * Internal counter for figuring out how many particles to launch.
+ * @property {number} _counter
+ * @private
+ * @default
+ */
this._counter = 0;
/**
- * Internal helper for the style of particle emission (all at once, or one at a time).
- * @property {boolean} _explode
- * @private
- * @default
- */
+ * Internal helper for the style of particle emission (all at once, or one at a time).
+ * @property {boolean} _explode
+ * @private
+ * @default
+ */
this._explode = true;
/**
- * Determines whether the emitter is currently emitting particles.
- * It is totally safe to directly toggle this.
- * @property {boolean} on
- * @default
- */
+ * Determines whether the emitter is currently emitting particles.
+ * It is totally safe to directly toggle this.
+ * @property {boolean} on
+ * @default
+ */
this.on = false;
/**
- * Determines whether the emitter is being updated by the core game loop.
- * @property {boolean} exists
- * @default
- */
+ * Determines whether the emitter is being updated by the core game loop.
+ * @property {boolean} exists
+ * @default
+ */
this.exists = true;
/**
- * The point the particles are emitted from.
- * Emitter.x and Emitter.y control the containers location, which updates all current particles
- * Emitter.emitX and Emitter.emitY control the emission location relative to the x/y position.
- * @property {boolean} emitX
- */
+ * The point the particles are emitted from.
+ * Emitter.x and Emitter.y control the containers location, which updates all current particles
+ * Emitter.emitX and Emitter.emitY control the emission location relative to the x/y position.
+ * @property {boolean} emitX
+ */
this.emitX = x;
/**
- * The point the particles are emitted from.
- * Emitter.x and Emitter.y control the containers location, which updates all current particles
- * Emitter.emitX and Emitter.emitY control the emission location relative to the x/y position.
- * @property {boolean} emitY
- */
+ * The point the particles are emitted from.
+ * Emitter.x and Emitter.y control the containers location, which updates all current particles
+ * Emitter.emitX and Emitter.emitY control the emission location relative to the x/y position.
+ * @property {boolean} emitY
+ */
this.emitY = y;
-
+
};
Phaser.Particles.Arcade.Emitter.prototype = Object.create(Phaser.Group.prototype);
@@ -234,12 +234,12 @@ Phaser.Particles.Arcade.Emitter.prototype.update = function () {
{
if (this._explode)
{
- this._counter = 0;
+ this._counter = 0;
do
{
- this.emitParticle();
- this._counter++;
+ this.emitParticle();
+ this._counter++;
}
while (this._counter < this._quantity);
@@ -247,22 +247,22 @@ Phaser.Particles.Arcade.Emitter.prototype.update = function () {
}
else
{
- if (this.game.time.now >= this._timer)
- {
+ if (this.game.time.now >= this._timer)
+ {
this.emitParticle();
-
- this._counter++;
+
+ this._counter++;
if (this._quantity > 0)
{
- if (this._counter >= this._quantity)
- {
- this.on = false;
- }
+ if (this._counter >= this._quantity)
+ {
+ this.on = false;
+ }
}
this._timer = this.game.time.now + this.frequency;
- }
+ }
}
}
@@ -286,7 +286,7 @@ Phaser.Particles.Arcade.Emitter.prototype.makeParticles = function (keys, frames
frames = 0;
}
- quantity = quantity || this.maxParticles;
+ quantity = quantity || this.maxParticles;
collide = collide || 0;
if (typeof collideWorldBounds == 'undefined')
@@ -315,10 +315,10 @@ Phaser.Particles.Arcade.Emitter.prototype.makeParticles = function (keys, frames
particle = new Phaser.Sprite(this.game, 0, 0, rndKey, rndFrame);
}
- else
- {
+ // else
+ // {
// particle = new this.particleClass(this.game);
- }
+ // }
if (collide > 0)
{
@@ -380,18 +380,18 @@ Phaser.Particles.Arcade.Emitter.prototype.revive = function () {
*/
Phaser.Particles.Arcade.Emitter.prototype.start = function (explode, lifespan, frequency, quantity) {
- if (typeof explode !== 'boolean')
- {
- explode = true;
- }
+ if (typeof explode !== 'boolean')
+ {
+ explode = true;
+ }
- lifespan = lifespan || 0;
+ lifespan = lifespan || 0;
- // How many ms between emissions?
- frequency = frequency || 250;
+ // How many ms between emissions?
+ frequency = frequency || 250;
- // Total number of particles to emit
- quantity = quantity || 0;
+ // Total number of particles to emit
+ quantity = quantity || 0;
this.revive();
@@ -426,16 +426,16 @@ Phaser.Particles.Arcade.Emitter.prototype.emitParticle = function () {
if (particle == null)
{
- return;
+ return;
}
if (this.width > 1 || this.height > 1)
{
- particle.reset(this.game.rnd.integerInRange(this.left, this.right), this.game.rnd.integerInRange(this.top, this.bottom));
+ particle.reset(this.game.rnd.integerInRange(this.left, this.right), this.game.rnd.integerInRange(this.top, this.bottom));
}
else
{
- particle.reset(this.emitX, this.emitY);
+ particle.reset(this.emitX, this.emitY);
}
particle.lifespan = this.lifespan;
@@ -504,8 +504,8 @@ Phaser.Particles.Arcade.Emitter.prototype.setSize = function (width, height) {
*/
Phaser.Particles.Arcade.Emitter.prototype.setXSpeed = function (min, max) {
- min = min || 0;
- max = max || 0;
+ min = min || 0;
+ max = max || 0;
this.minParticleSpeed.x = min;
this.maxParticleSpeed.x = max;
@@ -520,8 +520,8 @@ Phaser.Particles.Arcade.Emitter.prototype.setXSpeed = function (min, max) {
*/
Phaser.Particles.Arcade.Emitter.prototype.setYSpeed = function (min, max) {
- min = min || 0;
- max = max || 0;
+ min = min || 0;
+ max = max || 0;
this.minParticleSpeed.y = min;
this.maxParticleSpeed.y = max;
@@ -536,8 +536,8 @@ Phaser.Particles.Arcade.Emitter.prototype.setYSpeed = function (min, max) {
*/
Phaser.Particles.Arcade.Emitter.prototype.setRotation = function (min, max) {
- min = min || 0;
- max = max || 0;
+ min = min || 0;
+ max = max || 0;
this.minRotation = min;
this.maxRotation = max;
diff --git a/src/physics/advanced/collision/QuadTree.js b/src/physics/advanced/collision/QuadTree.js
index b0a48a73..1cf5c58b 100644
--- a/src/physics/advanced/collision/QuadTree.js
+++ b/src/physics/advanced/collision/QuadTree.js
@@ -27,10 +27,10 @@ function QuadTree(bounds, pointQuad, maxDepth, maxChildren){
}
/**
- * The root node of the QuadTree which covers the entire area being segmented.
- * @property root
- * @type Node
- */
+ * The root node of the QuadTree which covers the entire area being segmented.
+ * @property root
+ * @type Node
+ */
this.root = node;
}
@@ -299,7 +299,7 @@ BoundsNode.prototype.insert = function(item){
console.log("radius:",item.boundingRadius);
console.log("item x:",item.position[0] - item.boundingRadius,"x range:",node.bounds.x,node.bounds.x+node.bounds.width);
console.log("item y:",item.position[1] - item.boundingRadius,"y range:",node.bounds.y,node.bounds.y+node.bounds.height);
- */
+ */
//todo: make _bounds bounds
if( !(item instanceof Plane) && // Plane is infinite.. Make it a "stuck" child
diff --git a/src/physics/advanced/collision/SAP1DBroadphase.js b/src/physics/advanced/collision/SAP1DBroadphase.js
index 303d38da..7aa14c7c 100644
--- a/src/physics/advanced/collision/SAP1DBroadphase.js
+++ b/src/physics/advanced/collision/SAP1DBroadphase.js
@@ -19,24 +19,24 @@ function SAP1DBroadphase(world){
Broadphase.apply(this);
/**
- * List of bodies currently in the broadphase.
- * @property axisList
- * @type {Array}
- */
+ * List of bodies currently in the broadphase.
+ * @property axisList
+ * @type {Array}
+ */
this.axisList = world.bodies.slice(0);
/**
- * The world to search in.
- * @property world
- * @type {World}
- */
+ * The world to search in.
+ * @property world
+ * @type {World}
+ */
this.world = world;
/**
- * Axis to sort the bodies along. Set to 0 for x axis, and 1 for y axis. For best performance, choose an axis that the bodies are spread out more on.
- * @property axisIndex
- * @type {Number}
- */
+ * Axis to sort the bodies along. Set to 0 for x axis, and 1 for y axis. For best performance, choose an axis that the bodies are spread out more on.
+ * @property axisIndex
+ * @type {Number}
+ */
this.axisIndex = 0;
// Add listeners to update the list of bodies.
diff --git a/src/physics/advanced/constraints/Constraint.js b/src/physics/advanced/constraints/Constraint.js
index df838cb1..b73c0376 100644
--- a/src/physics/advanced/constraints/Constraint.js
+++ b/src/physics/advanced/constraints/Constraint.js
@@ -12,24 +12,24 @@ module.exports = Constraint;
function Constraint(bodyA,bodyB){
/**
- * Equations to be solved in this constraint
- * @property equations
- * @type {Array}
- */
+ * Equations to be solved in this constraint
+ * @property equations
+ * @type {Array}
+ */
this.equations = [];
/**
- * First body participating in the constraint.
- * @property bodyA
- * @type {Body}
- */
+ * First body participating in the constraint.
+ * @property bodyA
+ * @type {Body}
+ */
this.bodyA = bodyA;
/**
- * Second body participating in the constraint.
- * @property bodyB
- * @type {Body}
- */
+ * Second body participating in the constraint.
+ * @property bodyB
+ * @type {Body}
+ */
this.bodyB = bodyB;
};
diff --git a/src/physics/advanced/constraints/Equation.js b/src/physics/advanced/constraints/Equation.js
index 877f1222..2bbd564b 100644
--- a/src/physics/advanced/constraints/Equation.js
+++ b/src/physics/advanced/constraints/Equation.js
@@ -12,45 +12,45 @@ module.exports = Equation;
function Equation(bi,bj,minForce,maxForce){
/**
- * Minimum force to apply when solving
- * @property minForce
- * @type {Number}
- */
+ * Minimum force to apply when solving
+ * @property minForce
+ * @type {Number}
+ */
this.minForce = typeof(minForce)=="undefined" ? -1e6 : minForce;
/**
- * Max force to apply when solving
- * @property maxForce
- * @type {Number}
- */
+ * Max force to apply when solving
+ * @property maxForce
+ * @type {Number}
+ */
this.maxForce = typeof(maxForce)=="undefined" ? 1e6 : maxForce;
/**
- * First body participating in the constraint
- * @property bi
- * @type {Body}
- */
+ * First body participating in the constraint
+ * @property bi
+ * @type {Body}
+ */
this.bi = bi;
/**
- * Second body participating in the constraint
- * @property bj
- * @type {Body}
- */
+ * Second body participating in the constraint
+ * @property bj
+ * @type {Body}
+ */
this.bj = bj;
/**
- * The stiffness of this equation. Typically chosen to a large number (~1e7), but can be chosen somewhat freely to get a stable simulation.
- * @property stiffness
- * @type {Number}
- */
+ * The stiffness of this equation. Typically chosen to a large number (~1e7), but can be chosen somewhat freely to get a stable simulation.
+ * @property stiffness
+ * @type {Number}
+ */
this.stiffness = 1e6;
/**
- * The number of time steps needed to stabilize the constraint equation. Typically between 3 and 5 time steps.
- * @property relaxation
- * @type {Number}
- */
+ * The number of time steps needed to stabilize the constraint equation. Typically between 3 and 5 time steps.
+ * @property relaxation
+ * @type {Number}
+ */
this.relaxation = 4;
this.a = 0;
diff --git a/src/physics/advanced/constraints/FrictionEquation.js b/src/physics/advanced/constraints/FrictionEquation.js
index a8b09184..d0a3e812 100644
--- a/src/physics/advanced/constraints/FrictionEquation.js
+++ b/src/physics/advanced/constraints/FrictionEquation.js
@@ -31,24 +31,24 @@ function FrictionEquation(bi,bj,slipForce){
Equation.call(this,bi,bj,-slipForce,slipForce);
/**
- * Relative vector from center of body i to the contact point, in world coords.
- * @property ri
- * @type {Float32Array}
- */
+ * Relative vector from center of body i to the contact point, in world coords.
+ * @property ri
+ * @type {Float32Array}
+ */
this.ri = vec2.create();
/**
- * Relative vector from center of body j to the contact point, in world coords.
- * @property rj
- * @type {Float32Array}
- */
+ * Relative vector from center of body j to the contact point, in world coords.
+ * @property rj
+ * @type {Float32Array}
+ */
this.rj = vec2.create();
/**
- * Tangent vector that the friction force will act along, in world coords.
- * @property t
- * @type {Float32Array}
- */
+ * Tangent vector that the friction force will act along, in world coords.
+ * @property t
+ * @type {Float32Array}
+ */
this.t = vec2.create();
this.rixt = 0;
diff --git a/src/physics/advanced/events/EventEmitter.js b/src/physics/advanced/events/EventEmitter.js
index 576d2024..35bfbc7d 100644
--- a/src/physics/advanced/events/EventEmitter.js
+++ b/src/physics/advanced/events/EventEmitter.js
@@ -11,12 +11,12 @@ EventEmitter.prototype = {
constructor: EventEmitter,
/**
- * Add an event listener
- * @method on
- * @param {String} type
- * @param {Function} listener
- * @return {EventEmitter} The self object, for chainability.
- */
+ * Add an event listener
+ * @method on
+ * @param {String} type
+ * @param {Function} listener
+ * @return {EventEmitter} The self object, for chainability.
+ */
on: function ( type, listener ) {
if ( this._listeners === undefined ) this._listeners = {};
var listeners = this._listeners;
@@ -30,12 +30,12 @@ EventEmitter.prototype = {
},
/**
- * Check if an event listener is added
- * @method has
- * @param {String} type
- * @param {Function} listener
- * @return {Boolean}
- */
+ * Check if an event listener is added
+ * @method has
+ * @param {String} type
+ * @param {Function} listener
+ * @return {Boolean}
+ */
has: function ( type, listener ) {
if ( this._listeners === undefined ) return false;
var listeners = this._listeners;
@@ -46,12 +46,12 @@ EventEmitter.prototype = {
},
/**
- * Remove an event listener
- * @method off
- * @param {String} type
- * @param {Function} listener
- * @return {EventEmitter} The self object, for chainability.
- */
+ * Remove an event listener
+ * @method off
+ * @param {String} type
+ * @param {Function} listener
+ * @return {EventEmitter} The self object, for chainability.
+ */
off: function ( type, listener ) {
if ( this._listeners === undefined ) return;
var listeners = this._listeners;
@@ -63,12 +63,12 @@ EventEmitter.prototype = {
},
/**
- * Emit an event.
- * @method emit
- * @param {Object} event
- * @param {String} event.type
- * @return {EventEmitter} The self object, for chainability.
- */
+ * Emit an event.
+ * @method emit
+ * @param {Object} event
+ * @param {String} event.type
+ * @return {EventEmitter} The self object, for chainability.
+ */
emit: function ( event ) {
if ( this._listeners === undefined ) return;
var listeners = this._listeners;
diff --git a/src/physics/advanced/material/ContactMaterial.js b/src/physics/advanced/material/ContactMaterial.js
index 6040c2d6..0577e608 100644
--- a/src/physics/advanced/material/ContactMaterial.js
+++ b/src/physics/advanced/material/ContactMaterial.js
@@ -17,65 +17,65 @@ function ContactMaterial(materialA, materialB, options){
options = options || {};
/**
- * The contact material identifier
- * @property id
- * @type {Number}
- */
+ * The contact material identifier
+ * @property id
+ * @type {Number}
+ */
this.id = idCounter++;
/**
- * First material participating in the contact material
- * @property materialA
- * @type {Material}
- */
+ * First material participating in the contact material
+ * @property materialA
+ * @type {Material}
+ */
this.materialA = materialA;
/**
- * Second material participating in the contact material
- * @property materialB
- * @type {Material}
- */
+ * Second material participating in the contact material
+ * @property materialB
+ * @type {Material}
+ */
this.materialB = materialB;
/**
- * Friction to use in the contact of these two materials
- * @property friction
- * @type {Number}
- */
+ * Friction to use in the contact of these two materials
+ * @property friction
+ * @type {Number}
+ */
this.friction = typeof(options.friction) !== "undefined" ? Number(options.friction) : 0.3;
/**
- * Restitution to use in the contact of these two materials
- * @property restitution
- * @type {Number}
- */
+ * Restitution to use in the contact of these two materials
+ * @property restitution
+ * @type {Number}
+ */
this.restitution = typeof(options.restitution) !== "undefined" ? Number(options.restitution) : 0.3;
/**
- * Stiffness of the resulting ContactEquation that this ContactMaterial generate
- * @property stiffness
- * @type {Number}
- */
+ * Stiffness of the resulting ContactEquation that this ContactMaterial generate
+ * @property stiffness
+ * @type {Number}
+ */
this.stiffness = typeof(options.stiffness) !== "undefined" ? Number(options.stiffness) : 1e7;
/**
- * Relaxation of the resulting ContactEquation that this ContactMaterial generate
- * @property relaxation
- * @type {Number}
- */
+ * Relaxation of the resulting ContactEquation that this ContactMaterial generate
+ * @property relaxation
+ * @type {Number}
+ */
this.relaxation = typeof(options.relaxation) !== "undefined" ? Number(options.relaxation) : 3;
/**
- * Stiffness of the resulting FrictionEquation that this ContactMaterial generate
- * @property frictionStiffness
- * @type {Number}
- */
+ * Stiffness of the resulting FrictionEquation that this ContactMaterial generate
+ * @property frictionStiffness
+ * @type {Number}
+ */
this.frictionStiffness = typeof(options.frictionStiffness) !== "undefined" ? Number(options.frictionStiffness) : 1e7;
/**
- * Relaxation of the resulting FrictionEquation that this ContactMaterial generate
- * @property frictionRelaxation
- * @type {Number}
- */
+ * Relaxation of the resulting FrictionEquation that this ContactMaterial generate
+ * @property frictionRelaxation
+ * @type {Number}
+ */
this.frictionRelaxation = typeof(options.frictionRelaxation) !== "undefined" ? Number(options.frictionRelaxation) : 3;
};
diff --git a/src/physics/advanced/material/Material.js b/src/physics/advanced/material/Material.js
index 7c878dd9..7ae21ea2 100644
--- a/src/physics/advanced/material/Material.js
+++ b/src/physics/advanced/material/Material.js
@@ -11,9 +11,9 @@ var idCounter = 0;
*/
function Material(){
/**
- * The material identifier
- * @property id
- * @type {Number}
- */
+ * The material identifier
+ * @property id
+ * @type {Number}
+ */
this.id = idCounter++;
};
diff --git a/src/physics/advanced/math/polyk.js b/src/physics/advanced/math/polyk.js
index 7be20833..6f4b4d5f 100644
--- a/src/physics/advanced/math/polyk.js
+++ b/src/physics/advanced/math/polyk.js
@@ -472,6 +472,6 @@
PolyK._tp = [];
for(var i=0; i<10; i++) PolyK._tp.push(new PolyK._P(0,0));
- */
+ */
module.exports = PolyK;
diff --git a/src/physics/advanced/objects/Body.js b/src/physics/advanced/objects/Body.js
index eeaa004d..701df13d 100644
--- a/src/physics/advanced/objects/Body.js
+++ b/src/physics/advanced/objects/Body.js
@@ -25,155 +25,155 @@ function Body(options){
options = options || {};
/**
- * The body identifyer
- * @property id
- * @type {Number}
- */
+ * The body identifyer
+ * @property id
+ * @type {Number}
+ */
this.id = ++Body._idCounter;
/**
- * The shapes of the body. The local transform of the shape in .shapes[i] is
- * defined by .shapeOffsets[i] and .shapeAngles[i].
- *
- * @property shapes
- * @type {Array}
- */
+ * The shapes of the body. The local transform of the shape in .shapes[i] is
+ * defined by .shapeOffsets[i] and .shapeAngles[i].
+ *
+ * @property shapes
+ * @type {Array}
+ */
this.shapes = [];
/**
- * The local shape offsets, relative to the body center of mass. This is an
- * array of Float32Array.
- * @property shapeOffsets
- * @type {Array}
- */
+ * The local shape offsets, relative to the body center of mass. This is an
+ * array of Float32Array.
+ * @property shapeOffsets
+ * @type {Array}
+ */
this.shapeOffsets = [];
/**
- * The body-local shape angle transforms. This is an array of numbers (angles).
- * @property shapeAngles
- * @type {Array}
- */
+ * The body-local shape angle transforms. This is an array of numbers (angles).
+ * @property shapeAngles
+ * @type {Array}
+ */
this.shapeAngles = [];
/**
- * The mass of the body.
- * @property mass
- * @type {number}
- */
+ * The mass of the body.
+ * @property mass
+ * @type {number}
+ */
this.mass = options.mass || 0;
/**
- * The inverse mass of the body.
- * @property invMass
- * @type {number}
- */
+ * The inverse mass of the body.
+ * @property invMass
+ * @type {number}
+ */
this.invMass = 0;
/**
- * The inertia of the body around the Z axis.
- * @property inertia
- * @type {number}
- */
+ * The inertia of the body around the Z axis.
+ * @property inertia
+ * @type {number}
+ */
this.inertia = 0;
/**
- * The inverse inertia of the body.
- * @property invInertia
- * @type {number}
- */
+ * The inverse inertia of the body.
+ * @property invInertia
+ * @type {number}
+ */
this.invInertia = 0;
this.updateMassProperties();
/**
- * The position of the body
- * @property position
- * @type {Float32Array}
- */
+ * The position of the body
+ * @property position
+ * @type {Float32Array}
+ */
this.position = vec2.fromValues(0,0);
if(options.position) vec2.copy(this.position, options.position);
/**
- * The velocity of the body
- * @property velocity
- * @type {Float32Array}
- */
+ * The velocity of the body
+ * @property velocity
+ * @type {Float32Array}
+ */
this.velocity = vec2.fromValues(0,0);
if(options.velocity) vec2.copy(this.velocity, options.velocity);
/**
- * Constraint velocity that was added to the body during the last step.
- * @property vlambda
- * @type {Float32Array}
- */
+ * Constraint velocity that was added to the body during the last step.
+ * @property vlambda
+ * @type {Float32Array}
+ */
this.vlambda = vec2.fromValues(0,0);
/**
- * Angular constraint velocity that was added to the body during last step.
- * @property wlambda
- * @type {Float32Array}
- */
+ * Angular constraint velocity that was added to the body during last step.
+ * @property wlambda
+ * @type {Float32Array}
+ */
this.wlambda = 0;
/**
- * The angle of the body
- * @property angle
- * @type {number}
- */
+ * The angle of the body
+ * @property angle
+ * @type {number}
+ */
this.angle = options.angle || 0;
/**
- * The angular velocity of the body
- * @property angularVelocity
- * @type {number}
- */
+ * The angular velocity of the body
+ * @property angularVelocity
+ * @type {number}
+ */
this.angularVelocity = options.angularVelocity || 0;
/**
- * The force acting on the body
- * @property force
- * @type {Float32Array}
- */
+ * The force acting on the body
+ * @property force
+ * @type {Float32Array}
+ */
this.force = vec2.create();
if(options.force) vec2.copy(this.force, options.force);
/**
- * The angular force acting on the body
- * @property angularForce
- * @type {number}
- */
+ * The angular force acting on the body
+ * @property angularForce
+ * @type {number}
+ */
this.angularForce = options.angularForce || 0;
/**
- * The type of motion this body has. Should be one of: Body.STATIC (the body
- * does not move), Body.DYNAMIC (body can move and respond to collisions)
- * and Body.KINEMATIC (only moves according to its .velocity).
- *
- * @property motionState
- * @type {number}
- *
- * @example
- * // This body will move and interact with other bodies
- * var dynamicBody = new Body();
- * dynamicBody.motionState = Body.DYNAMIC;
- *
- * @example
- * // This body will not move at all
- * var staticBody = new Body();
- * staticBody.motionState = Body.STATIC;
- *
- * @example
- * // This body will only move if you change its velocity
- * var kinematicBody = new Body();
- * kinematicBody.motionState = Body.KINEMATIC;
- */
+ * The type of motion this body has. Should be one of: Body.STATIC (the body
+ * does not move), Body.DYNAMIC (body can move and respond to collisions)
+ * and Body.KINEMATIC (only moves according to its .velocity).
+ *
+ * @property motionState
+ * @type {number}
+ *
+ * @example
+ * // This body will move and interact with other bodies
+ * var dynamicBody = new Body();
+ * dynamicBody.motionState = Body.DYNAMIC;
+ *
+ * @example
+ * // This body will not move at all
+ * var staticBody = new Body();
+ * staticBody.motionState = Body.STATIC;
+ *
+ * @example
+ * // This body will only move if you change its velocity
+ * var kinematicBody = new Body();
+ * kinematicBody.motionState = Body.KINEMATIC;
+ */
this.motionState = this.mass === 0 ? Body.STATIC : Body.DYNAMIC;
/**
- * Bounding circle radius
- * @property boundingRadius
- * @type {Number}
- */
+ * Bounding circle radius
+ * @property boundingRadius
+ * @type {Number}
+ */
this.boundingRadius = 0;
};
diff --git a/src/physics/advanced/objects/Spring.js b/src/physics/advanced/objects/Spring.js
index 44f7131c..8105a9c5 100644
--- a/src/physics/advanced/objects/Spring.js
+++ b/src/physics/advanced/objects/Spring.js
@@ -22,52 +22,52 @@ function Spring(bodyA,bodyB,options){
options = options || {};
/**
- * Rest length of the spring.
- * @property restLength
- * @type {number}
- */
+ * Rest length of the spring.
+ * @property restLength
+ * @type {number}
+ */
this.restLength = typeof(options.restLength)=="number" ? options.restLength : 1;
/**
- * Stiffness of the spring.
- * @property stiffness
- * @type {number}
- */
+ * Stiffness of the spring.
+ * @property stiffness
+ * @type {number}
+ */
this.stiffness = options.stiffness || 100;
/**
- * Damping of the spring.
- * @property damping
- * @type {number}
- */
+ * Damping of the spring.
+ * @property damping
+ * @type {number}
+ */
this.damping = options.damping || 1;
/**
- * First connected body.
- * @property bodyA
- * @type {Body}
- */
+ * First connected body.
+ * @property bodyA
+ * @type {Body}
+ */
this.bodyA = bodyA;
/**
- * Second connected body.
- * @property bodyB
- * @type {Body}
- */
+ * Second connected body.
+ * @property bodyB
+ * @type {Body}
+ */
this.bodyB = bodyB;
/**
- * Anchor for bodyA in local bodyA coordinates.
- * @property localAnchorA
- * @type {Array}
- */
+ * Anchor for bodyA in local bodyA coordinates.
+ * @property localAnchorA
+ * @type {Array}
+ */
this.localAnchorA = vec2.fromValues(0,0);
/**
- * Anchor for bodyB in local bodyB coordinates.
- * @property localAnchorB
- * @type {Array}
- */
+ * Anchor for bodyB in local bodyB coordinates.
+ * @property localAnchorB
+ * @type {Array}
+ */
this.localAnchorB = vec2.fromValues(0,0);
if(options.localAnchorA) vec2.copy(this.localAnchorA, options.localAnchorA);
diff --git a/src/physics/advanced/shapes/Circle.js b/src/physics/advanced/shapes/Circle.js
index 447e2cd9..9c2a1aeb 100644
--- a/src/physics/advanced/shapes/Circle.js
+++ b/src/physics/advanced/shapes/Circle.js
@@ -12,10 +12,10 @@ module.exports = Circle;
function Circle(radius){
/**
- * The radius of the circle.
- * @property radius
- * @type {number}
- */
+ * The radius of the circle.
+ * @property radius
+ * @type {number}
+ */
this.radius = radius || 1;
Shape.call(this,Shape.CIRCLE);
diff --git a/src/physics/advanced/shapes/Convex.js b/src/physics/advanced/shapes/Convex.js
index 8599608b..61c4912d 100644
--- a/src/physics/advanced/shapes/Convex.js
+++ b/src/physics/advanced/shapes/Convex.js
@@ -14,24 +14,24 @@ module.exports = Convex;
function Convex(vertices){
/**
- * Vertices defined in the local frame.
- * @property vertices
- * @type {Array}
- */
+ * Vertices defined in the local frame.
+ * @property vertices
+ * @type {Array}
+ */
this.vertices = vertices || [];
/**
- * The center of mass of the Convex
- * @property centerOfMass
- * @type {Float32Array}
- */
+ * The center of mass of the Convex
+ * @property centerOfMass
+ * @type {Float32Array}
+ */
this.centerOfMass = vec2.fromValues(0,0);
/**
- * Triangulated version of this convex. The structure is Array of 3-Arrays, and each subarray contains 3 integers, referencing the vertices.
- * @property triangles
- * @type {Array}
- */
+ * Triangulated version of this convex. The structure is Array of 3-Arrays, and each subarray contains 3 integers, referencing the vertices.
+ * @property triangles
+ * @type {Array}
+ */
this.triangles = [];
if(this.vertices.length){
@@ -40,10 +40,10 @@ function Convex(vertices){
}
/**
- * The bounding radius of the convex
- * @property boundingRadius
- * @type {Number}
- */
+ * The bounding radius of the convex
+ * @property boundingRadius
+ * @type {Number}
+ */
this.boundingRadius = 0;
this.updateBoundingRadius();
diff --git a/src/physics/advanced/shapes/Line.js b/src/physics/advanced/shapes/Line.js
index 30fc9205..630523eb 100644
--- a/src/physics/advanced/shapes/Line.js
+++ b/src/physics/advanced/shapes/Line.js
@@ -11,10 +11,10 @@ module.exports = Line;
function Line(length){
/**
- * Length of this line
- * @property length
- * @type {Number}
- */
+ * Length of this line
+ * @property length
+ * @type {Number}
+ */
this.length = length;
Shape.call(this,Shape.LINE);
diff --git a/src/physics/advanced/shapes/Shape.js b/src/physics/advanced/shapes/Shape.js
index 1d349b40..b0a9d708 100644
--- a/src/physics/advanced/shapes/Shape.js
+++ b/src/physics/advanced/shapes/Shape.js
@@ -9,56 +9,56 @@ function Shape(type){
this.type = type;
/**
- * Bounding circle radius of this shape
- * @property boundingRadius
- * @type {Number}
- */
+ * Bounding circle radius of this shape
+ * @property boundingRadius
+ * @type {Number}
+ */
this.boundingRadius = 0;
/**
- * Collision group that this shape belongs to (bit mask). See this tutorial.
- * @property collisionGroup
- * @type {Number}
- * @example
- * // Setup bits for each available group
- * var PLAYER = Math.pow(2,0),
- * ENEMY = Math.pow(2,1),
- * GROUND = Math.pow(2,2)
- *
- * // Put shapes into their groups
- * player1Shape.collisionGroup = PLAYER;
- * player2Shape.collisionGroup = PLAYER;
- * enemyShape .collisionGroup = ENEMY;
- * groundShape .collisionGroup = GROUND;
- *
- * // Assign groups that each shape collide with.
- * // Note that the players can collide with ground and enemies, but not with other players.
- * player1Shape.collisionMask = ENEMY | GROUND;
- * player2Shape.collisionMask = ENEMY | GROUND;
- * enemyShape .collisionMask = PLAYER | GROUND;
- * groundShape .collisionMask = PLAYER | ENEMY;
- *
- * @example
- * // How collision check is done
- * if(shapeA.collisionGroup & shapeB.collisionMask)!=0 && (shapeB.collisionGroup & shapeA.collisionMask)!=0){
- * // The shapes will collide
- * }
- */
+ * Collision group that this shape belongs to (bit mask). See this tutorial.
+ * @property collisionGroup
+ * @type {Number}
+ * @example
+ * // Setup bits for each available group
+ * var PLAYER = Math.pow(2,0),
+ * ENEMY = Math.pow(2,1),
+ * GROUND = Math.pow(2,2)
+ *
+ * // Put shapes into their groups
+ * player1Shape.collisionGroup = PLAYER;
+ * player2Shape.collisionGroup = PLAYER;
+ * enemyShape .collisionGroup = ENEMY;
+ * groundShape .collisionGroup = GROUND;
+ *
+ * // Assign groups that each shape collide with.
+ * // Note that the players can collide with ground and enemies, but not with other players.
+ * player1Shape.collisionMask = ENEMY | GROUND;
+ * player2Shape.collisionMask = ENEMY | GROUND;
+ * enemyShape .collisionMask = PLAYER | GROUND;
+ * groundShape .collisionMask = PLAYER | ENEMY;
+ *
+ * @example
+ * // How collision check is done
+ * if(shapeA.collisionGroup & shapeB.collisionMask)!=0 && (shapeB.collisionGroup & shapeA.collisionMask)!=0){
+ * // The shapes will collide
+ * }
+ */
this.collisionGroup = 1;
/**
- * Collision mask of this shape. See .collisionGroup.
- * @property collisionMask
- * @type {Number}
- */
+ * Collision mask of this shape. See .collisionGroup.
+ * @property collisionMask
+ * @type {Number}
+ */
this.collisionMask = 1;
if(type) this.updateBoundingRadius();
/**
- * Material to use in collisions for this Shape. If this is set to null, the world will use default material properties instead.
- * @property material
- * @type {Material}
- */
+ * Material to use in collisions for this Shape. If this is set to null, the world will use default material properties instead.
+ * @property material
+ * @type {Material}
+ */
this.material = null;
};
diff --git a/src/physics/advanced/solver/GSSolver.js b/src/physics/advanced/solver/GSSolver.js
index a2f25cb6..b5f6e761 100644
--- a/src/physics/advanced/solver/GSSolver.js
+++ b/src/physics/advanced/solver/GSSolver.js
@@ -30,31 +30,31 @@ function GSSolver(options){
this.invCs = new ARRAY_TYPE(this.arrayStep);
/**
- * Whether to use .stiffness and .relaxation parameters from the Solver instead of each Equation individually.
- * @type {Boolean}
- * @property useGlobalEquationParameters
- */
+ * Whether to use .stiffness and .relaxation parameters from the Solver instead of each Equation individually.
+ * @type {Boolean}
+ * @property useGlobalEquationParameters
+ */
this.useGlobalEquationParameters = true;
/**
- * Global equation stiffness.
- * @property stiffness
- * @type {Number}
- */
+ * Global equation stiffness.
+ * @property stiffness
+ * @type {Number}
+ */
this.stiffness = 1e6;
/**
- * Global equation relaxation.
- * @property relaxation
- * @type {Number}
- */
+ * Global equation relaxation.
+ * @property relaxation
+ * @type {Number}
+ */
this.relaxation = 4;
/**
- * Set to true to set all right hand side terms to zero when solving. Can be handy for a few applications.
- * @property useZeroRHS
- * @type {Boolean}
- */
+ * Set to true to set all right hand side terms to zero when solving. Can be handy for a few applications.
+ * @property useZeroRHS
+ * @type {Boolean}
+ */
this.useZeroRHS = false;
};
GSSolver.prototype = new Solver();
diff --git a/src/physics/advanced/solver/Island.js b/src/physics/advanced/solver/Island.js
index b3c8635d..ee5261ca 100644
--- a/src/physics/advanced/solver/Island.js
+++ b/src/physics/advanced/solver/Island.js
@@ -8,17 +8,17 @@ module.exports = Island;
function Island(){
/**
- * Current equations in this island.
- * @property equations
- * @type {Array}
- */
+ * Current equations in this island.
+ * @property equations
+ * @type {Array}
+ */
this.equations = [];
/**
- * Current bodies in this island.
- * @property bodies
- * @type {Array}
- */
+ * Current bodies in this island.
+ * @property bodies
+ * @type {Array}
+ */
this.bodies = [];
}
diff --git a/src/physics/advanced/solver/IslandSolver.js b/src/physics/advanced/solver/IslandSolver.js
index 9d4e35be..73c5b79c 100644
--- a/src/physics/advanced/solver/IslandSolver.js
+++ b/src/physics/advanced/solver/IslandSolver.js
@@ -19,17 +19,17 @@ function IslandSolver(subsolver){
var that = this;
/**
- * The solver used in the workers.
- * @property subsolver
- * @type {Solver}
- */
+ * The solver used in the workers.
+ * @property subsolver
+ * @type {Solver}
+ */
this.subsolver = subsolver;
/**
- * Number of islands
- * @property numIslands
- * @type {number}
- */
+ * Number of islands
+ * @property numIslands
+ * @type {number}
+ */
this.numIslands = 0;
// Pooling of node objects saves some GC load
diff --git a/src/physics/advanced/solver/Solver.js b/src/physics/advanced/solver/Solver.js
index 6cb482b9..5a1f8399 100644
--- a/src/physics/advanced/solver/Solver.js
+++ b/src/physics/advanced/solver/Solver.js
@@ -10,11 +10,11 @@ module.exports = Solver;
function Solver(){
/**
- * Current equations in the solver.
- *
- * @property equations
- * @type {Array}
- */
+ * Current equations in the solver.
+ *
+ * @property equations
+ * @type {Array}
+ */
this.equations = [];
};
diff --git a/src/physics/advanced/world/World.js b/src/physics/advanced/world/World.js
index 1c209d39..4d1e0540 100644
--- a/src/physics/advanced/world/World.js
+++ b/src/physics/advanced/world/World.js
@@ -48,110 +48,110 @@ function World(options){
options = options || {};
/**
- * All springs in the world.
- *
- * @property springs
- * @type {Array}
- */
+ * All springs in the world.
+ *
+ * @property springs
+ * @type {Array}
+ */
this.springs = [];
/**
- * All bodies in the world.
- *
- * @property bodies
- * @type {Array}
- */
+ * All bodies in the world.
+ *
+ * @property bodies
+ * @type {Array}
+ */
this.bodies = [];
/**
- * The solver used to satisfy constraints and contacts.
- *
- * @property solver
- * @type {Solver}
- */
+ * The solver used to satisfy constraints and contacts.
+ *
+ * @property solver
+ * @type {Solver}
+ */
this.solver = options.solver || new GSSolver();
/**
- * The nearphase to use to generate contacts.
- *
- * @property nearphase
- * @type {Nearphase}
- */
+ * The nearphase to use to generate contacts.
+ *
+ * @property nearphase
+ * @type {Nearphase}
+ */
this.nearphase = new Nearphase();
/**
- * Gravity in the world. This is applied on all bodies in the beginning of each step().
- *
- * @property
- * @type {Float32Array}
- */
+ * Gravity in the world. This is applied on all bodies in the beginning of each step().
+ *
+ * @property
+ * @type {Float32Array}
+ */
this.gravity = options.gravity || vec2.fromValues(0, -9.78);
/**
- * Whether to do timing measurements during the step() or not.
- *
- * @property doPofiling
- * @type {Boolean}
- */
+ * Whether to do timing measurements during the step() or not.
+ *
+ * @property doPofiling
+ * @type {Boolean}
+ */
this.doProfiling = options.doProfiling || false;
/**
- * How many millisecconds the last step() took. This is updated each step if .doProfiling is set to true.
- *
- * @property lastStepTime
- * @type {Number}
- */
+ * How many millisecconds the last step() took. This is updated each step if .doProfiling is set to true.
+ *
+ * @property lastStepTime
+ * @type {Number}
+ */
this.lastStepTime = 0.0;
/**
- * The broadphase algorithm to use.
- *
- * @property broadphase
- * @type {Broadphase}
- */
+ * The broadphase algorithm to use.
+ *
+ * @property broadphase
+ * @type {Broadphase}
+ */
this.broadphase = options.broadphase || new NaiveBroadphase();
/**
- * User-added constraints.
- *
- * @property constraints
- * @type {Array}
- */
+ * User-added constraints.
+ *
+ * @property constraints
+ * @type {Array}
+ */
this.constraints = [];
/**
- * Friction between colliding bodies. This value is used if no matching ContactMaterial is found for the body pair.
- * @property defaultFriction
- * @type {Number}
- */
+ * Friction between colliding bodies. This value is used if no matching ContactMaterial is found for the body pair.
+ * @property defaultFriction
+ * @type {Number}
+ */
this.defaultFriction = 0.1;
/**
- * For keeping track of what time step size we used last step
- * @property lastTimeStep
- * @type {Number}
- */
+ * For keeping track of what time step size we used last step
+ * @property lastTimeStep
+ * @type {Number}
+ */
this.lastTimeStep = 1/60;
/**
- * Enable to automatically apply spring forces each step.
- * @property applySpringForces
- * @type {Boolean}
- */
+ * Enable to automatically apply spring forces each step.
+ * @property applySpringForces
+ * @type {Boolean}
+ */
this.applySpringForces = true;
/**
- * Enable/disable constraint solving in each step.
- * @property solveConstraints
- * @type {Boolean}
- */
+ * Enable/disable constraint solving in each step.
+ * @property solveConstraints
+ * @type {Boolean}
+ */
this.solveConstraints = true;
/**
- * The ContactMaterials added to the World.
- * @property contactMaterials
- * @type {Array}
- */
+ * The ContactMaterials added to the World.
+ * @property contactMaterials
+ * @type {Array}
+ */
this.contactMaterials = [];
// Id counters
diff --git a/src/physics/arcade/ArcadePhysics.js b/src/physics/arcade/ArcadePhysics.js
index 60c76c10..b06959e6 100644
--- a/src/physics/arcade/ArcadePhysics.js
+++ b/src/physics/arcade/ArcadePhysics.js
@@ -27,7 +27,7 @@ Phaser.Physics.Arcade = function (game) {
/**
* @property {Phaser.Point} gravity - The World gravity setting. Defaults to x: 0, y: 0, or no gravity.
*/
- this.gravity = new Phaser.Point;
+ this.gravity = new Phaser.Point();
/**
* @property {Phaser.Rectangle} bounds - The bounds inside of which the physics world exists. Defaults to match the world bounds.
@@ -65,13 +65,13 @@ Phaser.Physics.Arcade = function (game) {
* @property {Phaser.Rectangle} _bounds1 - Internal cache var.
* @private
*/
- this._bounds1 = new Phaser.Rectangle;
+ this._bounds1 = new Phaser.Rectangle();
/**
* @property {Phaser.Rectangle} _bounds2 - Internal cache var.
* @private
*/
- this._bounds2 = new Phaser.Rectangle;
+ this._bounds2 = new Phaser.Rectangle();
/**
* @property {number} _overlap - Internal cache var.
@@ -462,7 +462,7 @@ Phaser.Physics.Arcade.prototype = {
{
var currentNode = group._container.first._iNext;
- do
+ do
{
if (currentNode.exists)
{
@@ -572,7 +572,7 @@ Phaser.Physics.Arcade.prototype = {
{
var currentNode = group1._container.first._iNext;
- do
+ do
{
if (currentNode.exists)
{
@@ -658,7 +658,7 @@ Phaser.Physics.Arcade.prototype = {
}
// Then adjust their positions and velocities accordingly (if there was any overlap)
- if (this._overlap != 0)
+ if (this._overlap !== 0)
{
body1.overlapX = this._overlap;
body2.overlapX = this._overlap;
@@ -766,7 +766,7 @@ Phaser.Physics.Arcade.prototype = {
}
// Then adjust their positions and velocities accordingly (if there was any overlap)
- if (this._overlap != 0)
+ if (this._overlap !== 0)
{
body1.overlapY = this._overlap;
body2.overlapY = this._overlap;
@@ -894,7 +894,7 @@ Phaser.Physics.Arcade.prototype = {
}
// Then adjust their positions and velocities accordingly (if there was any overlap)
- if (this._overlap != 0)
+ if (this._overlap !== 0)
{
if (separate)
{
@@ -980,7 +980,7 @@ Phaser.Physics.Arcade.prototype = {
}
// Then adjust their positions and velocities accordingly (if there was any overlap)
- if (this._overlap != 0)
+ if (this._overlap !== 0)
{
if (separate)
{
@@ -1133,7 +1133,7 @@ Phaser.Physics.Arcade.prototype = {
velocityFromAngle: function (angle, speed, point) {
if (typeof speed === 'undefined') { speed = 60; }
- point = point || new Phaser.Point;
+ point = point || new Phaser.Point();
return point.setTo((Math.cos(this.game.math.degToRad(angle)) * speed), (Math.sin(this.game.math.degToRad(angle)) * speed));
@@ -1152,7 +1152,7 @@ Phaser.Physics.Arcade.prototype = {
velocityFromRotation: function (rotation, speed, point) {
if (typeof speed === 'undefined') { speed = 60; }
- point = point || new Phaser.Point;
+ point = point || new Phaser.Point();
return point.setTo((Math.cos(rotation) * speed), (Math.sin(rotation) * speed));
@@ -1171,7 +1171,7 @@ Phaser.Physics.Arcade.prototype = {
accelerationFromRotation: function (rotation, speed, point) {
if (typeof speed === 'undefined') { speed = 60; }
- point = point || new Phaser.Point;
+ point = point || new Phaser.Point();
return point.setTo((Math.cos(rotation) * speed), (Math.sin(rotation) * speed));
diff --git a/src/physics/arcade/Body.js b/src/physics/arcade/Body.js
index c8a5edad..f1441d5e 100644
--- a/src/physics/arcade/Body.js
+++ b/src/physics/arcade/Body.js
@@ -18,91 +18,91 @@ Phaser.Physics.Arcade.Body = function (sprite) {
/**
* @property {Phaser.Sprite} sprite - Reference to the parent Sprite.
*/
- this.sprite = sprite;
+ this.sprite = sprite;
/**
* @property {Phaser.Game} game - Local reference to game.
*/
- this.game = sprite.game;
+ this.game = sprite.game;
/**
* @property {Phaser.Point} offset - The offset of the Physics Body from the Sprite x/y position.
*/
- this.offset = new Phaser.Point;
+ this.offset = new Phaser.Point();
/**
* @property {number} x - The x position of the physics body.
* @readonly
*/
- this.x = sprite.x;
+ this.x = sprite.x;
/**
* @property {number} y - The y position of the physics body.
* @readonly
*/
- this.y = sprite.y;
+ this.y = sprite.y;
/**
* @property {number} preX - The previous x position of the physics body.
* @readonly
*/
- this.preX = sprite.x;
+ this.preX = sprite.x;
/**
* @property {number} preY - The previous y position of the physics body.
* @readonly
*/
- this.preY = sprite.y;
+ this.preY = sprite.y;
/**
* @property {number} preRotation - The previous rotation of the physics body.
* @readonly
*/
- this.preRotation = sprite.angle;
+ this.preRotation = sprite.angle;
/**
* @property {number} screenX - The x position of the physics body translated to screen space.
* @readonly
*/
- this.screenX = sprite.x;
+ this.screenX = sprite.x;
/**
* @property {number} screenY - The y position of the physics body translated to screen space.
* @readonly
*/
- this.screenY = sprite.y;
+ this.screenY = sprite.y;
/**
* @property {number} sourceWidth - The un-scaled original size.
* @readonly
*/
- this.sourceWidth = sprite.currentFrame.sourceSizeW;
+ this.sourceWidth = sprite.currentFrame.sourceSizeW;
/**
* @property {number} sourceHeight - The un-scaled original size.
* @readonly
*/
- this.sourceHeight = sprite.currentFrame.sourceSizeH;
+ this.sourceHeight = sprite.currentFrame.sourceSizeH;
/**
* @property {number} width - The calculated width of the physics body.
*/
- this.width = sprite.currentFrame.sourceSizeW;
+ this.width = sprite.currentFrame.sourceSizeW;
/**
* @property .numInternal ID cache
*/
- this.height = sprite.currentFrame.sourceSizeH;
+ this.height = sprite.currentFrame.sourceSizeH;
/**
* @property {number} halfWidth - The calculated width / 2 of the physics body.
*/
- this.halfWidth = Math.floor(sprite.currentFrame.sourceSizeW / 2);
+ this.halfWidth = Math.floor(sprite.currentFrame.sourceSizeW / 2);
/**
* @property {number} halfHeight - The calculated height / 2 of the physics body.
*/
- this.halfHeight = Math.floor(sprite.currentFrame.sourceSizeH / 2);
+ this.halfHeight = Math.floor(sprite.currentFrame.sourceSizeH / 2);
/**
* @property {Phaser.Point} center - The center coordinate of the Physics Body.
@@ -113,38 +113,38 @@ Phaser.Physics.Arcade.Body = function (sprite) {
* @property {number} _sx - Internal cache var.
* @private
*/
- this._sx = sprite.scale.x;
+ this._sx = sprite.scale.x;
/**
* @property {number} _sy - Internal cache var.
* @private
*/
- this._sy = sprite.scale.y;
+ this._sy = sprite.scale.y;
/**
* @property {Phaser.Point} velocity - The velocity in pixels per second sq. of the Body.
*/
- this.velocity = new Phaser.Point;
+ this.velocity = new Phaser.Point();
/**
* @property {Phaser.Point} acceleration - The velocity in pixels per second sq. of the Body.
*/
- this.acceleration = new Phaser.Point;
+ this.acceleration = new Phaser.Point();
/**
* @property {Phaser.Point} drag - The drag applied to the motion of the Body.
*/
- this.drag = new Phaser.Point;
+ this.drag = new Phaser.Point();
/**
* @property {Phaser.Point} gravity - A private Gravity setting for the Body.
*/
- this.gravity = new Phaser.Point;
+ this.gravity = new Phaser.Point();
/**
* @property {Phaser.Point} bounce - The elasticitiy of the Body when colliding. bounce.x/y = 1 means full rebound, bounce.x/y = 0.5 means 50% rebound velocity.
*/
- this.bounce = new Phaser.Point;
+ this.bounce = new Phaser.Point();
/**
* @property {Phaser.Point} maxVelocity - The maximum velocity in pixels per second sq. that the Body can reach.
@@ -200,7 +200,7 @@ Phaser.Physics.Arcade.Body = function (sprite) {
*/
this.quadTreeIndex = -1;
- // Allow collision
+ // Allow collision
/**
* Set the allowCollision properties to control which directions collision is processed for this Body.
@@ -318,20 +318,20 @@ Phaser.Physics.Arcade.Body.prototype = {
* @method Phaser.Physics.Arcade#updateBounds
* @protected
*/
- updateBounds: function (centerX, centerY, scaleX, scaleY) {
+ updateBounds: function (centerX, centerY, scaleX, scaleY) {
- if (scaleX != this._sx || scaleY != this._sy)
- {
- this.width = this.sourceWidth * scaleX;
- this.height = this.sourceHeight * scaleY;
- this.halfWidth = Math.floor(this.width / 2);
- this.halfHeight = Math.floor(this.height / 2);
- this._sx = scaleX;
- this._sy = scaleY;
+ if (scaleX != this._sx || scaleY != this._sy)
+ {
+ this.width = this.sourceWidth * scaleX;
+ this.height = this.sourceHeight * scaleY;
+ this.halfWidth = Math.floor(this.width / 2);
+ this.halfHeight = Math.floor(this.height / 2);
+ this._sx = scaleX;
+ this._sy = scaleY;
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
- }
+ }
- },
+ },
/**
* Internal method.
@@ -339,55 +339,55 @@ Phaser.Physics.Arcade.Body.prototype = {
* @method Phaser.Physics.Arcade#preUpdate
* @protected
*/
- preUpdate: function () {
+ preUpdate: function () {
- // Store and reset collision flags
- 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;
+ // Store and reset collision flags
+ 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 = true;
- this.touching.up = false;
- this.touching.down = false;
- this.touching.left = false;
- this.touching.right = false;
+ this.touching.none = true;
+ this.touching.up = false;
+ this.touching.down = false;
+ this.touching.left = false;
+ this.touching.right = false;
- this.embedded = false;
+ this.embedded = false;
- 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.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.preRotation = this.sprite.angle;
- this.x = this.preX;
- this.y = this.preY;
- this.rotation = this.preRotation;
+ this.x = this.preX;
+ this.y = this.preY;
+ this.rotation = this.preRotation;
- if (this.moves)
- {
- this.game.physics.updateMotion(this);
+ if (this.moves)
+ {
+ this.game.physics.updateMotion(this);
- if (this.collideWorldBounds)
- {
- this.checkWorldBounds();
- }
+ if (this.collideWorldBounds)
+ {
+ this.checkWorldBounds();
+ }
- this.updateHulls();
+ this.updateHulls();
}
- if (this.skipQuadTree === false && this.allowCollision.none === false && this.sprite.visible && this.sprite.alive)
- {
- this.quadTreeIDs = [];
- this.quadTreeIndex = -1;
- this.game.physics.quadTree.insert(this);
- }
+ if (this.skipQuadTree === false && this.allowCollision.none === false && this.sprite.visible && this.sprite.alive)
+ {
+ this.quadTreeIDs = [];
+ this.quadTreeIndex = -1;
+ this.game.physics.quadTree.insert(this);
+ }
- },
+ },
/**
* Internal method.
@@ -395,25 +395,25 @@ Phaser.Physics.Arcade.Body.prototype = {
* @method Phaser.Physics.Arcade#postUpdate
* @protected
*/
- postUpdate: function () {
+ postUpdate: function () {
- if (this.deltaX() < 0)
- {
- this.facing = Phaser.LEFT;
- }
- else if (this.deltaX() > 0)
- {
- this.facing = Phaser.RIGHT;
- }
+ if (this.deltaX() < 0)
+ {
+ this.facing = Phaser.LEFT;
+ }
+ else if (this.deltaX() > 0)
+ {
+ this.facing = Phaser.RIGHT;
+ }
- if (this.deltaY() < 0)
- {
- this.facing = Phaser.UP;
- }
- else if (this.deltaY() > 0)
- {
- this.facing = Phaser.DOWN;
- }
+ if (this.deltaY() < 0)
+ {
+ this.facing = Phaser.UP;
+ }
+ else if (this.deltaY() > 0)
+ {
+ this.facing = Phaser.DOWN;
+ }
if (this.deltaX() !== 0 || this.deltaY() !== 0)
{
@@ -422,12 +422,12 @@ Phaser.Physics.Arcade.Body.prototype = {
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.
@@ -435,12 +435,12 @@ Phaser.Physics.Arcade.Body.prototype = {
* @method Phaser.Physics.Arcade#updateHulls
* @protected
*/
- updateHulls: function () {
+ updateHulls: function () {
- this.hullX.setTo(this.x, this.preY, this.width, this.height);
- this.hullY.setTo(this.preX, this.y, this.width, this.height);
+ this.hullX.setTo(this.x, this.preY, this.width, this.height);
+ this.hullY.setTo(this.preX, this.y, this.width, this.height);
- },
+ },
/**
* Internal method.
@@ -448,31 +448,31 @@ Phaser.Physics.Arcade.Body.prototype = {
* @method Phaser.Physics.Arcade#checkWorldBounds
* @protected
*/
- checkWorldBounds: function () {
+ checkWorldBounds: function () {
- if (this.x < this.game.world.bounds.x)
- {
- this.x = this.game.world.bounds.x;
- this.velocity.x *= -this.bounce.x;
- }
- else if (this.right > this.game.world.bounds.right)
- {
- this.x = this.game.world.bounds.right - this.width;
- this.velocity.x *= -this.bounce.x;
- }
+ if (this.x < this.game.world.bounds.x)
+ {
+ this.x = this.game.world.bounds.x;
+ this.velocity.x *= -this.bounce.x;
+ }
+ else if (this.right > this.game.world.bounds.right)
+ {
+ this.x = this.game.world.bounds.right - this.width;
+ this.velocity.x *= -this.bounce.x;
+ }
- if (this.y < this.game.world.bounds.y)
- {
- this.y = this.game.world.bounds.y;
- this.velocity.y *= -this.bounce.y;
- }
- else if (this.bottom > this.game.world.bounds.bottom)
- {
- this.y = this.game.world.bounds.bottom - this.height;
- this.velocity.y *= -this.bounce.y;
- }
+ if (this.y < this.game.world.bounds.y)
+ {
+ this.y = this.game.world.bounds.y;
+ this.velocity.y *= -this.bounce.y;
+ }
+ else if (this.bottom > this.game.world.bounds.bottom)
+ {
+ this.y = this.game.world.bounds.bottom - this.height;
+ this.velocity.y *= -this.bounce.y;
+ }
- },
+ },
/**
* You can modify the size of the physics Body to be any dimension you need.
@@ -485,46 +485,46 @@ Phaser.Physics.Arcade.Body.prototype = {
* @param {number} offsetX - The X offset of the Body from the Sprite position.
* @param {number} offsetY - The Y offset of the Body from the Sprite position.
*/
- setSize: function (width, height, offsetX, offsetY) {
+ setSize: function (width, height, offsetX, offsetY) {
- offsetX = offsetX || this.offset.x;
- offsetY = offsetY || this.offset.y;
+ offsetX = offsetX || this.offset.x;
+ offsetY = offsetY || this.offset.y;
- this.sourceWidth = width;
- this.sourceHeight = height;
- 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(offsetX, offsetY);
+ this.sourceWidth = width;
+ this.sourceHeight = height;
+ 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(offsetX, offsetY);
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
- },
+ },
/**
* Resets all Body values (velocity, acceleration, rotation, etc)
*
* @method Phaser.Physics.Arcade#reset
*/
- reset: function () {
+ reset: function () {
- this.velocity.setTo(0, 0);
- this.acceleration.setTo(0, 0);
+ this.velocity.setTo(0, 0);
+ this.acceleration.setTo(0, 0);
- this.angularVelocity = 0;
- this.angularAcceleration = 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.preRotation = this.sprite.angle;
- this.x = this.preX;
- this.y = this.preY;
- this.rotation = this.preRotation;
+ this.x = this.preX;
+ this.y = this.preY;
+ this.rotation = this.preRotation;
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
- },
+ },
/**
* Returns the absolute delta x value.
@@ -591,7 +591,7 @@ Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "bottom", {
* The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
* @method bottom
* @param {number} value
- */
+ */
set: function (value) {
if (value <= this.y)
@@ -618,7 +618,7 @@ Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "right", {
* However it does affect the width property.
* @method right
* @return {number}
- */
+ */
get: function () {
return this.x + this.width;
},
diff --git a/src/pixi/core/Circle.js b/src/pixi/core/Circle.js
index e2728335..3844f426 100644
--- a/src/pixi/core/Circle.js
+++ b/src/pixi/core/Circle.js
@@ -14,24 +14,24 @@
PIXI.Circle = function(x, y, radius)
{
/**
- * @property x
- * @type Number
- * @default 0
- */
+ * @property x
+ * @type Number
+ * @default 0
+ */
this.x = x || 0;
/**
- * @property y
- * @type Number
- * @default 0
- */
+ * @property y
+ * @type Number
+ * @default 0
+ */
this.y = y || 0;
/**
- * @property radius
- * @type Number
- * @default 0
- */
+ * @property radius
+ * @type Number
+ * @default 0
+ */
this.radius = radius || 0;
}
diff --git a/src/pixi/core/Ellipse.js b/src/pixi/core/Ellipse.js
index 1a95d20a..0d05b3ed 100644
--- a/src/pixi/core/Ellipse.js
+++ b/src/pixi/core/Ellipse.js
@@ -15,31 +15,31 @@
PIXI.Ellipse = function(x, y, width, height)
{
/**
- * @property x
- * @type Number
- * @default 0
- */
+ * @property x
+ * @type Number
+ * @default 0
+ */
this.x = x || 0;
/**
- * @property y
- * @type Number
- * @default 0
- */
+ * @property y
+ * @type Number
+ * @default 0
+ */
this.y = y || 0;
/**
- * @property width
- * @type Number
- * @default 0
- */
+ * @property width
+ * @type Number
+ * @default 0
+ */
this.width = width || 0;
/**
- * @property height
- * @type Number
- * @default 0
- */
+ * @property height
+ * @type Number
+ * @default 0
+ */
this.height = height || 0;
}
diff --git a/src/pixi/display/Sprite.js b/src/pixi/display/Sprite.js
index e567c795..bb36f1b1 100644
--- a/src/pixi/display/Sprite.js
+++ b/src/pixi/display/Sprite.js
@@ -26,9 +26,9 @@ PIXI.Sprite = function(texture)
* Setting than anchor to 0.5,0.5 means the textures origin is centered
* Setting the anchor to 1,1 would mean the textures origin points will be the bottom right
*
- * @property anchor
- * @type Point
- */
+ * @property anchor
+ * @type Point
+ */
this.anchor = new PIXI.Point();
/**
diff --git a/src/pixi/loaders/AssetLoader.js b/src/pixi/loaders/AssetLoader.js
index ee3b016a..d984d889 100644
--- a/src/pixi/loaders/AssetLoader.js
+++ b/src/pixi/loaders/AssetLoader.js
@@ -24,26 +24,26 @@ PIXI.AssetLoader = function(assetURLs, crossorigin)
/**
* The array of asset URLs that are going to be loaded
- *
+ *
* @property assetURLs
* @type ArrayTile.
*
@@ -205,7 +204,7 @@ Object.defineProperty(Phaser.Tile.prototype, "right", {
* However it does affect the width property.
* @method right
* @return {number}
- */
+ */
get: function () {
return this.x + this.width;
}
diff --git a/src/tilemap/Tilemap.js b/src/tilemap/Tilemap.js
index e58d1f65..6999ef3a 100644
--- a/src/tilemap/Tilemap.js
+++ b/src/tilemap/Tilemap.js
@@ -1,25 +1,25 @@
Phaser.Tilemap = function (game, key) {
- /**
- * @property {Phaser.Game} game - Description.
- */
+ /**
+ * @property {Phaser.Game} game - Description.
+ */
this.game = game;
/**
* @property {array} layers - Description.
*/
- this.layers;
+ this.layers = null;
if (typeof key === 'string')
{
- this.key = key;
+ this.key = key;
- this.layers = game.cache.getTilemapData(key).layers;
+ this.layers = game.cache.getTilemapData(key).layers;
this.calculateIndexes();
}
else
{
- this.layers = [];
+ this.layers = [];
}
this.currentLayer = 0;
@@ -55,15 +55,15 @@ Phaser.Tilemap.prototype = {
this.currentLayer = this.layers.push({
- name: name,
- width: width,
- height: height,
- alpha: 1,
- visible: true,
- tileMargin: 0,
- tileSpacing: 0,
- format: Phaser.Tilemap.CSV,
- data: data,
+ name: name,
+ width: width,
+ height: height,
+ alpha: 1,
+ visible: true,
+ tileMargin: 0,
+ tileSpacing: 0,
+ format: Phaser.Tilemap.CSV,
+ data: data,
indexes: []
});
@@ -96,10 +96,10 @@ Phaser.Tilemap.prototype = {
setLayer: function (layer) {
- if (this.layers[layer])
- {
- this.currentLayer = layer;
- }
+ if (this.layers[layer])
+ {
+ this.currentLayer = layer;
+ }
},
@@ -114,10 +114,10 @@ Phaser.Tilemap.prototype = {
if (typeof layer === "undefined") { layer = this.currentLayer; }
- if (x >= 0 && x < this.layers[layer].width && y >= 0 && y < this.layers[layer].height)
- {
- this.layers[layer].data[y][x] = index;
- }
+ if (x >= 0 && x < this.layers[layer].width && y >= 0 && y < this.layers[layer].height)
+ {
+ this.layers[layer].data[y][x] = index;
+ }
this.dirty = true;
@@ -273,7 +273,7 @@ Phaser.Tilemap.prototype = {
},
- swapHandler: function (value, index, array) {
+ swapHandler: function (value, index) {
if (value.index === this._tempA)
{
@@ -462,14 +462,14 @@ Phaser.Tilemap.prototype = {
if (this.layers[this.currentLayer].data[y][x] > 1)
{
- if (this.debugMap[this.layers[this.currentLayer].data[y][x]])
- {
- args.push("background: " + this.debugMap[this.layers[this.currentLayer].data[y][x]]);
- }
- else
- {
- args.push("background: #ffffff");
- }
+ if (this.debugMap[this.layers[this.currentLayer].data[y][x]])
+ {
+ args.push("background: " + this.debugMap[this.layers[this.currentLayer].data[y][x]]);
+ }
+ else
+ {
+ args.push("background: #ffffff");
+ }
}
else
{
diff --git a/src/tilemap/TilemapLayer.js b/src/tilemap/TilemapLayer.js
index 7cc4cbd7..61c85357 100644
--- a/src/tilemap/TilemapLayer.js
+++ b/src/tilemap/TilemapLayer.js
@@ -1,33 +1,33 @@
// Maybe should extend Sprite?
Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset, tilemap, layer) {
- /**
- * @property {Phaser.Game} game - Description.
- */
+ /**
+ * @property {Phaser.Game} game - Description.
+ */
this.game = game;
- /**
- * @property {Description} canvas - Description.
- * @default
- */
+ /**
+ * @property {Description} canvas - Description.
+ * @default
+ */
this.canvas = Phaser.Canvas.create(renderWidth, renderHeight);
- /**
- * @property {Description} context - Description.
- * @default
- */
+ /**
+ * @property {Description} context - Description.
+ * @default
+ */
this.context = this.canvas.getContext('2d');
- /**
- * @property {Description} baseTexture - Description.
- * @default
- */
+ /**
+ * @property {Description} baseTexture - Description.
+ * @default
+ */
this.baseTexture = new PIXI.BaseTexture(this.canvas);
- /**
- * @property {Description} texture - Description.
- * @default
- */
+ /**
+ * @property {Description} texture - Description.
+ * @default
+ */
this.texture = new PIXI.Texture(this.baseTexture);
this.textureFrame = new Phaser.Frame(0, 0, 0, renderWidth, renderHeight, 'tilemaplayer', game.rnd.uuid());
@@ -145,18 +145,18 @@ Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset,
/**
* @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
+ * 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;
+ 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
+ * 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;
+ this.scrollFactorY = 1;
this.tilemap = null;
this.layer = null;
@@ -251,14 +251,14 @@ Phaser.TilemapLayer.prototype.updateMapData = function (tilemap, layer) {
*/
Phaser.TilemapLayer.prototype._fixX = function(x) {
- if (this.scrollFactorX === 1)
+ if (this.scrollFactorX === 1)
{
return x;
}
- var left_edge = x - (this._x / this.scrollFactorX);
+ var leftEdge = x - (this._x / this.scrollFactorX);
- return this._x + left_edge;
+ return this._x + leftEdge;
}
@@ -270,14 +270,14 @@ Phaser.TilemapLayer.prototype._fixX = function(x) {
*/
Phaser.TilemapLayer.prototype._unfixX = function(x) {
- if (this.scrollFactorX === 1)
+ if (this.scrollFactorX === 1)
{
return x;
}
- var left_edge = x - this._x;
+ var leftEdge = x - this._x;
- return (this._x / this.scrollFactorX) + left_edge;
+ return (this._x / this.scrollFactorX) + leftEdge;
}
@@ -289,14 +289,14 @@ Phaser.TilemapLayer.prototype._unfixX = function(x) {
*/
Phaser.TilemapLayer.prototype._fixY = function(y) {
- if (this.scrollFactorY === 1)
+ if (this.scrollFactorY === 1)
{
return y;
}
- var top_edge = y - (this._y / this.scrollFactorY);
+ var topEdge = y - (this._y / this.scrollFactorY);
- return this._y + top_edge;
+ return this._y + topEdge;
}
@@ -308,14 +308,14 @@ Phaser.TilemapLayer.prototype._fixY = function(y) {
*/
Phaser.TilemapLayer.prototype._unfixY = function(y) {
- if (this.scrollFactorY === 1)
+ if (this.scrollFactorY === 1)
{
return y;
}
- var top_edge = y - this._y;
+ var topEdge = y - this._y;
- return (this._y / this.scrollFactorY) + top_edge;
+ return (this._y / this.scrollFactorY) + topEdge;
}
@@ -329,7 +329,7 @@ Phaser.TilemapLayer.prototype.getTileX = function (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), tileWidth) / tileWidth;
}
@@ -343,7 +343,7 @@ Phaser.TilemapLayer.prototype.getTileY = function (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), tileHeight) / tileHeight;
}
@@ -384,9 +384,9 @@ Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides
y = 0;
}
- // adjust the x,y coordinates for scrollFactor
- x = this._fixX( x );
- y = this._fixY( y );
+ // adjust the x,y coordinates for scrollFactor
+ x = this._fixX( x );
+ y = this._fixY( y );
if (width > this.widthInPixels)
{
@@ -435,9 +435,9 @@ Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides
if (collides === false || (collides && _tile.collideNone === false))
{
- // convert tile coordinates back to camera space for return
- var _wx = this._unfixX( wx*sx ) / tileWidth;
- var _wy = this._unfixY( wy*sy ) / tileHeight;
+ // 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 });
}
}
diff --git a/src/tilemap/TilemapParser.js b/src/tilemap/TilemapParser.js
index 638ba60d..e3ddd83b 100644
--- a/src/tilemap/TilemapParser.js
+++ b/src/tilemap/TilemapParser.js
@@ -1,183 +1,183 @@
Phaser.TilemapParser = {
- tileset: function (game, key, tileWidth, tileHeight, tileMax, tileMargin, tileSpacing) {
+ tileset: function (game, key, tileWidth, tileHeight, tileMax, tileMargin, tileSpacing) {
- // How big is our image?
- var img = game.cache.getTilesetImage(key);
+ // How big is our image?
+ var img = game.cache.getTilesetImage(key);
- if (img == null)
- {
- return null;
- }
+ if (img == null)
+ {
+ return null;
+ }
- var width = img.width;
- var height = img.height;
+ 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)
- {
- tileWidth = Math.floor(-width / Math.min(-1, tileWidth));
- }
+ // If no tile width/height is given, try and figure it out (won't work if the tileset has margin/spacing)
+ if (tileWidth <= 0)
+ {
+ tileWidth = Math.floor(-width / Math.min(-1, tileWidth));
+ }
- if (tileHeight <= 0)
- {
- tileHeight = Math.floor(-height / Math.min(-1, tileHeight));
- }
+ if (tileHeight <= 0)
+ {
+ tileHeight = Math.floor(-height / Math.min(-1, tileHeight));
+ }
- var row = Math.round(width / tileWidth);
- var column = Math.round(height / tileHeight);
- var total = row * column;
-
- if (tileMax !== -1)
- {
- total = tileMax;
- }
+ var row = Math.round(width / tileWidth);
+ var column = Math.round(height / tileHeight);
+ var total = row * column;
+
+ if (tileMax !== -1)
+ {
+ total = tileMax;
+ }
- // Zero or smaller than tile sizes?
- if (width === 0 || height === 0 || width < tileWidth || height < tileHeight || total === 0)
- {
- console.warn("Phaser.TilemapParser.tileSet: width/height zero or width/height < given tileWidth/tileHeight");
- return null;
- }
+ // Zero or smaller than tile sizes?
+ if (width === 0 || height === 0 || width < tileWidth || height < tileHeight || total === 0)
+ {
+ console.warn("Phaser.TilemapParser.tileSet: width/height zero or width/height < given tileWidth/tileHeight");
+ return null;
+ }
- // Let's create some tiles
- var x = tileMargin;
- var y = tileMargin;
+ // Let's create some tiles
+ var x = tileMargin;
+ var y = tileMargin;
- var tileset = new Phaser.Tileset(img, key, tileWidth, tileHeight, tileMargin, tileSpacing);
+ 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));
+ for (var i = 0; i < total; i++)
+ {
+ tileset.addTile(new Phaser.Tile(tileset, i, x, y, tileWidth, tileHeight));
- x += tileWidth + tileSpacing;
+ x += tileWidth + tileSpacing;
- if (x === width)
- {
- x = tileMargin;
- y += tileHeight + tileSpacing;
- }
- }
+ if (x === width)
+ {
+ x = tileMargin;
+ y += tileHeight + tileSpacing;
+ }
+ }
- return tileset;
+ return tileset;
- },
+ },
- parse: function (game, data, format) {
+ parse: function (game, data, format) {
- if (format === Phaser.Tilemap.CSV)
- {
- return this.parseCSV(data);
- }
- else if (format === Phaser.Tilemap.TILED_JSON)
- {
- return this.parseTiledJSON(data);
- }
+ if (format === Phaser.Tilemap.CSV)
+ {
+ return this.parseCSV(data);
+ }
+ else if (format === Phaser.Tilemap.TILED_JSON)
+ {
+ return this.parseTiledJSON(data);
+ }
- },
+ },
- /**
- * Parse csv map data and generate tiles.
- *
- * @method Phaser.Tilemap.prototype.parseCSV
- * @param {string} data - CSV map data.
- */
- parseCSV: function (data) {
+ /**
+ * Parse csv map data and generate tiles.
+ *
+ * @method Phaser.Tilemap.prototype.parseCSV
+ * @param {string} data - CSV map data.
+ */
+ parseCSV: function (data) {
- // Trim any rogue whitespace from the data
- data = data.trim();
+ // Trim any rogue whitespace from the data
+ data = data.trim();
- var output = [];
- var rows = data.split("\n");
- var height = rows.length;
- var width = 0;
+ var output = [];
+ var rows = data.split("\n");
+ var height = rows.length;
+ var width = 0;
- for (var i = 0; i < rows.length; i++)
- {
- output[i] = [];
+ for (var i = 0; i < rows.length; i++)
+ {
+ output[i] = [];
- var column = rows[i].split(",");
+ var column = rows[i].split(",");
- for (var c = 0; c < column.length; c++)
- {
- output[i][c] = parseInt(column[c]);
- }
+ for (var c = 0; c < column.length; c++)
+ {
+ output[i][c] = parseInt(column[c], 10);
+ }
if (width === 0)
{
- width = column.length;
+ width = column.length;
}
- }
+ }
- return [{ name: 'csv', width: width, height: height, alpha: 1, visible: true, indexes: [], tileMargin: 0, tileSpacing: 0, data: output }];
+ return [{ name: 'csv', width: width, height: height, alpha: 1, visible: true, indexes: [], tileMargin: 0, tileSpacing: 0, data: output }];
- },
+ },
- /**
- * Parse JSON map data and generate tiles.
- *
- * @method Phaser.Tilemap.prototype.parseTiledJSON
- * @param {string} data - JSON map data.
- * @param {string} key - Asset key for tileset image.
- */
- parseTiledJSON: function (json) {
+ /**
+ * Parse JSON map data and generate tiles.
+ *
+ * @method Phaser.Tilemap.prototype.parseTiledJSON
+ * @param {string} data - JSON map data.
+ * @param {string} key - Asset key for tileset image.
+ */
+ parseTiledJSON: function (json) {
- var layers = [];
+ var layers = [];
- for (var i = 0; i < json.layers.length; i++)
- {
- // Check it's a data layer
- if (!json.layers[i].data)
- {
- continue;
- }
+ for (var i = 0; i < json.layers.length; i++)
+ {
+ // Check it's a data layer
+ if (!json.layers[i].data)
+ {
+ continue;
+ }
- // json.tilewidth
- // json.tileheight
+ // json.tilewidth
+ // json.tileheight
- var layer = {
+ var layer = {
- name: json.layers[i].name,
- width: json.layers[i].width,
- height: json.layers[i].height,
- alpha: json.layers[i].opacity,
- visible: json.layers[i].visible,
- indexes: [],
+ name: json.layers[i].name,
+ width: json.layers[i].width,
+ height: json.layers[i].height,
+ alpha: json.layers[i].opacity,
+ visible: json.layers[i].visible,
+ indexes: [],
- tileMargin: json.tilesets[0].margin,
- tileSpacing: json.tilesets[0].spacing,
+ tileMargin: json.tilesets[0].margin,
+ tileSpacing: json.tilesets[0].spacing
- };
+ };
- var output = [];
- var c = 0;
- var row;
+ var output = [];
+ var c = 0;
+ var row;
- for (var t = 0; t < json.layers[i].data.length; t++)
- {
- if (c === 0)
- {
- row = [];
- }
+ for (var t = 0; t < json.layers[i].data.length; t++)
+ {
+ if (c === 0)
+ {
+ row = [];
+ }
- row.push(json.layers[i].data[t]);
- c++;
+ row.push(json.layers[i].data[t]);
+ c++;
- if (c == json.layers[i].width)
- {
- output.push(row);
- c = 0;
- }
- }
+ if (c == json.layers[i].width)
+ {
+ output.push(row);
+ c = 0;
+ }
+ }
- layer.data = output;
-
- layers.push(layer);
+ layer.data = output;
+
+ layers.push(layer);
- }
+ }
- return layers;
+ return layers;
- }
+ }
}
diff --git a/src/tilemap/Tileset.js b/src/tilemap/Tileset.js
index 5d3b3fe1..36e332a0 100644
--- a/src/tilemap/Tileset.js
+++ b/src/tilemap/Tileset.js
@@ -61,7 +61,7 @@ Phaser.Tileset.prototype = {
checkTileIndex: function (index) {
- return (this.tiles[index]);
+ return (this.tiles[index]);
},
@@ -84,7 +84,7 @@ Phaser.Tileset.prototype = {
this.tiles[index].setCollision(left, right, up, down);
}
- },
+ }
}
diff --git a/src/time/Time.js b/src/time/Time.js
index a587542a..7f1ac48c 100644
--- a/src/time/Time.js
+++ b/src/time/Time.js
@@ -20,124 +20,91 @@ Phaser.Time = function (game) {
this.game = game;
/**
- * The time at which the Game instance started.
- * @property {number} _started
+ * @property {number} _started - The time at which the Game instance started.
* @private
- * @default
*/
this._started = 0;
/**
- * The time (in ms) that the last second counter ticked over.
- * @property {number} _timeLastSecond
+ * @property {number} _timeLastSecond - The time (in ms) that the last second counter ticked over.
* @private
- * @default
*/
this._timeLastSecond = 0;
/**
- * The time the game started being paused.
- * @property {number} _pauseStarted
+ * @property {number} _pauseStarted - The time the game started being paused.
* @private
- * @default
*/
this._pauseStarted = 0;
/**
- * The elapsed time calculated for the physics motion updates.
- * @property {number} physicsElapsed
- * @default
+ * @property {number} physicsElapsed - The elapsed time calculated for the physics motion updates.
*/
this.physicsElapsed = 0;
/**
- * Game time counter.
- * @property {number} time
- * @default
+ * @property {number} time - Game time counter.
*/
this.time = 0;
/**
- * Records how long the game has been paused for. Is reset each time the game pauses.
- * @property {number} pausedTime
- * @default
+ * @property {number} pausedTime - Records how long the game has been paused for. Is reset each time the game pauses.
*/
this.pausedTime = 0;
/**
- * The time right now.
- * @property {number} now
- * @default
+ * @property {number} now - The time right now.
*/
this.now = 0;
/**
- * Elapsed time since the last frame.
- * @property {number} elapsed
- * @default
+ * @property {number} elapsed - Elapsed time since the last frame.
*/
this.elapsed = 0;
/**
- * Frames per second.
- * @property {number} fps
- * @default
+ * @property {number} fps - Frames per second.
*/
this.fps = 0;
/**
- * The lowest rate the fps has dropped to.
- * @property {number} fpsMin
- * @default
+ * @property {number} fpsMin - The lowest rate the fps has dropped to.
*/
this.fpsMin = 1000;
/**
- * The highest rate the fps has reached (usually no higher than 60fps).
- * @property {number} fpsMax
- * @default
+ * @property {number} fpsMax - The highest rate the fps has reached (usually no higher than 60fps).
*/
this.fpsMax = 0;
/**
- * The minimum amount of time the game has taken between two frames.
- * @property {number} msMin
+ * @property {number} msMin - The minimum amount of time the game has taken between two frames.
* @default
*/
this.msMin = 1000;
/**
- * The maximum amount of time the game has taken between two frames.
- * @property {number} msMax
- * @default
+ * @property {number} msMax - The maximum amount of time the game has taken between two frames.
*/
this.msMax = 0;
/**
- * The number of frames record in the last second.
- * @property {number} frames
- * @default
+ * @property {number} frames - The number of frames record in the last second.
*/
this.frames = 0;
/**
- * Records how long the game was paused for in miliseconds.
- * @property {number} pauseDuration
- * @default
+ * @property {number} pauseDuration - Records how long the game was paused for in miliseconds.
*/
this.pauseDuration = 0;
/**
- * The value that setTimeout needs to work out when to next update
- * @property {number} timeToCall
- * @default
+ * @property {number} timeToCall - The value that setTimeout needs to work out when to next update
*/
this.timeToCall = 0;
/**
- * Internal value used by timeToCall as part of the setTimeout loop
- * @property {number} lastTime
- * @default
+ * @property {number} lastTime - Internal value used by timeToCall as part of the setTimeout loop
*/
this.lastTime = 0;
@@ -146,9 +113,8 @@ Phaser.Time = function (game) {
this.game.onResume.add(this.gameResumed, this);
/**
- * Internal value used to recover from the game pause state.
- * @property {boolean} _justResumed
- * @default
+ * @property {boolean} _justResumed - Internal value used to recover from the game pause state.
+ * @private
*/
this._justResumed = false;
diff --git a/src/time/Timer.js b/src/time/Timer.js
index 87cf67e0..8677ea46 100644
--- a/src/time/Timer.js
+++ b/src/time/Timer.js
@@ -14,104 +14,104 @@
*/
Phaser.Timer = function (game) {
- /**
- * @property {Phaser.Game} game - Local reference to game.
- */
- this.game = game;
+ /**
+ * @property {Phaser.Game} game - Local reference to game.
+ */
+ this.game = game;
- /**
- * The time at which this Timer instance started.
- * @property {number} _started
- * @private
- * @default
- */
- this._started = 0;
+ /**
+ * The time at which this Timer instance started.
+ * @property {number} _started
+ * @private
+ * @default
+ */
+ this._started = 0;
- /**
- * The time (in ms) that the last second counter ticked over.
- * @property {number} _timeLastSecond
- * @private
- * @default
- */
- this._timeLastSecond = 0;
+ /**
+ * The time (in ms) that the last second counter ticked over.
+ * @property {number} _timeLastSecond
+ * @private
+ * @default
+ */
+ this._timeLastSecond = 0;
- this.running = false;
+ this.running = false;
- this.events = [];
+ this.events = [];
- this.onEvent = new Phaser.Signal();
+ this.onEvent = new Phaser.Signal();
- // Need to add custom FPS rate, for now we'll just use seconds
+ // Need to add custom FPS rate, for now we'll just use seconds
}
Phaser.Timer.prototype = {
- // delay could be from now, when the timer is created, or relative to an already running timer
+ // delay could be from now, when the timer is created, or relative to an already running timer
- // add: function (delay, callback, callbackContext) {
- add: function (delay) {
+ // add: function (delay, callback, callbackContext) {
+ add: function (delay) {
- this.events.push({
- delay: delay,
- dispatched: false,
- args: Array.prototype.splice.call(arguments, 1)
- });
+ this.events.push({
+ delay: delay,
+ dispatched: false,
+ args: Array.prototype.splice.call(arguments, 1)
+ });
- // this.events.push({
- // delay: delay,
- // dispatched: false,
- // callback: callback,
- // callbackContext: callbackContext,
- // args: Array.prototype.splice.call(arguments, 3)
- // });
+ // this.events.push({
+ // delay: delay,
+ // dispatched: false,
+ // callback: callback,
+ // callbackContext: callbackContext,
+ // args: Array.prototype.splice.call(arguments, 3)
+ // });
- },
+ },
- start: function() {
+ start: function() {
- this._started = this.game.time.now;
- this.running = true;
+ 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?
+ // 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?
- },
+ },
- stop: function() {
+ stop: function() {
- this.running = false;
- this.events.length = 0;
+ this.running = false;
+ this.events.length = 0;
- },
+ },
- update: function() {
+ update: function() {
- // TODO: Game Paused support
+ // TODO: Game Paused support
- if (this.running)
- {
- var seconds = this.seconds();
+ if (this.running)
+ {
+ var seconds = this.seconds();
- for (var i = 0, len = this.events.length; i < len; i++)
- {
- 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
- }
- }
- }
+ for (var i = 0, len = this.events.length; i < len; i++)
+ {
+ 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
+ }
+ }
+ }
- },
+ },
- seconds: function() {
- return (this.game.time.now - this._started) * 0.001;
- }
+ seconds: function() {
+ return (this.game.time.now - this._started) * 0.001;
+ }
}
\ No newline at end of file
diff --git a/src/tween/Easing.js b/src/tween/Easing.js
index bb52f087..96dbcd79 100644
--- a/src/tween/Easing.js
+++ b/src/tween/Easing.js
@@ -1,3 +1,5 @@
+/* jshint curly: false */
+
/**
* @author Richard Davey