mirror of
https://github.com/photonstorm/phaser
synced 2024-12-04 02:20:23 +00:00
The entire Phaser library has been updated to match the new JSHint configuration.
This commit is contained in:
parent
13a2cc2feb
commit
299115ca5d
74 changed files with 4992 additions and 4977 deletions
|
@ -42,6 +42,7 @@ Change Log
|
||||||
Version 1.1.3 - in build
|
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: 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 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: 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.
|
* 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: 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: 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: 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: 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: 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: 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.
|
* 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
|
You can view the complete Change Log for all previous versions at https://github.com/photonstorm/phaser/changelog.md
|
||||||
|
|
||||||
How to Build
|
How to Build
|
||||||
|
|
356
src/PixiPatch.js
356
src/PixiPatch.js
|
@ -16,238 +16,240 @@
|
||||||
*/
|
*/
|
||||||
PIXI.CanvasRenderer.prototype.render = function(stage)
|
PIXI.CanvasRenderer.prototype.render = function(stage)
|
||||||
{
|
{
|
||||||
PIXI.texturesToUpdate.length = 0;
|
PIXI.texturesToUpdate.length = 0;
|
||||||
PIXI.texturesToDestroy.length = 0;
|
PIXI.texturesToDestroy.length = 0;
|
||||||
|
|
||||||
PIXI.visibleCount++;
|
PIXI.visibleCount++;
|
||||||
stage.updateTransform();
|
stage.updateTransform();
|
||||||
|
|
||||||
// update the background color
|
// update the background color
|
||||||
// if(this.view.style.backgroundColor!=stage.backgroundColorString && !this.transparent)this.view.style.backgroundColor = stage.backgroundColorString;
|
// 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.setTransform(1, 0, 0, 1, 0, 0);
|
||||||
// this.context.clearRect(0, 0, this.width, this.height)
|
// this.context.clearRect(0, 0, this.width, this.height)
|
||||||
this.renderDisplayObject(stage);
|
this.renderDisplayObject(stage);
|
||||||
|
|
||||||
// Remove frame updates
|
// Remove frame updates
|
||||||
if (PIXI.Texture.frameUpdates.length > 0)
|
if (PIXI.Texture.frameUpdates.length > 0)
|
||||||
{
|
{
|
||||||
PIXI.Texture.frameUpdates.length = 0;
|
PIXI.Texture.frameUpdates.length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject)
|
PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject)
|
||||||
{
|
{
|
||||||
// Once the display object hits this we can break the loop
|
// Once the display object hits this we can break the loop
|
||||||
var testObject = displayObject.last._iNext;
|
var testObject = displayObject.last._iNext;
|
||||||
displayObject = displayObject.first;
|
displayObject = displayObject.first;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
//transform = displayObject.worldTransform;
|
//transform = displayObject.worldTransform;
|
||||||
|
|
||||||
if (!displayObject.visible)
|
if (!displayObject.visible)
|
||||||
{
|
{
|
||||||
displayObject = displayObject.last._iNext;
|
displayObject = displayObject.last._iNext;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!displayObject.renderable || displayObject.alpha === 0)
|
if (!displayObject.renderable || displayObject.alpha === 0)
|
||||||
{
|
{
|
||||||
displayObject = displayObject._iNext;
|
displayObject = displayObject._iNext;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (displayObject instanceof PIXI.Sprite)
|
if (displayObject instanceof PIXI.Sprite)
|
||||||
{
|
{
|
||||||
// var frame = displayObject.texture.frame;
|
// var frame = displayObject.texture.frame;
|
||||||
|
|
||||||
if (displayObject.texture.frame)
|
if (displayObject.texture.frame)
|
||||||
{
|
{
|
||||||
this.context.globalAlpha = displayObject.worldAlpha;
|
this.context.globalAlpha = displayObject.worldAlpha;
|
||||||
|
|
||||||
if (displayObject.texture.trimmed)
|
if (displayObject.texture.trimmed)
|
||||||
{
|
{
|
||||||
this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2] + displayObject.texture.trim.x, displayObject.worldTransform[5] + displayObject.texture.trim.y);
|
this.context.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
|
else
|
||||||
{
|
{
|
||||||
this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2], displayObject.worldTransform[5]);
|
this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2], displayObject.worldTransform[5]);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.context.drawImage(
|
this.context.drawImage(
|
||||||
displayObject.texture.baseTexture.source,
|
displayObject.texture.baseTexture.source,
|
||||||
displayObject.texture.frame.x,
|
displayObject.texture.frame.x,
|
||||||
displayObject.texture.frame.y,
|
displayObject.texture.frame.y,
|
||||||
displayObject.texture.frame.width,
|
displayObject.texture.frame.width,
|
||||||
displayObject.texture.frame.height,
|
displayObject.texture.frame.height,
|
||||||
(displayObject.anchor.x) * -displayObject.texture.frame.width,
|
(displayObject.anchor.x) * -displayObject.texture.frame.width,
|
||||||
(displayObject.anchor.y) * -displayObject.texture.frame.height,
|
(displayObject.anchor.y) * -displayObject.texture.frame.height,
|
||||||
displayObject.texture.frame.width,
|
displayObject.texture.frame.width,
|
||||||
displayObject.texture.frame.height);
|
displayObject.texture.frame.height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (displayObject instanceof PIXI.Strip)
|
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.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2], displayObject.worldTransform[5])
|
||||||
this.renderStrip(displayObject);
|
this.renderStrip(displayObject);
|
||||||
}
|
}
|
||||||
else if (displayObject instanceof PIXI.TilingSprite)
|
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.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2], displayObject.worldTransform[5])
|
||||||
this.renderTilingSprite(displayObject);
|
this.renderTilingSprite(displayObject);
|
||||||
}
|
}
|
||||||
else if (displayObject instanceof PIXI.CustomRenderable)
|
else if (displayObject instanceof PIXI.CustomRenderable)
|
||||||
{
|
{
|
||||||
displayObject.renderCanvas(this);
|
displayObject.renderCanvas(this);
|
||||||
}
|
}
|
||||||
else if (displayObject instanceof PIXI.Graphics)
|
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])
|
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);
|
PIXI.CanvasGraphics.renderGraphics(displayObject, this.context);
|
||||||
}
|
}
|
||||||
else if (displayObject instanceof PIXI.FilterBlock)
|
else if (displayObject instanceof PIXI.FilterBlock)
|
||||||
{
|
{
|
||||||
if (displayObject.open)
|
if (displayObject.open)
|
||||||
{
|
{
|
||||||
this.context.save();
|
this.context.save();
|
||||||
|
|
||||||
var cacheAlpha = displayObject.mask.alpha;
|
var cacheAlpha = displayObject.mask.alpha;
|
||||||
var maskTransform = displayObject.mask.worldTransform;
|
var maskTransform = displayObject.mask.worldTransform;
|
||||||
|
|
||||||
this.context.setTransform(maskTransform[0], maskTransform[3], maskTransform[1], maskTransform[4], maskTransform[2], maskTransform[5])
|
this.context.setTransform(maskTransform[0], maskTransform[3], maskTransform[1], maskTransform[4], maskTransform[2], maskTransform[5])
|
||||||
|
|
||||||
displayObject.mask.worldAlpha = 0.5;
|
displayObject.mask.worldAlpha = 0.5;
|
||||||
|
|
||||||
this.context.worldAlpha = 0;
|
this.context.worldAlpha = 0;
|
||||||
|
|
||||||
PIXI.CanvasGraphics.renderGraphicsMask(displayObject.mask, this.context);
|
PIXI.CanvasGraphics.renderGraphicsMask(displayObject.mask, this.context);
|
||||||
this.context.clip();
|
this.context.clip();
|
||||||
|
|
||||||
displayObject.mask.worldAlpha = cacheAlpha;
|
displayObject.mask.worldAlpha = cacheAlpha;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.context.restore();
|
this.context.restore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// count++
|
// count++
|
||||||
displayObject = displayObject._iNext;
|
displayObject = displayObject._iNext;
|
||||||
}
|
}
|
||||||
while(displayObject != testObject)
|
while(displayObject != testObject)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PIXI.WebGLBatch.prototype.update = function()
|
PIXI.WebGLBatch.prototype.update = function()
|
||||||
{
|
{
|
||||||
var gl = this.gl;
|
// var gl = this.gl;
|
||||||
var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index, index2, index3
|
// var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index, 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)
|
var displayObject = this.head;
|
||||||
{
|
|
||||||
if(displayObject.vcount === PIXI.visibleCount)
|
|
||||||
{
|
|
||||||
width = displayObject.texture.frame.width;
|
|
||||||
height = displayObject.texture.frame.height;
|
|
||||||
|
|
||||||
// TODO trim??
|
while(displayObject)
|
||||||
aX = displayObject.anchor.x;// - displayObject.texture.trim.x
|
{
|
||||||
aY = displayObject.anchor.y; //- displayObject.texture.trim.y
|
if(displayObject.vcount === PIXI.visibleCount)
|
||||||
w0 = width * (1-aX);
|
{
|
||||||
w1 = width * -aX;
|
width = displayObject.texture.frame.width;
|
||||||
|
height = displayObject.texture.frame.height;
|
||||||
|
|
||||||
h0 = height * (1-aY);
|
// TODO trim??
|
||||||
h1 = height * -aY;
|
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];
|
worldTransform = displayObject.worldTransform;
|
||||||
b = worldTransform[3];
|
|
||||||
c = worldTransform[1];
|
|
||||||
d = worldTransform[4];
|
|
||||||
tx = worldTransform[2];
|
|
||||||
ty = worldTransform[5];
|
|
||||||
|
|
||||||
if (displayObject.texture.trimmed)
|
a = worldTransform[0];
|
||||||
{
|
b = worldTransform[3];
|
||||||
tx += displayObject.texture.trim.x;
|
c = worldTransform[1];
|
||||||
ty += displayObject.texture.trim.y;
|
d = worldTransform[4];
|
||||||
}
|
tx = worldTransform[2];
|
||||||
|
ty = worldTransform[5];
|
||||||
|
|
||||||
this.verticies[index + 0 ] = a * w1 + c * h1 + tx;
|
if (displayObject.texture.trimmed)
|
||||||
this.verticies[index + 1 ] = d * h1 + b * w1 + ty;
|
{
|
||||||
|
tx += displayObject.texture.trim.x;
|
||||||
|
ty += displayObject.texture.trim.y;
|
||||||
|
}
|
||||||
|
|
||||||
this.verticies[index + 2 ] = a * w0 + c * h1 + tx;
|
this.verticies[index + 0 ] = a * w1 + c * h1 + tx;
|
||||||
this.verticies[index + 3 ] = d * h1 + b * w0 + ty;
|
this.verticies[index + 1 ] = d * h1 + b * w1 + ty;
|
||||||
|
|
||||||
this.verticies[index + 4 ] = a * w0 + c * h0 + tx;
|
this.verticies[index + 2 ] = a * w0 + c * h1 + tx;
|
||||||
this.verticies[index + 5 ] = d * h0 + b * w0 + ty;
|
this.verticies[index + 3 ] = d * h1 + b * w0 + ty;
|
||||||
|
|
||||||
this.verticies[index + 6] = a * w1 + c * h0 + tx;
|
this.verticies[index + 4 ] = a * w0 + c * h0 + tx;
|
||||||
this.verticies[index + 7] = d * h0 + b * w1 + ty;
|
this.verticies[index + 5 ] = d * h0 + b * w0 + ty;
|
||||||
|
|
||||||
if(displayObject.updateFrame || displayObject.texture.updateFrame)
|
this.verticies[index + 6] = a * w1 + c * h0 + tx;
|
||||||
{
|
this.verticies[index + 7] = d * h0 + b * w1 + ty;
|
||||||
this.dirtyUVS = true;
|
|
||||||
|
|
||||||
var texture = displayObject.texture;
|
if(displayObject.updateFrame || displayObject.texture.updateFrame)
|
||||||
|
{
|
||||||
|
this.dirtyUVS = true;
|
||||||
|
|
||||||
var frame = texture.frame;
|
var texture = displayObject.texture;
|
||||||
var tw = texture.baseTexture.width;
|
|
||||||
var th = texture.baseTexture.height;
|
|
||||||
|
|
||||||
this.uvs[index + 0] = frame.x / tw;
|
var frame = texture.frame;
|
||||||
this.uvs[index +1] = frame.y / th;
|
var tw = texture.baseTexture.width;
|
||||||
|
var th = texture.baseTexture.height;
|
||||||
|
|
||||||
this.uvs[index +2] = (frame.x + frame.width) / tw;
|
this.uvs[index + 0] = frame.x / tw;
|
||||||
this.uvs[index +3] = frame.y / th;
|
this.uvs[index +1] = frame.y / th;
|
||||||
|
|
||||||
this.uvs[index +4] = (frame.x + frame.width) / tw;
|
this.uvs[index +2] = (frame.x + frame.width) / tw;
|
||||||
this.uvs[index +5] = (frame.y + frame.height) / th;
|
this.uvs[index +3] = frame.y / th;
|
||||||
|
|
||||||
this.uvs[index +6] = frame.x / tw;
|
this.uvs[index +4] = (frame.x + frame.width) / tw;
|
||||||
this.uvs[index +7] = (frame.y + frame.height) / th;
|
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....
|
displayObject.updateFrame = false;
|
||||||
if(displayObject.cacheAlpha != displayObject.worldAlpha)
|
}
|
||||||
{
|
|
||||||
displayObject.cacheAlpha = displayObject.worldAlpha;
|
|
||||||
|
|
||||||
var colorIndex = indexRun * 4;
|
// TODO this probably could do with some optimisation....
|
||||||
this.colors[colorIndex] = this.colors[colorIndex + 1] = this.colors[colorIndex + 2] = this.colors[colorIndex + 3] = displayObject.worldAlpha;
|
if(displayObject.cacheAlpha != displayObject.worldAlpha)
|
||||||
this.dirtyColors = true;
|
{
|
||||||
}
|
displayObject.cacheAlpha = displayObject.worldAlpha;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
index = indexRun * 8;
|
|
||||||
|
|
||||||
this.verticies[index + 0 ] = 0;
|
var colorIndex = indexRun * 4;
|
||||||
this.verticies[index + 1 ] = 0;
|
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 + 0 ] = 0;
|
||||||
this.verticies[index + 3 ] = 0;
|
this.verticies[index + 1 ] = 0;
|
||||||
|
|
||||||
this.verticies[index + 4 ] = 0;
|
this.verticies[index + 2 ] = 0;
|
||||||
this.verticies[index + 5 ] = 0;
|
this.verticies[index + 3 ] = 0;
|
||||||
|
|
||||||
this.verticies[index + 6] = 0;
|
this.verticies[index + 4 ] = 0;
|
||||||
this.verticies[index + 7] = 0;
|
this.verticies[index + 5 ] = 0;
|
||||||
}
|
|
||||||
|
|
||||||
indexRun++;
|
this.verticies[index + 6] = 0;
|
||||||
displayObject = displayObject.__next;
|
this.verticies[index + 7] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
indexRun++;
|
||||||
|
displayObject = displayObject.__next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
* Sets the given property to the given value on the child. The operation controls the assignment of the value.
|
||||||
*
|
*
|
||||||
* @method Phaser.Group#setProperty
|
* @method Phaser.Group#setProperty
|
||||||
* @param {*} child - The child to set the property value on.
|
* @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 {array} key - An array of strings that make up the property that will be set.
|
||||||
* @param {*} value - The value 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.
|
* @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) {
|
setProperty: function (child, key, value, operation) {
|
||||||
|
|
||||||
operation = operation || 0;
|
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.
|
* 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.
|
* The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication.
|
||||||
*
|
*
|
||||||
* @method Phaser.Group#setAll
|
* @method Phaser.Group#setAll
|
||||||
* @param {string} key - The property, as a string, to be set. For example: 'body.velocity.x'
|
* @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 {*} value - The value that will be set.
|
||||||
* @param {boolean} [checkAlive=false] - If set then only children with alive=true will be updated.
|
* @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 {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.
|
* @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) {
|
setAll: function (key, value, checkAlive, checkVisible, operation) {
|
||||||
|
|
||||||
key = key.split('.');
|
key = key.split('.');
|
||||||
|
@ -671,15 +671,15 @@ Phaser.Group.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the amount to the given property on all children in this Group.
|
* 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.
|
* Group.addAll('x', 10) will add 10 to the child.x value.
|
||||||
*
|
*
|
||||||
* @method Phaser.Group#addAll
|
* @method Phaser.Group#addAll
|
||||||
* @param {string} property - The property to increment, for example 'body.velocity.x' or 'angle'.
|
* @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 {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} 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.
|
* @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
|
||||||
*/
|
*/
|
||||||
addAll: function (property, amount, checkAlive, checkVisible) {
|
addAll: function (property, amount, checkAlive, checkVisible) {
|
||||||
|
|
||||||
this.setAll(property, amount, checkAlive, checkVisible, 1);
|
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.
|
* 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.
|
* Group.subAll('x', 10) will minus 10 from the child.x value.
|
||||||
*
|
*
|
||||||
* @method Phaser.Group#subAll
|
* @method Phaser.Group#subAll
|
||||||
* @param {string} property - The property to decrement, for example 'body.velocity.x' or 'angle'.
|
* @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 {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} 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.
|
* @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
|
||||||
*/
|
*/
|
||||||
subAll: function (property, amount, checkAlive, checkVisible) {
|
subAll: function (property, amount, checkAlive, checkVisible) {
|
||||||
|
|
||||||
this.setAll(property, amount, checkAlive, checkVisible, 2);
|
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.
|
* Multiplies the given property by the amount on all children in this Group.
|
||||||
* Group.multiplyAll('x', 2) will x2 the child.x value.
|
* Group.multiplyAll('x', 2) will x2 the child.x value.
|
||||||
*
|
*
|
||||||
* @method Phaser.Group#multiplyAll
|
* @method Phaser.Group#multiplyAll
|
||||||
* @param {string} property - The property to multiply, for example 'body.velocity.x' or 'angle'.
|
* @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 {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} 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.
|
* @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
|
||||||
*/
|
*/
|
||||||
multiplyAll: function (property, amount, checkAlive, checkVisible) {
|
multiplyAll: function (property, amount, checkAlive, checkVisible) {
|
||||||
|
|
||||||
this.setAll(property, amount, checkAlive, checkVisible, 3);
|
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.
|
* Divides the given property by the amount on all children in this Group.
|
||||||
* Group.divideAll('x', 2) will half the child.x value.
|
* Group.divideAll('x', 2) will half the child.x value.
|
||||||
*
|
*
|
||||||
* @method Phaser.Group#divideAll
|
* @method Phaser.Group#divideAll
|
||||||
* @param {string} property - The property to divide, for example 'body.velocity.x' or 'angle'.
|
* @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 {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} 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.
|
* @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
|
||||||
*/
|
*/
|
||||||
divideAll: function (property, amount, checkAlive, checkVisible) {
|
divideAll: function (property, amount, checkAlive, checkVisible) {
|
||||||
|
|
||||||
this.setAll(property, amount, checkAlive, checkVisible, 4);
|
this.setAll(property, amount, checkAlive, checkVisible, 4);
|
||||||
|
|
|
@ -127,10 +127,10 @@ Phaser.PluginManager.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a Plugin from the PluginManager.
|
* Remove a Plugin from the PluginManager.
|
||||||
* @method Phaser.PluginManager#remove
|
* @method Phaser.PluginManager#remove
|
||||||
* @param {Phaser.Plugin} plugin - The plugin to be removed.
|
* @param {Phaser.Plugin} plugin - The plugin to be removed.
|
||||||
*/
|
*/
|
||||||
remove: function (plugin) {
|
remove: function (plugin) {
|
||||||
|
|
||||||
if (this._pluginsLength === 0)
|
if (this._pluginsLength === 0)
|
||||||
|
@ -151,9 +151,9 @@ Phaser.PluginManager.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all Plugins from the PluginManager.
|
* Removes all Plugins from the PluginManager.
|
||||||
* @method Phaser.PluginManager#removeAll
|
* @method Phaser.PluginManager#removeAll
|
||||||
*/
|
*/
|
||||||
removeAll: function() {
|
removeAll: function() {
|
||||||
|
|
||||||
for (this._p = 0; this._p < this._pluginsLength; this._p++)
|
for (this._p = 0; this._p < this._pluginsLength; this._p++)
|
||||||
|
|
|
@ -73,14 +73,14 @@ Phaser.Signal.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method Phaser.Signal#_registerListener
|
* @method Phaser.Signal#_registerListener
|
||||||
* @param {function} listener - Signal handler function.
|
* @param {function} listener - Signal handler function.
|
||||||
* @param {boolean} isOnce - Description.
|
* @param {boolean} isOnce - Description.
|
||||||
* @param {object} [listenerContext] - 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).
|
* @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.
|
* @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_registerListener: function (listener, isOnce, listenerContext, priority) {
|
_registerListener: function (listener, isOnce, listenerContext, priority) {
|
||||||
|
|
||||||
var prevIndex = this._indexOfListener(listener, listenerContext),
|
var prevIndex = this._indexOfListener(listener, listenerContext),
|
||||||
|
@ -104,10 +104,10 @@ Phaser.Signal.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method Phaser.Signal#_addBinding
|
* @method Phaser.Signal#_addBinding
|
||||||
* @param {Phaser.SignalBinding} binding - An Object representing the binding between the Signal and listener.
|
* @param {Phaser.SignalBinding} binding - An Object representing the binding between the Signal and listener.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_addBinding: function (binding) {
|
_addBinding: function (binding) {
|
||||||
//simplified insertion sort
|
//simplified insertion sort
|
||||||
var n = this._bindings.length;
|
var n = this._bindings.length;
|
||||||
|
@ -116,11 +116,11 @@ Phaser.Signal.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method Phaser.Signal#_indexOfListener
|
* @method Phaser.Signal#_indexOfListener
|
||||||
* @param {function} listener - Signal handler function.
|
* @param {function} listener - Signal handler function.
|
||||||
* @return {number} Description.
|
* @return {number} Description.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_indexOfListener: function (listener, context) {
|
_indexOfListener: function (listener, context) {
|
||||||
var n = this._bindings.length,
|
var n = this._bindings.length,
|
||||||
cur;
|
cur;
|
||||||
|
@ -134,26 +134,26 @@ Phaser.Signal.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if listener was attached to Signal.
|
* Check if listener was attached to Signal.
|
||||||
*
|
*
|
||||||
* @method Phaser.Signal#has
|
* @method Phaser.Signal#has
|
||||||
* @param {Function} listener - Signal handler function.
|
* @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).
|
* @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.
|
* @return {boolean} If Signal has the specified listener.
|
||||||
*/
|
*/
|
||||||
has: function (listener, context) {
|
has: function (listener, context) {
|
||||||
return this._indexOfListener(listener, context) !== -1;
|
return this._indexOfListener(listener, context) !== -1;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a listener to the signal.
|
* Add a listener to the signal.
|
||||||
*
|
*
|
||||||
* @method Phaser.Signal#add
|
* @method Phaser.Signal#add
|
||||||
* @param {function} listener - Signal handler function.
|
* @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 {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).
|
* @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.
|
* @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
|
||||||
*/
|
*/
|
||||||
add: function (listener, listenerContext, priority) {
|
add: function (listener, listenerContext, priority) {
|
||||||
this.validateListener(listener, 'add');
|
this.validateListener(listener, 'add');
|
||||||
return this._registerListener(listener, false, listenerContext, priority);
|
return this._registerListener(listener, false, listenerContext, priority);
|
||||||
|
|
|
@ -58,8 +58,8 @@ Phaser.Stage = function (game, width, height) {
|
||||||
this.scale = new Phaser.StageScaleMode(this.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;
|
this.aspectRatio = width / height;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -172,10 +172,10 @@ Phaser.StateManager.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete the given state.
|
* Delete the given state.
|
||||||
* @method Phaser.StateManager#remove
|
* @method Phaser.StateManager#remove
|
||||||
* @param {string} key - A unique key you use to reference this state, i.e. "MainMenu", "Level1".
|
* @param {string} key - A unique key you use to reference this state, i.e. "MainMenu", "Level1".
|
||||||
*/
|
*/
|
||||||
remove: function (key) {
|
remove: function (key) {
|
||||||
|
|
||||||
if (this.current == key)
|
if (this.current == key)
|
||||||
|
|
|
@ -172,7 +172,7 @@ Phaser.BitmapData.prototype = {
|
||||||
{
|
{
|
||||||
this.data32[y * this.width + x] = (red << 24) | (green << 16) | (blue << 8) | alpha;
|
this.data32[y * this.width + x] = (red << 24) | (green << 16) | (blue << 8) | alpha;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// this.imageData.data.set(this.data8);
|
// this.imageData.data.set(this.data8);
|
||||||
|
|
||||||
|
@ -229,10 +229,10 @@ Phaser.BitmapData.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get pixels in array in a specific Rectangle.
|
* Get pixels in array in a specific Rectangle.
|
||||||
* @param rect {Rectangle} The specific Rectangle.
|
* @param rect {Rectangle} The specific Rectangle.
|
||||||
* @return {array} CanvasPixelArray.
|
* @return {array} CanvasPixelArray.
|
||||||
*/
|
*/
|
||||||
getPixels: function (rect) {
|
getPixels: function (rect) {
|
||||||
|
|
||||||
return this.context.getImageData(rect.x, rect.y, rect.width, rect.height);
|
return this.context.getImageData(rect.x, rect.y, rect.width, rect.height);
|
||||||
|
|
|
@ -21,10 +21,14 @@ Phaser.BitmapText = function (game, x, y, text, style) {
|
||||||
|
|
||||||
x = x || 0;
|
x = x || 0;
|
||||||
y = y || 0;
|
y = y || 0;
|
||||||
|
|
||||||
text = text || '';
|
text = text || '';
|
||||||
style = style || '';
|
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.
|
* @property {boolean} exists - If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all.
|
||||||
* @default
|
* @default
|
||||||
|
@ -38,53 +42,51 @@ Phaser.BitmapText = function (game, x, y, text, style) {
|
||||||
this.alive = true;
|
this.alive = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Description} group - Description.
|
* @property {Phaser.Group} group - The parent Group of this BitmapText.
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this.group = null;
|
this.group = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {string} name - Description.
|
* @property {string} name - The user defined name given to this BitmapText.
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.name = '';
|
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);
|
PIXI.BitmapText.call(this, text, style);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Description} type - Description.
|
* @property {number} position.x - The x position of this object.
|
||||||
*/
|
|
||||||
this.type = Phaser.BITMAPTEXT;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @property {number} position.x - Description.
|
|
||||||
*/
|
*/
|
||||||
this.position.x = x;
|
this.position.x = x;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} position.y - Description.
|
* @property {number} position.y - The y position of this object.
|
||||||
*/
|
*/
|
||||||
this.position.y = y;
|
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();
|
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);
|
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
|
* @private
|
||||||
*/
|
*/
|
||||||
this._cache = {
|
this._cache = {
|
||||||
|
@ -114,15 +116,13 @@ Phaser.BitmapText = function (game, x, y, text, style) {
|
||||||
this._cache.y = this.y;
|
this._cache.y = this.y;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {boolean} renderable - Description.
|
* @property {boolean} renderable - A renderable object will be rendered to the context each frame.
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
this.renderable = true;
|
this.renderable = true;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Phaser.BitmapText.prototype = Object.create(PIXI.BitmapText.prototype);
|
Phaser.BitmapText.prototype = Object.create(PIXI.BitmapText.prototype);
|
||||||
// Phaser.BitmapText.prototype = Phaser.Utils.extend(true, PIXI.BitmapText.prototype);
|
|
||||||
Phaser.BitmapText.prototype.constructor = Phaser.BitmapText;
|
Phaser.BitmapText.prototype.constructor = Phaser.BitmapText;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -180,11 +180,11 @@ Phaser.BitmapText.prototype.destroy = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get
|
* 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.
|
||||||
* @returns {Description}
|
* 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.
|
||||||
* Set
|
* @name Phaser.BitmapText#angle
|
||||||
* @param {Description} value - Description
|
* @property {number} angle - Gets or sets the angle of rotation in degrees.
|
||||||
*/
|
*/
|
||||||
Object.defineProperty(Phaser.BitmapText.prototype, 'angle', {
|
Object.defineProperty(Phaser.BitmapText.prototype, 'angle', {
|
||||||
|
|
||||||
|
@ -199,11 +199,9 @@ Object.defineProperty(Phaser.BitmapText.prototype, 'angle', {
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get
|
* The x coordinate of this object in world space.
|
||||||
* @returns {Description}
|
* @name Phaser.BitmapText#x
|
||||||
*//**
|
* @property {number} x - The x coordinate of this object in world space.
|
||||||
* Set
|
|
||||||
* @param {Description} value - Description
|
|
||||||
*/
|
*/
|
||||||
Object.defineProperty(Phaser.BitmapText.prototype, 'x', {
|
Object.defineProperty(Phaser.BitmapText.prototype, 'x', {
|
||||||
|
|
||||||
|
@ -218,11 +216,9 @@ Object.defineProperty(Phaser.BitmapText.prototype, 'x', {
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get
|
* The y coordinate of this object in world space.
|
||||||
* @returns {Description}
|
* @name Phaser.BitmapText#y
|
||||||
*//**
|
* @property {number} y - The y coordinate of this object in world space.
|
||||||
* Set
|
|
||||||
* @param {Description} value - Description
|
|
||||||
*/
|
*/
|
||||||
Object.defineProperty(Phaser.BitmapText.prototype, 'y', {
|
Object.defineProperty(Phaser.BitmapText.prototype, 'y', {
|
||||||
|
|
||||||
|
|
|
@ -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
|
* @method Phaser.GameObjectFactory#audio
|
||||||
* @param {string} key - The Game.cache key of the sound that this object will use.
|
* @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 {number} volume - The volume at which the sound will be played.
|
||||||
* @param {boolean} loop - Whether or not the sound will loop.
|
* @param {boolean} loop - Whether or not the sound will loop.
|
||||||
* @return {Phaser.Sound} The newly created text object.
|
* @return {Phaser.Sound} The newly created text object.
|
||||||
*/
|
*/
|
||||||
audio: function (key, volume, loop) {
|
audio: function (key, volume, loop) {
|
||||||
|
|
||||||
return this.game.sound.add(key, volume, loop);
|
return this.game.sound.add(key, volume, loop);
|
||||||
|
@ -115,17 +115,17 @@ Phaser.GameObjectFactory.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new <code>TileSprite</code>.
|
* Creates a new <code>TileSprite</code>.
|
||||||
*
|
*
|
||||||
* @method Phaser.GameObjectFactory#tileSprite
|
* @method Phaser.GameObjectFactory#tileSprite
|
||||||
* @param {number} x - X position of the new tileSprite.
|
* @param {number} x - X position of the new tileSprite.
|
||||||
* @param {number} y - Y position of the new tileSprite.
|
* @param {number} y - Y position of the new tileSprite.
|
||||||
* @param {number} width - the width of the tilesprite.
|
* @param {number} width - the width of the tilesprite.
|
||||||
* @param {number} height - the height 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|Phaser.RenderTexture|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture.
|
||||||
* @param {string|number} frame - If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
|
* @param {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.
|
* @return {Phaser.TileSprite} The newly created tileSprite object.
|
||||||
*/
|
*/
|
||||||
tileSprite: function (x, y, width, height, key, frame) {
|
tileSprite: function (x, y, width, height, key, frame) {
|
||||||
|
|
||||||
return this.world.add(new Phaser.TileSprite(this.game, 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 <code>Text</code>.
|
* Creates a new <code>Text</code>.
|
||||||
*
|
*
|
||||||
* @method Phaser.GameObjectFactory#text
|
* @method Phaser.GameObjectFactory#text
|
||||||
* @param {number} x - X position of the new text object.
|
* @param {number} x - X position of the new text object.
|
||||||
* @param {number} y - Y 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 {string} text - The actual text that will be written.
|
||||||
* @param {object} style - The style object containing style attributes like font, font size , etc.
|
* @param {object} style - The style object containing style attributes like font, font size , etc.
|
||||||
* @return {Phaser.Text} The newly created text object.
|
* @return {Phaser.Text} The newly created text object.
|
||||||
*/
|
*/
|
||||||
text: function (x, y, text, style) {
|
text: function (x, y, text, style) {
|
||||||
|
|
||||||
return this.world.add(new Phaser.Text(this.game, 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 <code>Graphics</code> object.
|
* Creates a new <code>Graphics</code> object.
|
||||||
*
|
*
|
||||||
* @method Phaser.GameObjectFactory#graphics
|
* @method Phaser.GameObjectFactory#graphics
|
||||||
* @param {number} x - X position of the new graphics object.
|
* @param {number} x - X position of the new graphics object.
|
||||||
* @param {number} y - Y position of the new graphics object.
|
* @param {number} y - Y position of the new graphics object.
|
||||||
* @return {Phaser.Graphics} The newly created graphics object.
|
* @return {Phaser.Graphics} The newly created graphics object.
|
||||||
*/
|
*/
|
||||||
graphics: function (x, y) {
|
graphics: function (x, y) {
|
||||||
|
|
||||||
return this.world.add(new Phaser.Graphics(this.game, x, y));
|
return this.world.add(new Phaser.Graphics(this.game, x, y));
|
||||||
|
|
|
@ -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 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
|
* 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();
|
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;
|
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;
|
this.y = y;
|
||||||
|
|
||||||
|
|
|
@ -27,24 +27,24 @@ Phaser.Text = function (game, x, y, text, style) {
|
||||||
this.game = 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.
|
* @property {boolean} exists - If exists = false then the Text isn't updated by the core game loop.
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.exists = true;
|
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
|
* @default
|
||||||
*/
|
*/
|
||||||
this.alive = true;
|
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;
|
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
|
* @default
|
||||||
*/
|
*/
|
||||||
this.name = '';
|
this.name = '';
|
||||||
|
@ -70,8 +70,8 @@ Phaser.Text = function (game, x, y, text, style) {
|
||||||
PIXI.Text.call(this, 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.x = this.x = x;
|
||||||
this.position.y = this.y = y;
|
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 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
|
* 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();
|
this.anchor = new Phaser.Point();
|
||||||
|
|
||||||
|
@ -182,11 +182,11 @@ Phaser.Text.prototype.destroy = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get
|
* 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.
|
||||||
* @returns {Description}
|
* 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.
|
||||||
* Set
|
* @name Phaser.Text#angle
|
||||||
* @param {Description} value - Description
|
* @property {number} angle - Gets or sets the angle of rotation in degrees.
|
||||||
*/
|
*/
|
||||||
Object.defineProperty(Phaser.Text.prototype, 'angle', {
|
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', {
|
Object.defineProperty(Phaser.Text.prototype, 'content', {
|
||||||
|
|
||||||
get: function() {
|
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', {
|
Object.defineProperty(Phaser.Text.prototype, 'font', {
|
||||||
|
|
||||||
get: function() {
|
get: function() {
|
||||||
|
|
|
@ -39,9 +39,9 @@ Phaser.Circle = function (x, y, diameter) {
|
||||||
if (diameter > 0)
|
if (diameter > 0)
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @property {number} _radius - The radius of the circle.
|
* @property {number} _radius - The radius of the circle.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._radius = diameter * 0.5;
|
this._radius = diameter * 0.5;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -233,29 +233,29 @@ Phaser.Point.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the length of the vector
|
* Calculates the length of the vector
|
||||||
* @method Phaser.Point#getMagnitude
|
* @method Phaser.Point#getMagnitude
|
||||||
* @return {number} the length of the vector
|
* @return {number} the length of the vector
|
||||||
*/
|
*/
|
||||||
getMagnitude: function() {
|
getMagnitude: function() {
|
||||||
return Math.sqrt((this.x * this.x) + (this.y * this.y));
|
return Math.sqrt((this.x * this.x) + (this.y * this.y));
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Alters the length of the vector without changing the direction
|
* Alters the length of the vector without changing the direction
|
||||||
* @method Phaser.Point#getMagnitude
|
* @method Phaser.Point#getMagnitude
|
||||||
* @param {number} magnitude the desired magnitude of the resulting vector
|
* @param {number} magnitude the desired magnitude of the resulting vector
|
||||||
* @return {Phaser.Point} the modified original vector
|
* @return {Phaser.Point} the modified original vector
|
||||||
*/
|
*/
|
||||||
setMagnitude: function(magnitude) {
|
setMagnitude: function(magnitude) {
|
||||||
return this.normalize().multiply(magnitude, magnitude);
|
return this.normalize().multiply(magnitude, magnitude);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Alters the vector so that its length is 1, but it retains the same direction
|
* Alters the vector so that its length is 1, but it retains the same direction
|
||||||
* @method Phaser.Point#normalize
|
* @method Phaser.Point#normalize
|
||||||
* @return {Phaser.Point} the modified original vector
|
* @return {Phaser.Point} the modified original vector
|
||||||
*/
|
*/
|
||||||
normalize: function() {
|
normalize: function() {
|
||||||
|
|
||||||
if(!this.isZero()) {
|
if(!this.isZero()) {
|
||||||
|
@ -269,10 +269,10 @@ Phaser.Point.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if this point is at 0,0
|
* Determine if this point is at 0,0
|
||||||
* @method Phaser.Point#isZero
|
* @method Phaser.Point#isZero
|
||||||
* @return {boolean} True if this Point is 0,0, otherwise false
|
* @return {boolean} True if this Point is 0,0, otherwise false
|
||||||
*/
|
*/
|
||||||
isZero: function() {
|
isZero: function() {
|
||||||
return (this.x === 0 && this.y === 0);
|
return (this.x === 0 && this.y === 0);
|
||||||
},
|
},
|
||||||
|
|
|
@ -62,10 +62,10 @@ Phaser.Input.prototype = {
|
||||||
pollRate: 0,
|
pollRate: 0,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} _pollCounter - Internal var holding the current poll counter.
|
* @property {number} _pollCounter - Internal var holding the current poll counter.
|
||||||
* @private
|
* @private
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
_pollCounter: 0,
|
_pollCounter: 0,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -273,7 +273,7 @@ Phaser.Touch.prototype = {
|
||||||
{
|
{
|
||||||
//console.log('touch enter');
|
//console.log('touch enter');
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ Phaser.Touch.prototype = {
|
||||||
{
|
{
|
||||||
//console.log('touch leave');
|
//console.log('touch leave');
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -16,44 +16,44 @@
|
||||||
Phaser.Cache = function (game) {
|
Phaser.Cache = function (game) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Phaser.Game} game - Local reference to game.
|
* @property {Phaser.Game} game - Local reference to game.
|
||||||
*/
|
*/
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {object} game - Canvas key-value container.
|
* @property {object} game - Canvas key-value container.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._canvases = {};
|
this._canvases = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {object} _images - Image key-value container.
|
* @property {object} _images - Image key-value container.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._images = {};
|
this._images = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {object} _textures - RenderTexture key-value container.
|
* @property {object} _textures - RenderTexture key-value container.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._textures = {};
|
this._textures = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {object} _sounds - Sound key-value container.
|
* @property {object} _sounds - Sound key-value container.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._sounds = {};
|
this._sounds = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {object} _text - Text key-value container.
|
* @property {object} _text - Text key-value container.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._text = {};
|
this._text = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {object} _tilemaps - Tilemap key-value container.
|
* @property {object} _tilemaps - Tilemap key-value container.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._tilemaps = {};
|
this._tilemaps = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,9 +72,9 @@ Phaser.Cache = function (game) {
|
||||||
this.addMissingImage();
|
this.addMissingImage();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Phaser.Signal} onSoundUnlock - Description.
|
* @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;
|
this.onSoundUnlock = new Phaser.Signal();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -326,7 +326,6 @@ Phaser.Cache.prototype = {
|
||||||
webAudio = webAudio || true;
|
webAudio = webAudio || true;
|
||||||
audioTag = audioTag || false;
|
audioTag = audioTag || false;
|
||||||
|
|
||||||
var locked = this.game.sound.touchLocked;
|
|
||||||
var decoded = false;
|
var decoded = false;
|
||||||
|
|
||||||
if (audioTag)
|
if (audioTag)
|
||||||
|
@ -388,13 +387,13 @@ Phaser.Cache.prototype = {
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new decoded sound.
|
* Add a new decoded sound.
|
||||||
*
|
*
|
||||||
* @method Phaser.Cache#decodedSound
|
* @method Phaser.Cache#decodedSound
|
||||||
* @param {string} key - Asset key for the sound.
|
* @param {string} key - Asset key for the sound.
|
||||||
* @param {object} data - Extra sound data.
|
* @param {object} data - Extra sound data.
|
||||||
*/
|
*/
|
||||||
decodedSound: function (key, data) {
|
decodedSound: function (key, data) {
|
||||||
|
|
||||||
this._sounds[key].data = 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
|
* @method Phaser.Cache#getCanvas
|
||||||
* @param {string} key - Asset key of the canvas you want.
|
* @param {string} key - Asset key of the canvas you want.
|
||||||
* @return {object} The canvas you want.
|
* @return {object} The canvas you want.
|
||||||
*/
|
*/
|
||||||
getCanvas: function (key) {
|
getCanvas: function (key) {
|
||||||
|
|
||||||
if (this._canvases[key])
|
if (this._canvases[key])
|
||||||
|
@ -457,13 +456,13 @@ Phaser.Cache.prototype = {
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get image data by key.
|
* Get image data by key.
|
||||||
*
|
*
|
||||||
* @method Phaser.Cache#getImage
|
* @method Phaser.Cache#getImage
|
||||||
* @param {string} key - Asset key of the image you want.
|
* @param {string} key - Asset key of the image you want.
|
||||||
* @return {object} The image data you want.
|
* @return {object} The image data you want.
|
||||||
*/
|
*/
|
||||||
getImage: function (key) {
|
getImage: function (key) {
|
||||||
|
|
||||||
if (this._images[key])
|
if (this._images[key])
|
||||||
|
@ -528,13 +527,13 @@ Phaser.Cache.prototype = {
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get frame data by key.
|
* Get frame data by key.
|
||||||
*
|
*
|
||||||
* @method Phaser.Cache#getFrameData
|
* @method Phaser.Cache#getFrameData
|
||||||
* @param {string} key - Asset key of the frame data you want.
|
* @param {string} key - Asset key of the frame data you want.
|
||||||
* @return {Phaser.FrameData} The frame data you want.
|
* @return {Phaser.FrameData} The frame data you want.
|
||||||
*/
|
*/
|
||||||
getFrameData: function (key) {
|
getFrameData: function (key) {
|
||||||
|
|
||||||
if (this._images[key] && this._images[key].frameData)
|
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
|
* @method Phaser.Cache#getSound
|
||||||
* @param {string} key - Asset key of the sound you want.
|
* @param {string} key - Asset key of the sound you want.
|
||||||
* @return {Phaser.Sound} The sound you want.
|
* @return {Phaser.Sound} The sound you want.
|
||||||
*/
|
*/
|
||||||
getSound: function (key) {
|
getSound: function (key) {
|
||||||
|
|
||||||
if (this._sounds[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
|
* @method Phaser.Cache#getSoundData
|
||||||
* @param {string} key - Asset key of the sound you want.
|
* @param {string} key - Asset key of the sound you want.
|
||||||
* @return {object} The sound data you want.
|
* @return {object} The sound data you want.
|
||||||
*/
|
*/
|
||||||
getSoundData: function (key) {
|
getSoundData: function (key) {
|
||||||
|
|
||||||
if (this._sounds[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
|
* @method Phaser.Cache#isSoundDecoded
|
||||||
* @param {string} key - Asset key of the sound you want.
|
* @param {string} key - Asset key of the sound you want.
|
||||||
* @return {boolean} The decoded state of the Sound object.
|
* @return {boolean} The decoded state of the Sound object.
|
||||||
*/
|
*/
|
||||||
isSoundDecoded: function (key) {
|
isSoundDecoded: function (key) {
|
||||||
|
|
||||||
if (this._sounds[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
|
* @method Phaser.Cache#isSoundReady
|
||||||
* @param {string} key - Asset key of the sound you want.
|
* @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.
|
* @return {boolean} True if the sound is decoded and the device is not touch locked.
|
||||||
*/
|
*/
|
||||||
isSoundReady: function (key) {
|
isSoundReady: function (key) {
|
||||||
|
|
||||||
return (this._sounds[key] && this._sounds[key].decoded && this.game.sound.touchLocked === false);
|
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
|
* @method Phaser.Cache#isSpriteSheet
|
||||||
* @param {string} key - Asset key of the sprite sheet you want.
|
* @param {string} key - Asset key of the sprite sheet you want.
|
||||||
* @return {boolean} True if the image is a sprite sheet.
|
* @return {boolean} True if the image is a sprite sheet.
|
||||||
*/
|
*/
|
||||||
isSpriteSheet: function (key) {
|
isSpriteSheet: function (key) {
|
||||||
|
|
||||||
if (this._images[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
|
* @method Phaser.Cache#getText
|
||||||
* @param {string} key - Asset key of the text data you want.
|
* @param {string} key - Asset key of the text data you want.
|
||||||
* @return {object} The text data you want.
|
* @return {object} The text data you want.
|
||||||
*/
|
*/
|
||||||
getText: function (key) {
|
getText: function (key) {
|
||||||
|
|
||||||
if (this._text[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
|
* @method Phaser.Cache#getImageKeys
|
||||||
* @return {Array} The string based keys in the Cache.
|
* @return {Array} The string based keys in the Cache.
|
||||||
*/
|
*/
|
||||||
getImageKeys: function () {
|
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
|
* @method Phaser.Cache#getSoundKeys
|
||||||
* @return {Array} The string based keys in the Cache.
|
* @return {Array} The string based keys in the Cache.
|
||||||
*/
|
*/
|
||||||
getSoundKeys: function () {
|
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
|
* @method Phaser.Cache#getTextKeys
|
||||||
* @return {Array} The string based keys in the Cache.
|
* @return {Array} The string based keys in the Cache.
|
||||||
*/
|
*/
|
||||||
getTextKeys: function () {
|
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.
|
* @param {string} key - Key of the asset you want to remove.
|
||||||
*/
|
*/
|
||||||
removeCanvas: function (key) {
|
removeCanvas: function (key) {
|
||||||
delete this._canvases[key];
|
delete this._canvases[key];
|
||||||
},
|
},
|
||||||
|
@ -826,11 +825,11 @@ Phaser.Cache.prototype = {
|
||||||
delete this._text[key];
|
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 () {
|
destroy: function () {
|
||||||
|
|
||||||
for (var item in this._canvases)
|
for (var item in this._canvases)
|
||||||
|
|
2110
src/loader/Loader.js
2110
src/loader/Loader.js
File diff suppressed because it is too large
Load diff
|
@ -17,7 +17,7 @@ Phaser.LoaderParser = {
|
||||||
* @param {object} xml - XML data you want to parse.
|
* @param {object} xml - XML data you want to parse.
|
||||||
* @return {FrameData} Generated FrameData object.
|
* @return {FrameData} Generated FrameData object.
|
||||||
*/
|
*/
|
||||||
bitmapFont: function (game, xml, cacheKey) {
|
bitmapFont: function (game, xml, cacheKey) {
|
||||||
|
|
||||||
// Malformed?
|
// Malformed?
|
||||||
if (!xml.getElementsByTagName('font'))
|
if (!xml.getElementsByTagName('font'))
|
||||||
|
@ -50,8 +50,8 @@ Phaser.LoaderParser = {
|
||||||
height: parseInt(letters[i].attributes.getNamedItem("height").nodeValue, 10)
|
height: parseInt(letters[i].attributes.getNamedItem("height").nodeValue, 10)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Note: This means you can only have 1 BitmapFont loaded at once!
|
// Note: This means you can only have 1 BitmapFont loaded at once!
|
||||||
// Need to replace this with our own handler soon.
|
// Need to replace this with our own handler soon.
|
||||||
PIXI.TextureCache[charCode] = new PIXI.Texture(texture, textureRect);
|
PIXI.TextureCache[charCode] = new PIXI.Texture(texture, textureRect);
|
||||||
|
|
||||||
data.chars[charCode] = {
|
data.chars[charCode] = {
|
||||||
|
@ -69,9 +69,9 @@ Phaser.LoaderParser = {
|
||||||
|
|
||||||
for (i = 0; i < kernings.length; i++)
|
for (i = 0; i < kernings.length; i++)
|
||||||
{
|
{
|
||||||
var first = parseInt(kernings[i].attributes.getNamedItem("first").nodeValue, 10);
|
var first = parseInt(kernings[i].attributes.getNamedItem("first").nodeValue, 10);
|
||||||
var second = parseInt(kernings[i].attributes.getNamedItem("second").nodeValue, 10);
|
var second = parseInt(kernings[i].attributes.getNamedItem("second").nodeValue, 10);
|
||||||
var amount = parseInt(kernings[i].attributes.getNamedItem("amount").nodeValue, 10);
|
var amount = parseInt(kernings[i].attributes.getNamedItem("amount").nodeValue, 10);
|
||||||
|
|
||||||
data.chars[second].kerning[first] = amount;
|
data.chars[second].kerning[first] = amount;
|
||||||
}
|
}
|
||||||
|
|
830
src/math/Math.js
830
src/math/Math.js
File diff suppressed because it is too large
Load diff
|
@ -59,206 +59,207 @@
|
||||||
*/
|
*/
|
||||||
Phaser.QuadTree = function (physicsManager, x, y, width, height, maxObjects, maxLevels, level) {
|
Phaser.QuadTree = function (physicsManager, x, y, width, height, maxObjects, maxLevels, level) {
|
||||||
|
|
||||||
this.physicsManager = physicsManager;
|
this.physicsManager = physicsManager;
|
||||||
this.ID = physicsManager.quadTreeID;
|
this.ID = physicsManager.quadTreeID;
|
||||||
physicsManager.quadTreeID++;
|
physicsManager.quadTreeID++;
|
||||||
|
|
||||||
this.maxObjects = maxObjects || 10;
|
this.maxObjects = maxObjects || 10;
|
||||||
this.maxLevels = maxLevels || 4;
|
this.maxLevels = maxLevels || 4;
|
||||||
this.level = level || 0;
|
this.level = level || 0;
|
||||||
|
|
||||||
this.bounds = {
|
this.bounds = {
|
||||||
x: Math.round(x),
|
x: Math.round(x),
|
||||||
y: Math.round(y),
|
y: Math.round(y),
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
subWidth: Math.floor(width / 2),
|
subWidth: Math.floor(width / 2),
|
||||||
subHeight: Math.floor(height / 2),
|
subHeight: Math.floor(height / 2),
|
||||||
right: Math.round(x) + Math.floor(width / 2),
|
right: Math.round(x) + Math.floor(width / 2),
|
||||||
bottom: Math.round(y) + Math.floor(height / 2)
|
bottom: Math.round(y) + Math.floor(height / 2)
|
||||||
};
|
};
|
||||||
|
|
||||||
this.objects = [];
|
this.objects = [];
|
||||||
this.nodes = [];
|
this.nodes = [];
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Phaser.QuadTree.prototype = {
|
Phaser.QuadTree.prototype = {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Split the node into 4 subnodes
|
* Split the node into 4 subnodes
|
||||||
*
|
*
|
||||||
* @method Phaser.QuadTree#split
|
* @method Phaser.QuadTree#split
|
||||||
*/
|
*/
|
||||||
split: function() {
|
split: function() {
|
||||||
|
|
||||||
this.level++;
|
this.level++;
|
||||||
|
|
||||||
// top right node
|
// top right node
|
||||||
this.nodes[0] = new Phaser.QuadTree(this.physicsManager, this.bounds.right, this.bounds.y, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
|
this.nodes[0] = new Phaser.QuadTree(this.physicsManager, this.bounds.right, this.bounds.y, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
|
||||||
|
|
||||||
// top left node
|
// top left node
|
||||||
this.nodes[1] = new Phaser.QuadTree(this.physicsManager, this.bounds.x, this.bounds.y, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
|
this.nodes[1] = new Phaser.QuadTree(this.physicsManager, this.bounds.x, this.bounds.y, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
|
||||||
|
|
||||||
// bottom left node
|
// bottom left node
|
||||||
this.nodes[2] = new Phaser.QuadTree(this.physicsManager, this.bounds.x, this.bounds.bottom, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
|
this.nodes[2] = new Phaser.QuadTree(this.physicsManager, this.bounds.x, this.bounds.bottom, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
|
||||||
|
|
||||||
// bottom right node
|
// bottom right node
|
||||||
this.nodes[3] = new Phaser.QuadTree(this.physicsManager, this.bounds.right, this.bounds.bottom, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
|
this.nodes[3] = new Phaser.QuadTree(this.physicsManager, this.bounds.right, this.bounds.bottom, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Insert the object into the node. If the node
|
* Insert the object into the node. If the node
|
||||||
* exceeds the capacity, it will split and add all
|
* exceeds the capacity, it will split and add all
|
||||||
* objects to their corresponding subnodes.
|
* objects to their corresponding subnodes.
|
||||||
*
|
*
|
||||||
* @method Phaser.QuadTree#insert
|
* @method Phaser.QuadTree#insert
|
||||||
* @param {object} body - Description.
|
* @param {object} body - Description.
|
||||||
*/
|
*/
|
||||||
insert: function (body) {
|
insert: function (body) {
|
||||||
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
var index;
|
var index;
|
||||||
|
|
||||||
// if we have subnodes ...
|
// if we have subnodes ...
|
||||||
if (this.nodes[0] != null)
|
if (this.nodes[0] != null)
|
||||||
{
|
{
|
||||||
index = this.getIndex(body);
|
index = this.getIndex(body);
|
||||||
|
|
||||||
if (index !== -1)
|
if (index !== -1)
|
||||||
{
|
{
|
||||||
this.nodes[index].insert(body);
|
this.nodes[index].insert(body);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.objects.push(body);
|
this.objects.push(body);
|
||||||
|
|
||||||
if (this.objects.length > this.maxObjects && this.level < this.maxLevels)
|
if (this.objects.length > this.maxObjects && this.level < this.maxLevels)
|
||||||
{
|
{
|
||||||
// Split if we don't already have subnodes
|
// Split if we don't already have subnodes
|
||||||
if (this.nodes[0] == null)
|
if (this.nodes[0] == null)
|
||||||
{
|
{
|
||||||
this.split();
|
this.split();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add objects to subnodes
|
// Add objects to subnodes
|
||||||
while (i < this.objects.length)
|
while (i < this.objects.length)
|
||||||
{
|
{
|
||||||
index = this.getIndex(this.objects[i]);
|
index = this.getIndex(this.objects[i]);
|
||||||
|
|
||||||
if (index !== -1)
|
if (index !== -1)
|
||||||
{
|
{
|
||||||
// this is expensive - see what we can do about it
|
// this is expensive - see what we can do about it
|
||||||
this.nodes[index].insert(this.objects.splice(i, 1)[0]);
|
this.nodes[index].insert(this.objects.splice(i, 1)[0]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
/*
|
},
|
||||||
* Determine which node the object belongs to.
|
|
||||||
*
|
|
||||||
* @method Phaser.QuadTree#getIndex
|
|
||||||
* @param {object} rect - Description.
|
|
||||||
* @return {number} index - Index of the subnode (0-3), or -1 if rect cannot completely fit within a subnode and is part of the parent node.
|
|
||||||
*/
|
|
||||||
getIndex: function (rect) {
|
|
||||||
|
|
||||||
// default is that rect doesn't fit, i.e. it straddles the internal quadrants
|
/*
|
||||||
var index = -1;
|
* Determine which node the object belongs to.
|
||||||
|
*
|
||||||
|
* @method Phaser.QuadTree#getIndex
|
||||||
|
* @param {object} rect - Description.
|
||||||
|
* @return {number} index - Index of the subnode (0-3), or -1 if rect cannot completely fit within a subnode and is part of the parent node.
|
||||||
|
*/
|
||||||
|
getIndex: function (rect) {
|
||||||
|
|
||||||
if (rect.x < this.bounds.right && rect.right < this.bounds.right)
|
// default is that rect doesn't fit, i.e. it straddles the internal quadrants
|
||||||
{
|
var index = -1;
|
||||||
if ((rect.y < this.bounds.bottom && rect.bottom < this.bounds.bottom))
|
|
||||||
{
|
|
||||||
// rect fits within the top-left quadrant of this quadtree
|
|
||||||
index = 1;
|
|
||||||
}
|
|
||||||
else if ((rect.y > this.bounds.bottom))
|
|
||||||
{
|
|
||||||
// rect fits within the bottom-left quadrant of this quadtree
|
|
||||||
index = 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (rect.x > this.bounds.right)
|
|
||||||
{
|
|
||||||
// rect can completely fit within the right quadrants
|
|
||||||
if ((rect.y < this.bounds.bottom && rect.bottom < this.bounds.bottom))
|
|
||||||
{
|
|
||||||
// rect fits within the top-right quadrant of this quadtree
|
|
||||||
index = 0;
|
|
||||||
}
|
|
||||||
else if ((rect.y > this.bounds.bottom))
|
|
||||||
{
|
|
||||||
// rect fits within the bottom-right quadrant of this quadtree
|
|
||||||
index = 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return index;
|
if (rect.x < this.bounds.right && rect.right < this.bounds.right)
|
||||||
|
{
|
||||||
|
if ((rect.y < this.bounds.bottom && rect.bottom < this.bounds.bottom))
|
||||||
|
{
|
||||||
|
// rect fits within the top-left quadrant of this quadtree
|
||||||
|
index = 1;
|
||||||
|
}
|
||||||
|
else if ((rect.y > this.bounds.bottom))
|
||||||
|
{
|
||||||
|
// rect fits within the bottom-left quadrant of this quadtree
|
||||||
|
index = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (rect.x > this.bounds.right)
|
||||||
|
{
|
||||||
|
// rect can completely fit within the right quadrants
|
||||||
|
if ((rect.y < this.bounds.bottom && rect.bottom < this.bounds.bottom))
|
||||||
|
{
|
||||||
|
// rect fits within the top-right quadrant of this quadtree
|
||||||
|
index = 0;
|
||||||
|
}
|
||||||
|
else if ((rect.y > this.bounds.bottom))
|
||||||
|
{
|
||||||
|
// rect fits within the bottom-right quadrant of this quadtree
|
||||||
|
index = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
},
|
return index;
|
||||||
|
|
||||||
/*
|
},
|
||||||
* Return all objects that could collide with the given object.
|
|
||||||
*
|
|
||||||
* @method Phaser.QuadTree#retrieve
|
|
||||||
* @param {object} rect - Description.
|
|
||||||
* @Return {array} - Array with all detected objects.
|
|
||||||
*/
|
|
||||||
retrieve: function (sprite) {
|
|
||||||
|
|
||||||
var returnObjects = this.objects;
|
/*
|
||||||
|
* Return all objects that could collide with the given object.
|
||||||
|
*
|
||||||
|
* @method Phaser.QuadTree#retrieve
|
||||||
|
* @param {object} rect - Description.
|
||||||
|
* @Return {array} - Array with all detected objects.
|
||||||
|
*/
|
||||||
|
retrieve: function (sprite) {
|
||||||
|
|
||||||
sprite.body.quadTreeIndex = this.getIndex(sprite.body);
|
var returnObjects = this.objects;
|
||||||
|
|
||||||
// Temp store for the node IDs this sprite is in, we can use this for fast elimination later
|
sprite.body.quadTreeIndex = this.getIndex(sprite.body);
|
||||||
sprite.body.quadTreeIDs.push(this.ID);
|
|
||||||
|
|
||||||
if (this.nodes[0])
|
// Temp store for the node IDs this sprite is in, we can use this for fast elimination later
|
||||||
{
|
sprite.body.quadTreeIDs.push(this.ID);
|
||||||
// if rect fits into a subnode ..
|
|
||||||
if (sprite.body.quadTreeIndex !== -1)
|
|
||||||
{
|
|
||||||
returnObjects = returnObjects.concat(this.nodes[sprite.body.quadTreeIndex].retrieve(sprite));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// if rect does not fit into a subnode, check it against all subnodes (unrolled for speed)
|
|
||||||
returnObjects = returnObjects.concat(this.nodes[0].retrieve(sprite));
|
|
||||||
returnObjects = returnObjects.concat(this.nodes[1].retrieve(sprite));
|
|
||||||
returnObjects = returnObjects.concat(this.nodes[2].retrieve(sprite));
|
|
||||||
returnObjects = returnObjects.concat(this.nodes[3].retrieve(sprite));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnObjects;
|
if (this.nodes[0])
|
||||||
|
{
|
||||||
|
// if rect fits into a subnode ..
|
||||||
|
if (sprite.body.quadTreeIndex !== -1)
|
||||||
|
{
|
||||||
|
returnObjects = returnObjects.concat(this.nodes[sprite.body.quadTreeIndex].retrieve(sprite));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// if rect does not fit into a subnode, check it against all subnodes (unrolled for speed)
|
||||||
|
returnObjects = returnObjects.concat(this.nodes[0].retrieve(sprite));
|
||||||
|
returnObjects = returnObjects.concat(this.nodes[1].retrieve(sprite));
|
||||||
|
returnObjects = returnObjects.concat(this.nodes[2].retrieve(sprite));
|
||||||
|
returnObjects = returnObjects.concat(this.nodes[3].retrieve(sprite));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
},
|
return returnObjects;
|
||||||
|
|
||||||
/*
|
},
|
||||||
* Clear the quadtree.
|
|
||||||
* @method Phaser.QuadTree#clear
|
|
||||||
*/
|
|
||||||
clear: function () {
|
|
||||||
|
|
||||||
this.objects = [];
|
/*
|
||||||
|
* Clear the quadtree.
|
||||||
|
* @method Phaser.QuadTree#clear
|
||||||
|
*/
|
||||||
|
clear: function () {
|
||||||
|
|
||||||
for (var i = 0, len = this.nodes.length; i < len; i++)
|
this.objects = [];
|
||||||
{
|
|
||||||
// if (typeof this.nodes[i] !== 'undefined')
|
for (var i = 0, len = this.nodes.length; i < len; i++)
|
||||||
if (this.nodes[i])
|
{
|
||||||
{
|
// if (typeof this.nodes[i] !== 'undefined')
|
||||||
this.nodes[i].clear();
|
if (this.nodes[i])
|
||||||
delete this.nodes[i];
|
{
|
||||||
}
|
this.nodes[i].clear();
|
||||||
}
|
delete this.nodes[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* jshint noempty: false */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Richard Davey <rich@photonstorm.com>
|
* @author Richard Davey <rich@photonstorm.com>
|
||||||
* @copyright 2013 Photon Storm Ltd.
|
* @copyright 2013 Photon Storm Ltd.
|
||||||
|
@ -17,230 +19,229 @@
|
||||||
*/
|
*/
|
||||||
Phaser.RandomDataGenerator = function (seeds) {
|
Phaser.RandomDataGenerator = function (seeds) {
|
||||||
|
|
||||||
if (typeof seeds === "undefined") { seeds = []; }
|
if (typeof seeds === "undefined") { seeds = []; }
|
||||||
|
|
||||||
this.sow(seeds);
|
/**
|
||||||
|
* @property {number} c - Internal var.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.c = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {number} s0 - Internal var.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.s0 = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {number} s1 - Internal var.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.s1 = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {number} s2 - Internal var.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.s2 = 0;
|
||||||
|
|
||||||
|
this.sow(seeds);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Phaser.RandomDataGenerator.prototype = {
|
Phaser.RandomDataGenerator.prototype = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} c
|
* Private random helper.
|
||||||
* @private
|
* @method Phaser.RandomDataGenerator#rnd
|
||||||
*/
|
* @private
|
||||||
c: 1,
|
* @return {number}
|
||||||
|
*/
|
||||||
|
rnd: function () {
|
||||||
|
|
||||||
/**
|
var t = 2091639 * this.s0 + this.c * 2.3283064365386963e-10; // 2^-32
|
||||||
* @property {number} s0
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
s0: 0,
|
|
||||||
|
|
||||||
/**
|
this.c = t | 0;
|
||||||
* @property {number} s1
|
this.s0 = this.s1;
|
||||||
* @private
|
this.s1 = this.s2;
|
||||||
*/
|
this.s2 = t - this.c;
|
||||||
s1: 0,
|
|
||||||
|
|
||||||
/**
|
return this.s2;
|
||||||
* @property {number} s2
|
},
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
s2: 0,
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private random helper.
|
* Reset the seed of the random data generator.
|
||||||
* @method Phaser.RandomDataGenerator#rnd
|
*
|
||||||
* @private
|
* @method Phaser.RandomDataGenerator#sow
|
||||||
* @return {number} Description.
|
* @param {array} seeds
|
||||||
*/
|
*/
|
||||||
rnd: function () {
|
sow: function (seeds) {
|
||||||
|
|
||||||
var t = 2091639 * this.s0 + this.c * 2.3283064365386963e-10; // 2^-32
|
if (typeof seeds === "undefined") { seeds = []; }
|
||||||
|
|
||||||
this.c = t | 0;
|
this.s0 = this.hash(' ');
|
||||||
this.s0 = this.s1;
|
this.s1 = this.hash(this.s0);
|
||||||
this.s1 = this.s2;
|
this.s2 = this.hash(this.s1);
|
||||||
this.s2 = t - this.c;
|
this.c = 1;
|
||||||
|
|
||||||
return this.s2;
|
var seed;
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
for (var i = 0; seed = seeds[i++]; )
|
||||||
* Reset the seed of the random data generator.
|
{
|
||||||
*
|
this.s0 -= this.hash(seed);
|
||||||
* @method Phaser.RandomDataGenerator#sow
|
this.s0 += ~~(this.s0 < 0);
|
||||||
* @param {array} seeds
|
this.s1 -= this.hash(seed);
|
||||||
*/
|
this.s1 += ~~(this.s1 < 0);
|
||||||
sow: function (seeds) {
|
this.s2 -= this.hash(seed);
|
||||||
|
this.s2 += ~~(this.s2 < 0);
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof seeds === "undefined") { seeds = []; }
|
},
|
||||||
|
|
||||||
this.s0 = this.hash(' ');
|
/**
|
||||||
this.s1 = this.hash(this.s0);
|
* Internal method that creates a seed hash.
|
||||||
this.s2 = this.hash(this.s1);
|
* @method Phaser.RandomDataGenerator#hash
|
||||||
this.c = 1;
|
* @param {Any} data
|
||||||
|
* @private
|
||||||
|
* @return {number} hashed value.
|
||||||
|
*/
|
||||||
|
hash: function (data) {
|
||||||
|
|
||||||
var seed;
|
var h, i, n;
|
||||||
|
n = 0xefc8249d;
|
||||||
|
data = data.toString();
|
||||||
|
|
||||||
for (var i = 0; seed = seeds[i++]; )
|
for (i = 0; i < data.length; i++) {
|
||||||
{
|
n += data.charCodeAt(i);
|
||||||
this.s0 -= this.hash(seed);
|
h = 0.02519603282416938 * n;
|
||||||
this.s0 += ~~(this.s0 < 0);
|
n = h >>> 0;
|
||||||
this.s1 -= this.hash(seed);
|
h -= n;
|
||||||
this.s1 += ~~(this.s1 < 0);
|
h *= n;
|
||||||
this.s2 -= this.hash(seed);
|
n = h >>> 0;
|
||||||
this.s2 += ~~(this.s2 < 0);
|
h -= n;
|
||||||
}
|
n += h * 0x100000000;// 2^32
|
||||||
|
}
|
||||||
|
|
||||||
},
|
return (n >>> 0) * 2.3283064365386963e-10;// 2^-32
|
||||||
|
|
||||||
/**
|
},
|
||||||
* Description.
|
|
||||||
* @method Phaser.RandomDataGenerator#hash
|
|
||||||
* @param {Any} data
|
|
||||||
* @private
|
|
||||||
* @return {number} Description.
|
|
||||||
*/
|
|
||||||
hash: function (data) {
|
|
||||||
|
|
||||||
var h, i, n;
|
/**
|
||||||
n = 0xefc8249d;
|
* Returns a random integer between 0 and 2^32.
|
||||||
data = data.toString();
|
* @method Phaser.RandomDataGenerator#integer
|
||||||
|
* @return {number} A random integer between 0 and 2^32.
|
||||||
|
*/
|
||||||
|
integer: function() {
|
||||||
|
return this.rnd.apply(this) * 0x100000000;// 2^32
|
||||||
|
},
|
||||||
|
|
||||||
for (i = 0; i < data.length; i++) {
|
/**
|
||||||
n += data.charCodeAt(i);
|
* Returns a random real number between 0 and 1.
|
||||||
h = 0.02519603282416938 * n;
|
* @method Phaser.RandomDataGenerator#frac
|
||||||
n = h >>> 0;
|
* @return {number} A random real number between 0 and 1.
|
||||||
h -= n;
|
*/
|
||||||
h *= n;
|
frac: function() {
|
||||||
n = h >>> 0;
|
return this.rnd.apply(this) + (this.rnd.apply(this) * 0x200000 | 0) * 1.1102230246251565e-16;// 2^-53
|
||||||
h -= n;
|
},
|
||||||
n += h * 0x100000000;// 2^32
|
|
||||||
}
|
|
||||||
|
|
||||||
return (n >>> 0) * 2.3283064365386963e-10;// 2^-32
|
/**
|
||||||
|
* Returns a random real number between 0 and 2^32.
|
||||||
|
* @method Phaser.RandomDataGenerator#real
|
||||||
|
* @return {number} A random real number between 0 and 2^32.
|
||||||
|
*/
|
||||||
|
real: function() {
|
||||||
|
return this.integer() + this.frac();
|
||||||
|
},
|
||||||
|
|
||||||
},
|
/**
|
||||||
|
* Returns a random integer between min and max.
|
||||||
|
* @method Phaser.RandomDataGenerator#integerInRange
|
||||||
|
* @param {number} min - The minimum value in the range.
|
||||||
|
* @param {number} max - The maximum value in the range.
|
||||||
|
* @return {number} A random number between min and max.
|
||||||
|
*/
|
||||||
|
integerInRange: function (min, max) {
|
||||||
|
return Math.floor(this.realInRange(min, max));
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a random integer between 0 and 2^32.
|
* Returns a random real number between min and max.
|
||||||
* @method Phaser.RandomDataGenerator#integer
|
* @method Phaser.RandomDataGenerator#realInRange
|
||||||
* @return {number}
|
* @param {number} min - The minimum value in the range.
|
||||||
*/
|
* @param {number} max - The maximum value in the range.
|
||||||
integer: function() {
|
* @return {number} A random number between min and max.
|
||||||
return this.rnd.apply(this) * 0x100000000;// 2^32
|
*/
|
||||||
},
|
realInRange: function (min, max) {
|
||||||
|
|
||||||
/**
|
return this.frac() * (max - min) + min;
|
||||||
* Returns a random real number between 0 and 1.
|
|
||||||
* @method Phaser.RandomDataGenerator#frac
|
|
||||||
* @return {number}
|
|
||||||
*/
|
|
||||||
frac: function() {
|
|
||||||
return this.rnd.apply(this) + (this.rnd.apply(this) * 0x200000 | 0) * 1.1102230246251565e-16;// 2^-53
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
},
|
||||||
* Returns a random real number between 0 and 2^32.
|
|
||||||
* @method Phaser.RandomDataGenerator#real
|
|
||||||
* @return {number}
|
|
||||||
*/
|
|
||||||
real: function() {
|
|
||||||
return this.integer() + this.frac();
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a random integer between min and max.
|
* Returns a random real number between -1 and 1.
|
||||||
* @method Phaser.RandomDataGenerator#integerInRange
|
* @method Phaser.RandomDataGenerator#normal
|
||||||
* @param {number} min
|
* @return {number} A random real number between -1 and 1.
|
||||||
* @param {number} max
|
*/
|
||||||
* @return {number}
|
normal: function () {
|
||||||
*/
|
return 1 - 2 * this.frac();
|
||||||
integerInRange: function (min, max) {
|
},
|
||||||
return Math.floor(this.realInRange(min, max));
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a random real number between min and max.
|
* Returns a valid RFC4122 version4 ID hex string from https://gist.github.com/1308368
|
||||||
* @method Phaser.RandomDataGenerator#realInRange
|
* @method Phaser.RandomDataGenerator#uuid
|
||||||
* @param {number} min
|
* @return {string} A valid RFC4122 version4 ID hex string
|
||||||
* @param {number} max
|
*/
|
||||||
* @return {number}
|
uuid: function () {
|
||||||
*/
|
|
||||||
realInRange: function (min, max) {
|
|
||||||
|
|
||||||
return this.frac() * (max - min) + min;
|
var a = '';
|
||||||
|
var b = '';
|
||||||
|
|
||||||
},
|
for (b = a = ''; a++ < 36; b +=~a % 5 | a * 3&4 ? (a^15 ? 8^this.frac() * (a^20 ? 16 : 4) : 4).toString(16) : '-')
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
return b;
|
||||||
* Returns a random real number between -1 and 1.
|
|
||||||
* @method Phaser.RandomDataGenerator#normal
|
|
||||||
* @return {number}
|
|
||||||
*/
|
|
||||||
normal: function () {
|
|
||||||
return 1 - 2 * this.frac();
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
},
|
||||||
* Returns a valid RFC4122 version4 ID hex string from https://gist.github.com/1308368
|
|
||||||
* @method Phaser.RandomDataGenerator#uuid
|
|
||||||
* @return {string}
|
|
||||||
*/
|
|
||||||
uuid: function () {
|
|
||||||
|
|
||||||
var a, b;
|
/**
|
||||||
|
* Returns a random member of `array`.
|
||||||
|
* @method Phaser.RandomDataGenerator#pick
|
||||||
|
* @param {Array} ary - An Array to pick a random member of.
|
||||||
|
* @return {any} A random member of the array.
|
||||||
|
*/
|
||||||
|
pick: function (ary) {
|
||||||
|
return ary[this.integerInRange(0, ary.length)];
|
||||||
|
},
|
||||||
|
|
||||||
for (
|
/**
|
||||||
b=a='';
|
* Returns a random member of `array`, favoring the earlier entries.
|
||||||
a++<36;
|
* @method Phaser.RandomDataGenerator#weightedPick
|
||||||
b+=~a%5|a*3&4?(a^15?8^this.frac()*(a^20?16:4):4).toString(16):'-'
|
* @param {Array} ary - An Array to pick a random member of.
|
||||||
);
|
* @return {any} A random member of the array.
|
||||||
|
*/
|
||||||
|
weightedPick: function (ary) {
|
||||||
|
return ary[~~(Math.pow(this.frac(), 2) * ary.length)];
|
||||||
|
},
|
||||||
|
|
||||||
return b;
|
/**
|
||||||
|
* Returns a random timestamp between min and max, or between the beginning of 2000 and the end of 2020 if min and max aren't specified.
|
||||||
|
* @method Phaser.RandomDataGenerator#timestamp
|
||||||
|
* @param {number} min - The minimum value in the range.
|
||||||
|
* @param {number} max - The maximum value in the range.
|
||||||
|
* @return {number} A random timestamp between min and max.
|
||||||
|
*/
|
||||||
|
timestamp: function (min, max) {
|
||||||
|
return this.realInRange(min || 946684800000, max || 1577862000000);
|
||||||
|
},
|
||||||
|
|
||||||
},
|
/**
|
||||||
|
* Returns a random angle between -180 and 180.
|
||||||
/**
|
* @method Phaser.RandomDataGenerator#angle
|
||||||
* Returns a random member of `array`.
|
* @return {number} A random number between -180 and 180.
|
||||||
* @method Phaser.RandomDataGenerator#pick
|
*/
|
||||||
* @param {Any} ary
|
angle: function() {
|
||||||
* @return {number}
|
return this.integerInRange(-180, 180);
|
||||||
*/
|
}
|
||||||
pick: function (ary) {
|
|
||||||
return ary[this.integerInRange(0, ary.length)];
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a random member of `array`, favoring the earlier entries.
|
|
||||||
* @method Phaser.RandomDataGenerator#weightedPick
|
|
||||||
* @param {Any} ary
|
|
||||||
* @return {number}
|
|
||||||
*/
|
|
||||||
weightedPick: function (ary) {
|
|
||||||
return ary[~~(Math.pow(this.frac(), 2) * ary.length)];
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a random timestamp between min and max, or between the beginning of 2000 and the end of 2020 if min and max aren't specified.
|
|
||||||
* @method Phaser.RandomDataGenerator#timestamp
|
|
||||||
* @param {number} min
|
|
||||||
* @param {number} max
|
|
||||||
* @return {number}
|
|
||||||
*/
|
|
||||||
timestamp: function (a, b) {
|
|
||||||
return this.realInRange(a || 946684800000, b || 1577862000000);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a random angle between -180 and 180.
|
|
||||||
* @method Phaser.RandomDataGenerator#angle
|
|
||||||
* @return {number}
|
|
||||||
*/
|
|
||||||
angle: function() {
|
|
||||||
return this.integerInRange(-180, 180);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
246
src/net/Net.js
246
src/net/Net.js
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description of Phaser.Net
|
* Phaser.Net handles browser URL related tasks such as checking host names, domain names and query string manipulation.
|
||||||
*
|
*
|
||||||
* @class Phaser.Net
|
* @class Phaser.Net
|
||||||
* @constructor
|
* @constructor
|
||||||
|
@ -13,156 +13,152 @@
|
||||||
*/
|
*/
|
||||||
Phaser.Net = function (game) {
|
Phaser.Net = function (game) {
|
||||||
|
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Phaser.Net.prototype = {
|
Phaser.Net.prototype = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the hostname given by the browser.
|
* Returns the hostname given by the browser.
|
||||||
*
|
*
|
||||||
* @method Phaser.Net#getHostName
|
* @method Phaser.Net#getHostName
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
getHostName: function () {
|
getHostName: function () {
|
||||||
|
|
||||||
if (window.location && window.location.hostname) {
|
if (window.location && window.location.hostname) {
|
||||||
return window.location.hostname;
|
return window.location.hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares the given domain name against the hostname of the browser containing the game.
|
* Compares the given domain name against the hostname of the browser containing the game.
|
||||||
* If the domain name is found it returns true.
|
* If the domain name is found it returns true.
|
||||||
* You can specify a part of a domain, for example 'google' would match 'google.com', 'google.co.uk', etc.
|
* You can specify a part of a domain, for example 'google' would match 'google.com', 'google.co.uk', etc.
|
||||||
* Do not include 'http://' at the start.
|
* Do not include 'http://' at the start.
|
||||||
*
|
*
|
||||||
* @method Phaser.Net#checkDomainName
|
* @method Phaser.Net#checkDomainName
|
||||||
* @param {string} domain
|
* @param {string} domain
|
||||||
* @return {boolean}
|
* @return {boolean} true if the given domain fragment can be found in the window.location.hostname
|
||||||
*/
|
*/
|
||||||
checkDomainName: function (domain) {
|
checkDomainName: function (domain) {
|
||||||
return window.location.hostname.indexOf(domain) !== -1;
|
return window.location.hostname.indexOf(domain) !== -1;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates a value on the Query String and returns it in full.
|
* Updates a value on the Query String and returns it in full.
|
||||||
* If the value doesn't already exist it is set.
|
* If the value doesn't already exist it is set.
|
||||||
* If the value exists it is replaced with the new value given. If you don't provide a new value it is removed from the query string.
|
* If the value exists it is replaced with the new value given. If you don't provide a new value it is removed from the query string.
|
||||||
* Optionally you can redirect to the new url, or just return it as a string.
|
* Optionally you can redirect to the new url, or just return it as a string.
|
||||||
*
|
*
|
||||||
* @method Phaser.Net#updateQueryString
|
* @method Phaser.Net#updateQueryString
|
||||||
* @param {string} key - The querystring key to update.
|
* @param {string} key - The querystring key to update.
|
||||||
* @param {string} value - The new value to be set. If it already exists it will be replaced.
|
* @param {string} value - The new value to be set. If it already exists it will be replaced.
|
||||||
* @param {boolean} redirect - If true the browser will issue a redirect to the url with the new querystring.
|
* @param {boolean} redirect - If true the browser will issue a redirect to the url with the new querystring.
|
||||||
* @param {string} url - The URL to modify. If none is given it uses window.location.href.
|
* @param {string} url - The URL to modify. If none is given it uses window.location.href.
|
||||||
* @return {string} If redirect is false then the modified url and query string is returned.
|
* @return {string} If redirect is false then the modified url and query string is returned.
|
||||||
*/
|
*/
|
||||||
updateQueryString: function (key, value, redirect, url) {
|
updateQueryString: function (key, value, redirect, url) {
|
||||||
|
|
||||||
if (typeof redirect === "undefined") { redirect = false; }
|
if (typeof redirect === "undefined") { redirect = false; }
|
||||||
if (typeof url === "undefined") { url = ''; }
|
if (typeof url === "undefined" || url === '') { url = window.location.href; }
|
||||||
|
|
||||||
if (url == '') {
|
var output = '';
|
||||||
url = window.location.href;
|
var re = new RegExp("([?|&])" + key + "=.*?(&|#|$)(.*)", "gi");
|
||||||
}
|
|
||||||
|
|
||||||
var output = '';
|
if (re.test(url))
|
||||||
var re = new RegExp("([?|&])" + key + "=.*?(&|#|$)(.*)", "gi");
|
{
|
||||||
|
if (typeof value !== 'undefined' && value !== null)
|
||||||
|
{
|
||||||
|
output = url.replace(re, '$1' + key + "=" + value + '$2$3');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
output = url.replace(re, '$1$3').replace(/(&|\?)$/, '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (typeof value !== 'undefined' && value !== null)
|
||||||
|
{
|
||||||
|
var separator = url.indexOf('?') !== -1 ? '&' : '?';
|
||||||
|
var hash = url.split('#');
|
||||||
|
url = hash[0] + separator + key + '=' + value;
|
||||||
|
|
||||||
if (re.test(url))
|
if (hash[1]) {
|
||||||
{
|
url += '#' + hash[1];
|
||||||
if (typeof value !== 'undefined' && value !== null)
|
}
|
||||||
{
|
|
||||||
output = url.replace(re, '$1' + key + "=" + value + '$2$3');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
output = url.replace(re, '$1$3').replace(/(&|\?)$/, '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (typeof value !== 'undefined' && value !== null)
|
|
||||||
{
|
|
||||||
var separator = url.indexOf('?') !== -1 ? '&' : '?';
|
|
||||||
var hash = url.split('#');
|
|
||||||
url = hash[0] + separator + key + '=' + value;
|
|
||||||
|
|
||||||
if (hash[1]) {
|
output = url;
|
||||||
url += '#' + hash[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
output = url;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
output = url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
if (redirect)
|
||||||
else
|
{
|
||||||
{
|
window.location.href = output;
|
||||||
output = url;
|
}
|
||||||
}
|
else
|
||||||
}
|
{
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
if (redirect)
|
},
|
||||||
{
|
|
||||||
window.location.href = output;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
/**
|
||||||
|
* Returns the Query String as an object.
|
||||||
|
* If you specify a parameter it will return just the value of that parameter, should it exist.
|
||||||
|
*
|
||||||
|
* @method Phaser.Net#getQueryString
|
||||||
|
* @param {string} [parameter=''] - If specified this will return just the value for that key.
|
||||||
|
* @return {string|object} An object containing the key value pairs found in the query string or just the value if a parameter was given.
|
||||||
|
*/
|
||||||
|
getQueryString: function (parameter) {
|
||||||
|
|
||||||
/**
|
if (typeof parameter === "undefined") { parameter = ''; }
|
||||||
* Returns the Query String as an object.
|
|
||||||
* If you specify a parameter it will return just the value of that parameter, should it exist.
|
|
||||||
*
|
|
||||||
* @method Phaser.Net#getQueryString
|
|
||||||
* @param {string} [parameter=''] - If specified this will return just the value for that key.
|
|
||||||
* @return {string|object} An object containing the key value pairs found in the query string or just the value if a parameter was given.
|
|
||||||
*/
|
|
||||||
getQueryString: function (parameter) {
|
|
||||||
|
|
||||||
if (typeof parameter === "undefined") { parameter = ''; }
|
var output = {};
|
||||||
|
var keyValues = location.search.substring(1).split('&');
|
||||||
|
|
||||||
var output = {};
|
for (var i in keyValues) {
|
||||||
var keyValues = location.search.substring(1).split('&');
|
|
||||||
|
|
||||||
for (var i in keyValues) {
|
var key = keyValues[i].split('=');
|
||||||
|
|
||||||
var key = keyValues[i].split('=');
|
if (key.length > 1)
|
||||||
|
{
|
||||||
|
if (parameter && parameter == this.decodeURI(key[0]))
|
||||||
|
{
|
||||||
|
return this.decodeURI(key[1]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
output[this.decodeURI(key[0])] = this.decodeURI(key[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (key.length > 1)
|
return output;
|
||||||
{
|
|
||||||
if (parameter && parameter == this.decodeURI(key[0]))
|
|
||||||
{
|
|
||||||
return this.decodeURI(key[1]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
output[this.decodeURI(key[0])] = this.decodeURI(key[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
},
|
||||||
|
|
||||||
},
|
/**
|
||||||
|
* Returns the Query String as an object.
|
||||||
/**
|
* If you specify a parameter it will return just the value of that parameter, should it exist.
|
||||||
* Returns the Query String as an object.
|
*
|
||||||
* If you specify a parameter it will return just the value of that parameter, should it exist.
|
* @method Phaser.Net#decodeURI
|
||||||
*
|
* @param {string} value - The URI component to be decoded.
|
||||||
* @method Phaser.Net#decodeURI
|
* @return {string} The decoded value.
|
||||||
* @param {string} value - The URI component to be decoded.
|
*/
|
||||||
* @return {string} The decoded value.
|
decodeURI: function (value) {
|
||||||
*/
|
return decodeURIComponent(value.replace(/\+/g, " "));
|
||||||
decodeURI: function (value) {
|
}
|
||||||
return decodeURIComponent(value.replace(/\+/g, " "));
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,61 +14,66 @@
|
||||||
*/
|
*/
|
||||||
Phaser.Particles = function (game) {
|
Phaser.Particles = function (game) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Description} emitters - Description.
|
* @property {Phaser.Game} game - A reference to the currently running Game.
|
||||||
*/
|
*/
|
||||||
this.emitters = {};
|
this.game = game;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} ID - Description.
|
* @property {object} emitters - Internal emitters store.
|
||||||
* @default
|
*/
|
||||||
*/
|
this.emitters = {};
|
||||||
this.ID = 0;
|
|
||||||
|
/**
|
||||||
|
* @property {number} ID -
|
||||||
|
* @default
|
||||||
|
*/
|
||||||
|
this.ID = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Phaser.Particles.prototype = {
|
Phaser.Particles.prototype = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new Particle Emitter to the Particle Manager.
|
* Adds a new Particle Emitter to the Particle Manager.
|
||||||
* @method Phaser.Particles#add
|
* @method Phaser.Particles#add
|
||||||
* @param {Phaser.Emitter} emitter - Description.
|
* @param {Phaser.Emitter} emitter - The emitter to be added to the particle manager.
|
||||||
* @return {Phaser.Emitter} The emitter that was added.
|
* @return {Phaser.Emitter} The emitter that was added.
|
||||||
*/
|
*/
|
||||||
add: function (emitter) {
|
add: function (emitter) {
|
||||||
|
|
||||||
this.emitters[emitter.name] = emitter;
|
this.emitters[emitter.name] = emitter;
|
||||||
|
|
||||||
return emitter;
|
return emitter;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes an existing Particle Emitter from the Particle Manager.
|
* Removes an existing Particle Emitter from the Particle Manager.
|
||||||
* @method Phaser.Particles#remove
|
* @method Phaser.Particles#remove
|
||||||
* @param {Phaser.Emitter} emitter - The emitter to remove.
|
* @param {Phaser.Emitter} emitter - The emitter to remove.
|
||||||
*/
|
*/
|
||||||
remove: function (emitter) {
|
remove: function (emitter) {
|
||||||
|
|
||||||
delete this.emitters[emitter.name];
|
delete this.emitters[emitter.name];
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the core game loop. Updates all Emitters who have their exists value set to true.
|
* Called by the core game loop. Updates all Emitters who have their exists value set to true.
|
||||||
* @method Phaser.Particles#update
|
* @method Phaser.Particles#update
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
update: function () {
|
update: function () {
|
||||||
|
|
||||||
for (var key in this.emitters)
|
for (var key in this.emitters)
|
||||||
{
|
{
|
||||||
if (this.emitters[key].exists)
|
if (this.emitters[key].exists)
|
||||||
{
|
{
|
||||||
this.emitters[key].update();
|
this.emitters[key].update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
|
@ -26,36 +26,36 @@ Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) {
|
||||||
* @property {number} maxParticles - The total number of particles in this emitter..
|
* @property {number} maxParticles - The total number of particles in this emitter..
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.maxParticles = maxParticles || 50;
|
this.maxParticles = maxParticles || 50;
|
||||||
|
|
||||||
Phaser.Group.call(this, game);
|
Phaser.Group.call(this, game);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {string} name - Description.
|
* @property {string} name - Description.
|
||||||
*/
|
*/
|
||||||
this.name = 'emitter' + this.game.particles.ID++;
|
this.name = 'emitter' + this.game.particles.ID++;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Description} type - Description.
|
* @property {Description} type - Description.
|
||||||
*/
|
*/
|
||||||
this.type = Phaser.EMITTER;
|
this.type = Phaser.EMITTER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} x - The X position of the top left corner of the emitter in world space.
|
* @property {number} x - The X position of the top left corner of the emitter in world space.
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.x = 0;
|
this.x = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} y - The Y position of the top left corner of emitter in world space.
|
* @property {number} y - The Y position of the top left corner of emitter in world space.
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.y = 0;
|
this.y = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} width - The width of the emitter. Particles can be randomly generated from anywhere within this box.
|
* @property {number} width - The width of the emitter. Particles can be randomly generated from anywhere within this box.
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.width = 1;
|
this.width = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,136 +87,136 @@ Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) {
|
||||||
this.minParticleScale = 1;
|
this.minParticleScale = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum possible scale of a particle.
|
* The maximum possible scale of a particle.
|
||||||
* The default value is 1.
|
* The default value is 1.
|
||||||
* @property {number} maxParticleScale
|
* @property {number} maxParticleScale
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.maxParticleScale = 1;
|
this.maxParticleScale = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The minimum possible angular velocity of a particle. The default value is -360.
|
* The minimum possible angular velocity of a particle. The default value is -360.
|
||||||
* @property {number} minRotation
|
* @property {number} minRotation
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.minRotation = -360;
|
this.minRotation = -360;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum possible angular velocity of a particle. The default value is 360.
|
* The maximum possible angular velocity of a particle. The default value is 360.
|
||||||
* @property {number} maxRotation
|
* @property {number} maxRotation
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.maxRotation = 360;
|
this.maxRotation = 360;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the <code>gravity.y</code> of each particle to this value on launch.
|
* Sets the <code>gravity.y</code> of each particle to this value on launch.
|
||||||
* @property {number} gravity
|
* @property {number} gravity
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.gravity = 2;
|
this.gravity = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set your own particle class type here.
|
* Set your own particle class type here.
|
||||||
* @property {Description} particleClass
|
* @property {Description} particleClass
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.particleClass = null;
|
this.particleClass = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The X and Y drag component of particles launched from the emitter.
|
* The X and Y drag component of particles launched from the emitter.
|
||||||
* @property {Phaser.Point} particleDrag
|
* @property {Phaser.Point} particleDrag
|
||||||
*/
|
*/
|
||||||
this.particleDrag = new Phaser.Point();
|
this.particleDrag = new Phaser.Point();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The angular drag component of particles launched from the emitter if they are rotating.
|
* The angular drag component of particles launched from the emitter if they are rotating.
|
||||||
* @property {number} angularDrag
|
* @property {number} angularDrag
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.angularDrag = 0;
|
this.angularDrag = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How often a particle is emitted in ms (if emitter is started with Explode === false).
|
* How often a particle is emitted in ms (if emitter is started with Explode === false).
|
||||||
* @property {boolean} frequency
|
* @property {boolean} frequency
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.frequency = 100;
|
this.frequency = 100;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How long each particle lives once it is emitted in ms. Default is 2 seconds.
|
* How long each particle lives once it is emitted in ms. Default is 2 seconds.
|
||||||
* Set lifespan to 'zero' for particles to live forever.
|
* Set lifespan to 'zero' for particles to live forever.
|
||||||
* @property {number} lifespan
|
* @property {number} lifespan
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.lifespan = 2000;
|
this.lifespan = 2000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How much each particle should bounce on each axis. 1 = full bounce, 0 = no bounce.
|
* How much each particle should bounce on each axis. 1 = full bounce, 0 = no bounce.
|
||||||
* @property {Phaser.Point} bounce
|
* @property {Phaser.Point} bounce
|
||||||
*/
|
*/
|
||||||
this.bounce = new Phaser.Point();
|
this.bounce = new Phaser.Point();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal helper for deciding how many particles to launch.
|
* Internal helper for deciding how many particles to launch.
|
||||||
* @property {number} _quantity
|
* @property {number} _quantity
|
||||||
* @private
|
* @private
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this._quantity = 0;
|
this._quantity = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal helper for deciding when to launch particles or kill them.
|
* Internal helper for deciding when to launch particles or kill them.
|
||||||
* @property {number} _timer
|
* @property {number} _timer
|
||||||
* @private
|
* @private
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this._timer = 0;
|
this._timer = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal counter for figuring out how many particles to launch.
|
* Internal counter for figuring out how many particles to launch.
|
||||||
* @property {number} _counter
|
* @property {number} _counter
|
||||||
* @private
|
* @private
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this._counter = 0;
|
this._counter = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal helper for the style of particle emission (all at once, or one at a time).
|
* Internal helper for the style of particle emission (all at once, or one at a time).
|
||||||
* @property {boolean} _explode
|
* @property {boolean} _explode
|
||||||
* @private
|
* @private
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this._explode = true;
|
this._explode = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether the emitter is currently emitting particles.
|
* Determines whether the emitter is currently emitting particles.
|
||||||
* It is totally safe to directly toggle this.
|
* It is totally safe to directly toggle this.
|
||||||
* @property {boolean} on
|
* @property {boolean} on
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.on = false;
|
this.on = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether the emitter is being updated by the core game loop.
|
* Determines whether the emitter is being updated by the core game loop.
|
||||||
* @property {boolean} exists
|
* @property {boolean} exists
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.exists = true;
|
this.exists = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The point the particles are emitted from.
|
* The point the particles are emitted from.
|
||||||
* Emitter.x and Emitter.y control the containers location, which updates all current particles
|
* 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.
|
* Emitter.emitX and Emitter.emitY control the emission location relative to the x/y position.
|
||||||
* @property {boolean} emitX
|
* @property {boolean} emitX
|
||||||
*/
|
*/
|
||||||
this.emitX = x;
|
this.emitX = x;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The point the particles are emitted from.
|
* The point the particles are emitted from.
|
||||||
* Emitter.x and Emitter.y control the containers location, which updates all current particles
|
* 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.
|
* Emitter.emitX and Emitter.emitY control the emission location relative to the x/y position.
|
||||||
* @property {boolean} emitY
|
* @property {boolean} emitY
|
||||||
*/
|
*/
|
||||||
this.emitY = y;
|
this.emitY = y;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -234,12 +234,12 @@ Phaser.Particles.Arcade.Emitter.prototype.update = function () {
|
||||||
{
|
{
|
||||||
if (this._explode)
|
if (this._explode)
|
||||||
{
|
{
|
||||||
this._counter = 0;
|
this._counter = 0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
this.emitParticle();
|
this.emitParticle();
|
||||||
this._counter++;
|
this._counter++;
|
||||||
}
|
}
|
||||||
while (this._counter < this._quantity);
|
while (this._counter < this._quantity);
|
||||||
|
|
||||||
|
@ -247,22 +247,22 @@ Phaser.Particles.Arcade.Emitter.prototype.update = function () {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (this.game.time.now >= this._timer)
|
if (this.game.time.now >= this._timer)
|
||||||
{
|
{
|
||||||
this.emitParticle();
|
this.emitParticle();
|
||||||
|
|
||||||
this._counter++;
|
this._counter++;
|
||||||
|
|
||||||
if (this._quantity > 0)
|
if (this._quantity > 0)
|
||||||
{
|
{
|
||||||
if (this._counter >= this._quantity)
|
if (this._counter >= this._quantity)
|
||||||
{
|
{
|
||||||
this.on = false;
|
this.on = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this._timer = this.game.time.now + this.frequency;
|
this._timer = this.game.time.now + this.frequency;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,7 +286,7 @@ Phaser.Particles.Arcade.Emitter.prototype.makeParticles = function (keys, frames
|
||||||
frames = 0;
|
frames = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
quantity = quantity || this.maxParticles;
|
quantity = quantity || this.maxParticles;
|
||||||
collide = collide || 0;
|
collide = collide || 0;
|
||||||
|
|
||||||
if (typeof collideWorldBounds == 'undefined')
|
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);
|
particle = new Phaser.Sprite(this.game, 0, 0, rndKey, rndFrame);
|
||||||
}
|
}
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
// particle = new this.particleClass(this.game);
|
// particle = new this.particleClass(this.game);
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (collide > 0)
|
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) {
|
Phaser.Particles.Arcade.Emitter.prototype.start = function (explode, lifespan, frequency, quantity) {
|
||||||
|
|
||||||
if (typeof explode !== 'boolean')
|
if (typeof explode !== 'boolean')
|
||||||
{
|
{
|
||||||
explode = true;
|
explode = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
lifespan = lifespan || 0;
|
lifespan = lifespan || 0;
|
||||||
|
|
||||||
// How many ms between emissions?
|
// How many ms between emissions?
|
||||||
frequency = frequency || 250;
|
frequency = frequency || 250;
|
||||||
|
|
||||||
// Total number of particles to emit
|
// Total number of particles to emit
|
||||||
quantity = quantity || 0;
|
quantity = quantity || 0;
|
||||||
|
|
||||||
this.revive();
|
this.revive();
|
||||||
|
|
||||||
|
@ -426,16 +426,16 @@ Phaser.Particles.Arcade.Emitter.prototype.emitParticle = function () {
|
||||||
|
|
||||||
if (particle == null)
|
if (particle == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.width > 1 || this.height > 1)
|
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
|
else
|
||||||
{
|
{
|
||||||
particle.reset(this.emitX, this.emitY);
|
particle.reset(this.emitX, this.emitY);
|
||||||
}
|
}
|
||||||
|
|
||||||
particle.lifespan = this.lifespan;
|
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) {
|
Phaser.Particles.Arcade.Emitter.prototype.setXSpeed = function (min, max) {
|
||||||
|
|
||||||
min = min || 0;
|
min = min || 0;
|
||||||
max = max || 0;
|
max = max || 0;
|
||||||
|
|
||||||
this.minParticleSpeed.x = min;
|
this.minParticleSpeed.x = min;
|
||||||
this.maxParticleSpeed.x = max;
|
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) {
|
Phaser.Particles.Arcade.Emitter.prototype.setYSpeed = function (min, max) {
|
||||||
|
|
||||||
min = min || 0;
|
min = min || 0;
|
||||||
max = max || 0;
|
max = max || 0;
|
||||||
|
|
||||||
this.minParticleSpeed.y = min;
|
this.minParticleSpeed.y = min;
|
||||||
this.maxParticleSpeed.y = max;
|
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) {
|
Phaser.Particles.Arcade.Emitter.prototype.setRotation = function (min, max) {
|
||||||
|
|
||||||
min = min || 0;
|
min = min || 0;
|
||||||
max = max || 0;
|
max = max || 0;
|
||||||
|
|
||||||
this.minRotation = min;
|
this.minRotation = min;
|
||||||
this.maxRotation = max;
|
this.maxRotation = max;
|
||||||
|
|
|
@ -27,10 +27,10 @@ function QuadTree(bounds, pointQuad, maxDepth, maxChildren){
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The root node of the QuadTree which covers the entire area being segmented.
|
* The root node of the QuadTree which covers the entire area being segmented.
|
||||||
* @property root
|
* @property root
|
||||||
* @type Node
|
* @type Node
|
||||||
*/
|
*/
|
||||||
this.root = node;
|
this.root = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +299,7 @@ BoundsNode.prototype.insert = function(item){
|
||||||
console.log("radius:",item.boundingRadius);
|
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 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);
|
console.log("item y:",item.position[1] - item.boundingRadius,"y range:",node.bounds.y,node.bounds.y+node.bounds.height);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//todo: make _bounds bounds
|
//todo: make _bounds bounds
|
||||||
if( !(item instanceof Plane) && // Plane is infinite.. Make it a "stuck" child
|
if( !(item instanceof Plane) && // Plane is infinite.. Make it a "stuck" child
|
||||||
|
|
|
@ -19,24 +19,24 @@ function SAP1DBroadphase(world){
|
||||||
Broadphase.apply(this);
|
Broadphase.apply(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of bodies currently in the broadphase.
|
* List of bodies currently in the broadphase.
|
||||||
* @property axisList
|
* @property axisList
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
*/
|
*/
|
||||||
this.axisList = world.bodies.slice(0);
|
this.axisList = world.bodies.slice(0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The world to search in.
|
* The world to search in.
|
||||||
* @property world
|
* @property world
|
||||||
* @type {World}
|
* @type {World}
|
||||||
*/
|
*/
|
||||||
this.world = 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.
|
* 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
|
* @property axisIndex
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.axisIndex = 0;
|
this.axisIndex = 0;
|
||||||
|
|
||||||
// Add listeners to update the list of bodies.
|
// Add listeners to update the list of bodies.
|
||||||
|
|
|
@ -12,24 +12,24 @@ module.exports = Constraint;
|
||||||
function Constraint(bodyA,bodyB){
|
function Constraint(bodyA,bodyB){
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Equations to be solved in this constraint
|
* Equations to be solved in this constraint
|
||||||
* @property equations
|
* @property equations
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
*/
|
*/
|
||||||
this.equations = [];
|
this.equations = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* First body participating in the constraint.
|
* First body participating in the constraint.
|
||||||
* @property bodyA
|
* @property bodyA
|
||||||
* @type {Body}
|
* @type {Body}
|
||||||
*/
|
*/
|
||||||
this.bodyA = bodyA;
|
this.bodyA = bodyA;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Second body participating in the constraint.
|
* Second body participating in the constraint.
|
||||||
* @property bodyB
|
* @property bodyB
|
||||||
* @type {Body}
|
* @type {Body}
|
||||||
*/
|
*/
|
||||||
this.bodyB = bodyB;
|
this.bodyB = bodyB;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,45 +12,45 @@ module.exports = Equation;
|
||||||
function Equation(bi,bj,minForce,maxForce){
|
function Equation(bi,bj,minForce,maxForce){
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Minimum force to apply when solving
|
* Minimum force to apply when solving
|
||||||
* @property minForce
|
* @property minForce
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.minForce = typeof(minForce)=="undefined" ? -1e6 : minForce;
|
this.minForce = typeof(minForce)=="undefined" ? -1e6 : minForce;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Max force to apply when solving
|
* Max force to apply when solving
|
||||||
* @property maxForce
|
* @property maxForce
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.maxForce = typeof(maxForce)=="undefined" ? 1e6 : maxForce;
|
this.maxForce = typeof(maxForce)=="undefined" ? 1e6 : maxForce;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* First body participating in the constraint
|
* First body participating in the constraint
|
||||||
* @property bi
|
* @property bi
|
||||||
* @type {Body}
|
* @type {Body}
|
||||||
*/
|
*/
|
||||||
this.bi = bi;
|
this.bi = bi;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Second body participating in the constraint
|
* Second body participating in the constraint
|
||||||
* @property bj
|
* @property bj
|
||||||
* @type {Body}
|
* @type {Body}
|
||||||
*/
|
*/
|
||||||
this.bj = bj;
|
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.
|
* 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
|
* @property stiffness
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.stiffness = 1e6;
|
this.stiffness = 1e6;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of time steps needed to stabilize the constraint equation. Typically between 3 and 5 time steps.
|
* The number of time steps needed to stabilize the constraint equation. Typically between 3 and 5 time steps.
|
||||||
* @property relaxation
|
* @property relaxation
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.relaxation = 4;
|
this.relaxation = 4;
|
||||||
|
|
||||||
this.a = 0;
|
this.a = 0;
|
||||||
|
|
|
@ -31,24 +31,24 @@ function FrictionEquation(bi,bj,slipForce){
|
||||||
Equation.call(this,bi,bj,-slipForce,slipForce);
|
Equation.call(this,bi,bj,-slipForce,slipForce);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Relative vector from center of body i to the contact point, in world coords.
|
* Relative vector from center of body i to the contact point, in world coords.
|
||||||
* @property ri
|
* @property ri
|
||||||
* @type {Float32Array}
|
* @type {Float32Array}
|
||||||
*/
|
*/
|
||||||
this.ri = vec2.create();
|
this.ri = vec2.create();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Relative vector from center of body j to the contact point, in world coords.
|
* Relative vector from center of body j to the contact point, in world coords.
|
||||||
* @property rj
|
* @property rj
|
||||||
* @type {Float32Array}
|
* @type {Float32Array}
|
||||||
*/
|
*/
|
||||||
this.rj = vec2.create();
|
this.rj = vec2.create();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tangent vector that the friction force will act along, in world coords.
|
* Tangent vector that the friction force will act along, in world coords.
|
||||||
* @property t
|
* @property t
|
||||||
* @type {Float32Array}
|
* @type {Float32Array}
|
||||||
*/
|
*/
|
||||||
this.t = vec2.create();
|
this.t = vec2.create();
|
||||||
|
|
||||||
this.rixt = 0;
|
this.rixt = 0;
|
||||||
|
|
|
@ -11,12 +11,12 @@ EventEmitter.prototype = {
|
||||||
constructor: EventEmitter,
|
constructor: EventEmitter,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an event listener
|
* Add an event listener
|
||||||
* @method on
|
* @method on
|
||||||
* @param {String} type
|
* @param {String} type
|
||||||
* @param {Function} listener
|
* @param {Function} listener
|
||||||
* @return {EventEmitter} The self object, for chainability.
|
* @return {EventEmitter} The self object, for chainability.
|
||||||
*/
|
*/
|
||||||
on: function ( type, listener ) {
|
on: function ( type, listener ) {
|
||||||
if ( this._listeners === undefined ) this._listeners = {};
|
if ( this._listeners === undefined ) this._listeners = {};
|
||||||
var listeners = this._listeners;
|
var listeners = this._listeners;
|
||||||
|
@ -30,12 +30,12 @@ EventEmitter.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if an event listener is added
|
* Check if an event listener is added
|
||||||
* @method has
|
* @method has
|
||||||
* @param {String} type
|
* @param {String} type
|
||||||
* @param {Function} listener
|
* @param {Function} listener
|
||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
*/
|
*/
|
||||||
has: function ( type, listener ) {
|
has: function ( type, listener ) {
|
||||||
if ( this._listeners === undefined ) return false;
|
if ( this._listeners === undefined ) return false;
|
||||||
var listeners = this._listeners;
|
var listeners = this._listeners;
|
||||||
|
@ -46,12 +46,12 @@ EventEmitter.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove an event listener
|
* Remove an event listener
|
||||||
* @method off
|
* @method off
|
||||||
* @param {String} type
|
* @param {String} type
|
||||||
* @param {Function} listener
|
* @param {Function} listener
|
||||||
* @return {EventEmitter} The self object, for chainability.
|
* @return {EventEmitter} The self object, for chainability.
|
||||||
*/
|
*/
|
||||||
off: function ( type, listener ) {
|
off: function ( type, listener ) {
|
||||||
if ( this._listeners === undefined ) return;
|
if ( this._listeners === undefined ) return;
|
||||||
var listeners = this._listeners;
|
var listeners = this._listeners;
|
||||||
|
@ -63,12 +63,12 @@ EventEmitter.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emit an event.
|
* Emit an event.
|
||||||
* @method emit
|
* @method emit
|
||||||
* @param {Object} event
|
* @param {Object} event
|
||||||
* @param {String} event.type
|
* @param {String} event.type
|
||||||
* @return {EventEmitter} The self object, for chainability.
|
* @return {EventEmitter} The self object, for chainability.
|
||||||
*/
|
*/
|
||||||
emit: function ( event ) {
|
emit: function ( event ) {
|
||||||
if ( this._listeners === undefined ) return;
|
if ( this._listeners === undefined ) return;
|
||||||
var listeners = this._listeners;
|
var listeners = this._listeners;
|
||||||
|
|
|
@ -17,65 +17,65 @@ function ContactMaterial(materialA, materialB, options){
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The contact material identifier
|
* The contact material identifier
|
||||||
* @property id
|
* @property id
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.id = idCounter++;
|
this.id = idCounter++;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* First material participating in the contact material
|
* First material participating in the contact material
|
||||||
* @property materialA
|
* @property materialA
|
||||||
* @type {Material}
|
* @type {Material}
|
||||||
*/
|
*/
|
||||||
this.materialA = materialA;
|
this.materialA = materialA;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Second material participating in the contact material
|
* Second material participating in the contact material
|
||||||
* @property materialB
|
* @property materialB
|
||||||
* @type {Material}
|
* @type {Material}
|
||||||
*/
|
*/
|
||||||
this.materialB = materialB;
|
this.materialB = materialB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Friction to use in the contact of these two materials
|
* Friction to use in the contact of these two materials
|
||||||
* @property friction
|
* @property friction
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.friction = typeof(options.friction) !== "undefined" ? Number(options.friction) : 0.3;
|
this.friction = typeof(options.friction) !== "undefined" ? Number(options.friction) : 0.3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restitution to use in the contact of these two materials
|
* Restitution to use in the contact of these two materials
|
||||||
* @property restitution
|
* @property restitution
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.restitution = typeof(options.restitution) !== "undefined" ? Number(options.restitution) : 0.3;
|
this.restitution = typeof(options.restitution) !== "undefined" ? Number(options.restitution) : 0.3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stiffness of the resulting ContactEquation that this ContactMaterial generate
|
* Stiffness of the resulting ContactEquation that this ContactMaterial generate
|
||||||
* @property stiffness
|
* @property stiffness
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.stiffness = typeof(options.stiffness) !== "undefined" ? Number(options.stiffness) : 1e7;
|
this.stiffness = typeof(options.stiffness) !== "undefined" ? Number(options.stiffness) : 1e7;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Relaxation of the resulting ContactEquation that this ContactMaterial generate
|
* Relaxation of the resulting ContactEquation that this ContactMaterial generate
|
||||||
* @property relaxation
|
* @property relaxation
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.relaxation = typeof(options.relaxation) !== "undefined" ? Number(options.relaxation) : 3;
|
this.relaxation = typeof(options.relaxation) !== "undefined" ? Number(options.relaxation) : 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stiffness of the resulting FrictionEquation that this ContactMaterial generate
|
* Stiffness of the resulting FrictionEquation that this ContactMaterial generate
|
||||||
* @property frictionStiffness
|
* @property frictionStiffness
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.frictionStiffness = typeof(options.frictionStiffness) !== "undefined" ? Number(options.frictionStiffness) : 1e7;
|
this.frictionStiffness = typeof(options.frictionStiffness) !== "undefined" ? Number(options.frictionStiffness) : 1e7;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Relaxation of the resulting FrictionEquation that this ContactMaterial generate
|
* Relaxation of the resulting FrictionEquation that this ContactMaterial generate
|
||||||
* @property frictionRelaxation
|
* @property frictionRelaxation
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.frictionRelaxation = typeof(options.frictionRelaxation) !== "undefined" ? Number(options.frictionRelaxation) : 3;
|
this.frictionRelaxation = typeof(options.frictionRelaxation) !== "undefined" ? Number(options.frictionRelaxation) : 3;
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,9 +11,9 @@ var idCounter = 0;
|
||||||
*/
|
*/
|
||||||
function Material(){
|
function Material(){
|
||||||
/**
|
/**
|
||||||
* The material identifier
|
* The material identifier
|
||||||
* @property id
|
* @property id
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.id = idCounter++;
|
this.id = idCounter++;
|
||||||
};
|
};
|
||||||
|
|
|
@ -472,6 +472,6 @@
|
||||||
|
|
||||||
PolyK._tp = [];
|
PolyK._tp = [];
|
||||||
for(var i=0; i<10; i++) PolyK._tp.push(new PolyK._P(0,0));
|
for(var i=0; i<10; i++) PolyK._tp.push(new PolyK._P(0,0));
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = PolyK;
|
module.exports = PolyK;
|
||||||
|
|
|
@ -25,155 +25,155 @@ function Body(options){
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The body identifyer
|
* The body identifyer
|
||||||
* @property id
|
* @property id
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.id = ++Body._idCounter;
|
this.id = ++Body._idCounter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The shapes of the body. The local transform of the shape in .shapes[i] is
|
* The shapes of the body. The local transform of the shape in .shapes[i] is
|
||||||
* defined by .shapeOffsets[i] and .shapeAngles[i].
|
* defined by .shapeOffsets[i] and .shapeAngles[i].
|
||||||
*
|
*
|
||||||
* @property shapes
|
* @property shapes
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
*/
|
*/
|
||||||
this.shapes = [];
|
this.shapes = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The local shape offsets, relative to the body center of mass. This is an
|
* The local shape offsets, relative to the body center of mass. This is an
|
||||||
* array of Float32Array.
|
* array of Float32Array.
|
||||||
* @property shapeOffsets
|
* @property shapeOffsets
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
*/
|
*/
|
||||||
this.shapeOffsets = [];
|
this.shapeOffsets = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The body-local shape angle transforms. This is an array of numbers (angles).
|
* The body-local shape angle transforms. This is an array of numbers (angles).
|
||||||
* @property shapeAngles
|
* @property shapeAngles
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
*/
|
*/
|
||||||
this.shapeAngles = [];
|
this.shapeAngles = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The mass of the body.
|
* The mass of the body.
|
||||||
* @property mass
|
* @property mass
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.mass = options.mass || 0;
|
this.mass = options.mass || 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The inverse mass of the body.
|
* The inverse mass of the body.
|
||||||
* @property invMass
|
* @property invMass
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.invMass = 0;
|
this.invMass = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The inertia of the body around the Z axis.
|
* The inertia of the body around the Z axis.
|
||||||
* @property inertia
|
* @property inertia
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.inertia = 0;
|
this.inertia = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The inverse inertia of the body.
|
* The inverse inertia of the body.
|
||||||
* @property invInertia
|
* @property invInertia
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.invInertia = 0;
|
this.invInertia = 0;
|
||||||
|
|
||||||
this.updateMassProperties();
|
this.updateMassProperties();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The position of the body
|
* The position of the body
|
||||||
* @property position
|
* @property position
|
||||||
* @type {Float32Array}
|
* @type {Float32Array}
|
||||||
*/
|
*/
|
||||||
this.position = vec2.fromValues(0,0);
|
this.position = vec2.fromValues(0,0);
|
||||||
if(options.position) vec2.copy(this.position, options.position);
|
if(options.position) vec2.copy(this.position, options.position);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The velocity of the body
|
* The velocity of the body
|
||||||
* @property velocity
|
* @property velocity
|
||||||
* @type {Float32Array}
|
* @type {Float32Array}
|
||||||
*/
|
*/
|
||||||
this.velocity = vec2.fromValues(0,0);
|
this.velocity = vec2.fromValues(0,0);
|
||||||
if(options.velocity) vec2.copy(this.velocity, options.velocity);
|
if(options.velocity) vec2.copy(this.velocity, options.velocity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constraint velocity that was added to the body during the last step.
|
* Constraint velocity that was added to the body during the last step.
|
||||||
* @property vlambda
|
* @property vlambda
|
||||||
* @type {Float32Array}
|
* @type {Float32Array}
|
||||||
*/
|
*/
|
||||||
this.vlambda = vec2.fromValues(0,0);
|
this.vlambda = vec2.fromValues(0,0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Angular constraint velocity that was added to the body during last step.
|
* Angular constraint velocity that was added to the body during last step.
|
||||||
* @property wlambda
|
* @property wlambda
|
||||||
* @type {Float32Array}
|
* @type {Float32Array}
|
||||||
*/
|
*/
|
||||||
this.wlambda = 0;
|
this.wlambda = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The angle of the body
|
* The angle of the body
|
||||||
* @property angle
|
* @property angle
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.angle = options.angle || 0;
|
this.angle = options.angle || 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The angular velocity of the body
|
* The angular velocity of the body
|
||||||
* @property angularVelocity
|
* @property angularVelocity
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.angularVelocity = options.angularVelocity || 0;
|
this.angularVelocity = options.angularVelocity || 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The force acting on the body
|
* The force acting on the body
|
||||||
* @property force
|
* @property force
|
||||||
* @type {Float32Array}
|
* @type {Float32Array}
|
||||||
*/
|
*/
|
||||||
this.force = vec2.create();
|
this.force = vec2.create();
|
||||||
if(options.force) vec2.copy(this.force, options.force);
|
if(options.force) vec2.copy(this.force, options.force);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The angular force acting on the body
|
* The angular force acting on the body
|
||||||
* @property angularForce
|
* @property angularForce
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.angularForce = options.angularForce || 0;
|
this.angularForce = options.angularForce || 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type of motion this body has. Should be one of: Body.STATIC (the body
|
* 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)
|
* does not move), Body.DYNAMIC (body can move and respond to collisions)
|
||||||
* and Body.KINEMATIC (only moves according to its .velocity).
|
* and Body.KINEMATIC (only moves according to its .velocity).
|
||||||
*
|
*
|
||||||
* @property motionState
|
* @property motionState
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // This body will move and interact with other bodies
|
* // This body will move and interact with other bodies
|
||||||
* var dynamicBody = new Body();
|
* var dynamicBody = new Body();
|
||||||
* dynamicBody.motionState = Body.DYNAMIC;
|
* dynamicBody.motionState = Body.DYNAMIC;
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // This body will not move at all
|
* // This body will not move at all
|
||||||
* var staticBody = new Body();
|
* var staticBody = new Body();
|
||||||
* staticBody.motionState = Body.STATIC;
|
* staticBody.motionState = Body.STATIC;
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // This body will only move if you change its velocity
|
* // This body will only move if you change its velocity
|
||||||
* var kinematicBody = new Body();
|
* var kinematicBody = new Body();
|
||||||
* kinematicBody.motionState = Body.KINEMATIC;
|
* kinematicBody.motionState = Body.KINEMATIC;
|
||||||
*/
|
*/
|
||||||
this.motionState = this.mass === 0 ? Body.STATIC : Body.DYNAMIC;
|
this.motionState = this.mass === 0 ? Body.STATIC : Body.DYNAMIC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bounding circle radius
|
* Bounding circle radius
|
||||||
* @property boundingRadius
|
* @property boundingRadius
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.boundingRadius = 0;
|
this.boundingRadius = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -22,52 +22,52 @@ function Spring(bodyA,bodyB,options){
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rest length of the spring.
|
* Rest length of the spring.
|
||||||
* @property restLength
|
* @property restLength
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.restLength = typeof(options.restLength)=="number" ? options.restLength : 1;
|
this.restLength = typeof(options.restLength)=="number" ? options.restLength : 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stiffness of the spring.
|
* Stiffness of the spring.
|
||||||
* @property stiffness
|
* @property stiffness
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.stiffness = options.stiffness || 100;
|
this.stiffness = options.stiffness || 100;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Damping of the spring.
|
* Damping of the spring.
|
||||||
* @property damping
|
* @property damping
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.damping = options.damping || 1;
|
this.damping = options.damping || 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* First connected body.
|
* First connected body.
|
||||||
* @property bodyA
|
* @property bodyA
|
||||||
* @type {Body}
|
* @type {Body}
|
||||||
*/
|
*/
|
||||||
this.bodyA = bodyA;
|
this.bodyA = bodyA;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Second connected body.
|
* Second connected body.
|
||||||
* @property bodyB
|
* @property bodyB
|
||||||
* @type {Body}
|
* @type {Body}
|
||||||
*/
|
*/
|
||||||
this.bodyB = bodyB;
|
this.bodyB = bodyB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Anchor for bodyA in local bodyA coordinates.
|
* Anchor for bodyA in local bodyA coordinates.
|
||||||
* @property localAnchorA
|
* @property localAnchorA
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
*/
|
*/
|
||||||
this.localAnchorA = vec2.fromValues(0,0);
|
this.localAnchorA = vec2.fromValues(0,0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Anchor for bodyB in local bodyB coordinates.
|
* Anchor for bodyB in local bodyB coordinates.
|
||||||
* @property localAnchorB
|
* @property localAnchorB
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
*/
|
*/
|
||||||
this.localAnchorB = vec2.fromValues(0,0);
|
this.localAnchorB = vec2.fromValues(0,0);
|
||||||
|
|
||||||
if(options.localAnchorA) vec2.copy(this.localAnchorA, options.localAnchorA);
|
if(options.localAnchorA) vec2.copy(this.localAnchorA, options.localAnchorA);
|
||||||
|
|
|
@ -12,10 +12,10 @@ module.exports = Circle;
|
||||||
function Circle(radius){
|
function Circle(radius){
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The radius of the circle.
|
* The radius of the circle.
|
||||||
* @property radius
|
* @property radius
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.radius = radius || 1;
|
this.radius = radius || 1;
|
||||||
|
|
||||||
Shape.call(this,Shape.CIRCLE);
|
Shape.call(this,Shape.CIRCLE);
|
||||||
|
|
|
@ -14,24 +14,24 @@ module.exports = Convex;
|
||||||
function Convex(vertices){
|
function Convex(vertices){
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vertices defined in the local frame.
|
* Vertices defined in the local frame.
|
||||||
* @property vertices
|
* @property vertices
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
*/
|
*/
|
||||||
this.vertices = vertices || [];
|
this.vertices = vertices || [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The center of mass of the Convex
|
* The center of mass of the Convex
|
||||||
* @property centerOfMass
|
* @property centerOfMass
|
||||||
* @type {Float32Array}
|
* @type {Float32Array}
|
||||||
*/
|
*/
|
||||||
this.centerOfMass = vec2.fromValues(0,0);
|
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.
|
* Triangulated version of this convex. The structure is Array of 3-Arrays, and each subarray contains 3 integers, referencing the vertices.
|
||||||
* @property triangles
|
* @property triangles
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
*/
|
*/
|
||||||
this.triangles = [];
|
this.triangles = [];
|
||||||
|
|
||||||
if(this.vertices.length){
|
if(this.vertices.length){
|
||||||
|
@ -40,10 +40,10 @@ function Convex(vertices){
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The bounding radius of the convex
|
* The bounding radius of the convex
|
||||||
* @property boundingRadius
|
* @property boundingRadius
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.boundingRadius = 0;
|
this.boundingRadius = 0;
|
||||||
this.updateBoundingRadius();
|
this.updateBoundingRadius();
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,10 @@ module.exports = Line;
|
||||||
function Line(length){
|
function Line(length){
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Length of this line
|
* Length of this line
|
||||||
* @property length
|
* @property length
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.length = length;
|
this.length = length;
|
||||||
|
|
||||||
Shape.call(this,Shape.LINE);
|
Shape.call(this,Shape.LINE);
|
||||||
|
|
|
@ -9,56 +9,56 @@ function Shape(type){
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bounding circle radius of this shape
|
* Bounding circle radius of this shape
|
||||||
* @property boundingRadius
|
* @property boundingRadius
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.boundingRadius = 0;
|
this.boundingRadius = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collision group that this shape belongs to (bit mask). See <a href="http://www.aurelienribon.com/blog/2011/07/box2d-tutorial-collision-filtering/">this tutorial</a>.
|
* Collision group that this shape belongs to (bit mask). See <a href="http://www.aurelienribon.com/blog/2011/07/box2d-tutorial-collision-filtering/">this tutorial</a>.
|
||||||
* @property collisionGroup
|
* @property collisionGroup
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
* @example
|
* @example
|
||||||
* // Setup bits for each available group
|
* // Setup bits for each available group
|
||||||
* var PLAYER = Math.pow(2,0),
|
* var PLAYER = Math.pow(2,0),
|
||||||
* ENEMY = Math.pow(2,1),
|
* ENEMY = Math.pow(2,1),
|
||||||
* GROUND = Math.pow(2,2)
|
* GROUND = Math.pow(2,2)
|
||||||
*
|
*
|
||||||
* // Put shapes into their groups
|
* // Put shapes into their groups
|
||||||
* player1Shape.collisionGroup = PLAYER;
|
* player1Shape.collisionGroup = PLAYER;
|
||||||
* player2Shape.collisionGroup = PLAYER;
|
* player2Shape.collisionGroup = PLAYER;
|
||||||
* enemyShape .collisionGroup = ENEMY;
|
* enemyShape .collisionGroup = ENEMY;
|
||||||
* groundShape .collisionGroup = GROUND;
|
* groundShape .collisionGroup = GROUND;
|
||||||
*
|
*
|
||||||
* // Assign groups that each shape collide with.
|
* // Assign groups that each shape collide with.
|
||||||
* // Note that the players can collide with ground and enemies, but not with other players.
|
* // Note that the players can collide with ground and enemies, but not with other players.
|
||||||
* player1Shape.collisionMask = ENEMY | GROUND;
|
* player1Shape.collisionMask = ENEMY | GROUND;
|
||||||
* player2Shape.collisionMask = ENEMY | GROUND;
|
* player2Shape.collisionMask = ENEMY | GROUND;
|
||||||
* enemyShape .collisionMask = PLAYER | GROUND;
|
* enemyShape .collisionMask = PLAYER | GROUND;
|
||||||
* groundShape .collisionMask = PLAYER | ENEMY;
|
* groundShape .collisionMask = PLAYER | ENEMY;
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // How collision check is done
|
* // How collision check is done
|
||||||
* if(shapeA.collisionGroup & shapeB.collisionMask)!=0 && (shapeB.collisionGroup & shapeA.collisionMask)!=0){
|
* if(shapeA.collisionGroup & shapeB.collisionMask)!=0 && (shapeB.collisionGroup & shapeA.collisionMask)!=0){
|
||||||
* // The shapes will collide
|
* // The shapes will collide
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
this.collisionGroup = 1;
|
this.collisionGroup = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collision mask of this shape. See .collisionGroup.
|
* Collision mask of this shape. See .collisionGroup.
|
||||||
* @property collisionMask
|
* @property collisionMask
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.collisionMask = 1;
|
this.collisionMask = 1;
|
||||||
if(type) this.updateBoundingRadius();
|
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.
|
* Material to use in collisions for this Shape. If this is set to null, the world will use default material properties instead.
|
||||||
* @property material
|
* @property material
|
||||||
* @type {Material}
|
* @type {Material}
|
||||||
*/
|
*/
|
||||||
this.material = null;
|
this.material = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,31 +30,31 @@ function GSSolver(options){
|
||||||
this.invCs = new ARRAY_TYPE(this.arrayStep);
|
this.invCs = new ARRAY_TYPE(this.arrayStep);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to use .stiffness and .relaxation parameters from the Solver instead of each Equation individually.
|
* Whether to use .stiffness and .relaxation parameters from the Solver instead of each Equation individually.
|
||||||
* @type {Boolean}
|
* @type {Boolean}
|
||||||
* @property useGlobalEquationParameters
|
* @property useGlobalEquationParameters
|
||||||
*/
|
*/
|
||||||
this.useGlobalEquationParameters = true;
|
this.useGlobalEquationParameters = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Global equation stiffness.
|
* Global equation stiffness.
|
||||||
* @property stiffness
|
* @property stiffness
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.stiffness = 1e6;
|
this.stiffness = 1e6;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Global equation relaxation.
|
* Global equation relaxation.
|
||||||
* @property relaxation
|
* @property relaxation
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.relaxation = 4;
|
this.relaxation = 4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set to true to set all right hand side terms to zero when solving. Can be handy for a few applications.
|
* Set to true to set all right hand side terms to zero when solving. Can be handy for a few applications.
|
||||||
* @property useZeroRHS
|
* @property useZeroRHS
|
||||||
* @type {Boolean}
|
* @type {Boolean}
|
||||||
*/
|
*/
|
||||||
this.useZeroRHS = false;
|
this.useZeroRHS = false;
|
||||||
};
|
};
|
||||||
GSSolver.prototype = new Solver();
|
GSSolver.prototype = new Solver();
|
||||||
|
|
|
@ -8,17 +8,17 @@ module.exports = Island;
|
||||||
function Island(){
|
function Island(){
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current equations in this island.
|
* Current equations in this island.
|
||||||
* @property equations
|
* @property equations
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
*/
|
*/
|
||||||
this.equations = [];
|
this.equations = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current bodies in this island.
|
* Current bodies in this island.
|
||||||
* @property bodies
|
* @property bodies
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
*/
|
*/
|
||||||
this.bodies = [];
|
this.bodies = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,17 +19,17 @@ function IslandSolver(subsolver){
|
||||||
var that = this;
|
var that = this;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The solver used in the workers.
|
* The solver used in the workers.
|
||||||
* @property subsolver
|
* @property subsolver
|
||||||
* @type {Solver}
|
* @type {Solver}
|
||||||
*/
|
*/
|
||||||
this.subsolver = subsolver;
|
this.subsolver = subsolver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of islands
|
* Number of islands
|
||||||
* @property numIslands
|
* @property numIslands
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.numIslands = 0;
|
this.numIslands = 0;
|
||||||
|
|
||||||
// Pooling of node objects saves some GC load
|
// Pooling of node objects saves some GC load
|
||||||
|
|
|
@ -10,11 +10,11 @@ module.exports = Solver;
|
||||||
function Solver(){
|
function Solver(){
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current equations in the solver.
|
* Current equations in the solver.
|
||||||
*
|
*
|
||||||
* @property equations
|
* @property equations
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
*/
|
*/
|
||||||
this.equations = [];
|
this.equations = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -48,110 +48,110 @@ function World(options){
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All springs in the world.
|
* All springs in the world.
|
||||||
*
|
*
|
||||||
* @property springs
|
* @property springs
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
*/
|
*/
|
||||||
this.springs = [];
|
this.springs = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All bodies in the world.
|
* All bodies in the world.
|
||||||
*
|
*
|
||||||
* @property bodies
|
* @property bodies
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
*/
|
*/
|
||||||
this.bodies = [];
|
this.bodies = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The solver used to satisfy constraints and contacts.
|
* The solver used to satisfy constraints and contacts.
|
||||||
*
|
*
|
||||||
* @property solver
|
* @property solver
|
||||||
* @type {Solver}
|
* @type {Solver}
|
||||||
*/
|
*/
|
||||||
this.solver = options.solver || new GSSolver();
|
this.solver = options.solver || new GSSolver();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The nearphase to use to generate contacts.
|
* The nearphase to use to generate contacts.
|
||||||
*
|
*
|
||||||
* @property nearphase
|
* @property nearphase
|
||||||
* @type {Nearphase}
|
* @type {Nearphase}
|
||||||
*/
|
*/
|
||||||
this.nearphase = new Nearphase();
|
this.nearphase = new Nearphase();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gravity in the world. This is applied on all bodies in the beginning of each step().
|
* Gravity in the world. This is applied on all bodies in the beginning of each step().
|
||||||
*
|
*
|
||||||
* @property
|
* @property
|
||||||
* @type {Float32Array}
|
* @type {Float32Array}
|
||||||
*/
|
*/
|
||||||
this.gravity = options.gravity || vec2.fromValues(0, -9.78);
|
this.gravity = options.gravity || vec2.fromValues(0, -9.78);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to do timing measurements during the step() or not.
|
* Whether to do timing measurements during the step() or not.
|
||||||
*
|
*
|
||||||
* @property doPofiling
|
* @property doPofiling
|
||||||
* @type {Boolean}
|
* @type {Boolean}
|
||||||
*/
|
*/
|
||||||
this.doProfiling = options.doProfiling || false;
|
this.doProfiling = options.doProfiling || false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How many millisecconds the last step() took. This is updated each step if .doProfiling is set to true.
|
* How many millisecconds the last step() took. This is updated each step if .doProfiling is set to true.
|
||||||
*
|
*
|
||||||
* @property lastStepTime
|
* @property lastStepTime
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.lastStepTime = 0.0;
|
this.lastStepTime = 0.0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The broadphase algorithm to use.
|
* The broadphase algorithm to use.
|
||||||
*
|
*
|
||||||
* @property broadphase
|
* @property broadphase
|
||||||
* @type {Broadphase}
|
* @type {Broadphase}
|
||||||
*/
|
*/
|
||||||
this.broadphase = options.broadphase || new NaiveBroadphase();
|
this.broadphase = options.broadphase || new NaiveBroadphase();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User-added constraints.
|
* User-added constraints.
|
||||||
*
|
*
|
||||||
* @property constraints
|
* @property constraints
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
*/
|
*/
|
||||||
this.constraints = [];
|
this.constraints = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Friction between colliding bodies. This value is used if no matching ContactMaterial is found for the body pair.
|
* Friction between colliding bodies. This value is used if no matching ContactMaterial is found for the body pair.
|
||||||
* @property defaultFriction
|
* @property defaultFriction
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.defaultFriction = 0.1;
|
this.defaultFriction = 0.1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For keeping track of what time step size we used last step
|
* For keeping track of what time step size we used last step
|
||||||
* @property lastTimeStep
|
* @property lastTimeStep
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.lastTimeStep = 1/60;
|
this.lastTimeStep = 1/60;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable to automatically apply spring forces each step.
|
* Enable to automatically apply spring forces each step.
|
||||||
* @property applySpringForces
|
* @property applySpringForces
|
||||||
* @type {Boolean}
|
* @type {Boolean}
|
||||||
*/
|
*/
|
||||||
this.applySpringForces = true;
|
this.applySpringForces = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable/disable constraint solving in each step.
|
* Enable/disable constraint solving in each step.
|
||||||
* @property solveConstraints
|
* @property solveConstraints
|
||||||
* @type {Boolean}
|
* @type {Boolean}
|
||||||
*/
|
*/
|
||||||
this.solveConstraints = true;
|
this.solveConstraints = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ContactMaterials added to the World.
|
* The ContactMaterials added to the World.
|
||||||
* @property contactMaterials
|
* @property contactMaterials
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
*/
|
*/
|
||||||
this.contactMaterials = [];
|
this.contactMaterials = [];
|
||||||
|
|
||||||
// Id counters
|
// Id counters
|
||||||
|
|
|
@ -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.
|
* @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.
|
* @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.
|
* @property {Phaser.Rectangle} _bounds1 - Internal cache var.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._bounds1 = new Phaser.Rectangle;
|
this._bounds1 = new Phaser.Rectangle();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Phaser.Rectangle} _bounds2 - Internal cache var.
|
* @property {Phaser.Rectangle} _bounds2 - Internal cache var.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._bounds2 = new Phaser.Rectangle;
|
this._bounds2 = new Phaser.Rectangle();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} _overlap - Internal cache var.
|
* @property {number} _overlap - Internal cache var.
|
||||||
|
@ -658,7 +658,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||||
if (this._overlap != 0)
|
if (this._overlap !== 0)
|
||||||
{
|
{
|
||||||
body1.overlapX = this._overlap;
|
body1.overlapX = this._overlap;
|
||||||
body2.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)
|
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||||
if (this._overlap != 0)
|
if (this._overlap !== 0)
|
||||||
{
|
{
|
||||||
body1.overlapY = this._overlap;
|
body1.overlapY = this._overlap;
|
||||||
body2.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)
|
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||||
if (this._overlap != 0)
|
if (this._overlap !== 0)
|
||||||
{
|
{
|
||||||
if (separate)
|
if (separate)
|
||||||
{
|
{
|
||||||
|
@ -980,7 +980,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||||
if (this._overlap != 0)
|
if (this._overlap !== 0)
|
||||||
{
|
{
|
||||||
if (separate)
|
if (separate)
|
||||||
{
|
{
|
||||||
|
@ -1133,7 +1133,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||||
velocityFromAngle: function (angle, speed, point) {
|
velocityFromAngle: function (angle, speed, point) {
|
||||||
|
|
||||||
if (typeof speed === 'undefined') { speed = 60; }
|
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));
|
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) {
|
velocityFromRotation: function (rotation, speed, point) {
|
||||||
|
|
||||||
if (typeof speed === 'undefined') { speed = 60; }
|
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));
|
return point.setTo((Math.cos(rotation) * speed), (Math.sin(rotation) * speed));
|
||||||
|
|
||||||
|
@ -1171,7 +1171,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||||
accelerationFromRotation: function (rotation, speed, point) {
|
accelerationFromRotation: function (rotation, speed, point) {
|
||||||
|
|
||||||
if (typeof speed === 'undefined') { speed = 60; }
|
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));
|
return point.setTo((Math.cos(rotation) * speed), (Math.sin(rotation) * speed));
|
||||||
|
|
||||||
|
|
|
@ -18,91 +18,91 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
||||||
/**
|
/**
|
||||||
* @property {Phaser.Sprite} sprite - Reference to the parent Sprite.
|
* @property {Phaser.Sprite} sprite - Reference to the parent Sprite.
|
||||||
*/
|
*/
|
||||||
this.sprite = sprite;
|
this.sprite = sprite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Phaser.Game} game - Local reference to game.
|
* @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.
|
* @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.
|
* @property {number} x - The x position of the physics body.
|
||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
this.x = sprite.x;
|
this.x = sprite.x;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} y - The y position of the physics body.
|
* @property {number} y - The y position of the physics body.
|
||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
this.y = sprite.y;
|
this.y = sprite.y;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} preX - The previous x position of the physics body.
|
* @property {number} preX - The previous x position of the physics body.
|
||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
this.preX = sprite.x;
|
this.preX = sprite.x;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} preY - The previous y position of the physics body.
|
* @property {number} preY - The previous y position of the physics body.
|
||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
this.preY = sprite.y;
|
this.preY = sprite.y;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} preRotation - The previous rotation of the physics body.
|
* @property {number} preRotation - The previous rotation of the physics body.
|
||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
this.preRotation = sprite.angle;
|
this.preRotation = sprite.angle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} screenX - The x position of the physics body translated to screen space.
|
* @property {number} screenX - The x position of the physics body translated to screen space.
|
||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
this.screenX = sprite.x;
|
this.screenX = sprite.x;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} screenY - The y position of the physics body translated to screen space.
|
* @property {number} screenY - The y position of the physics body translated to screen space.
|
||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
this.screenY = sprite.y;
|
this.screenY = sprite.y;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} sourceWidth - The un-scaled original size.
|
* @property {number} sourceWidth - The un-scaled original size.
|
||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
this.sourceWidth = sprite.currentFrame.sourceSizeW;
|
this.sourceWidth = sprite.currentFrame.sourceSizeW;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} sourceHeight - The un-scaled original size.
|
* @property {number} sourceHeight - The un-scaled original size.
|
||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
this.sourceHeight = sprite.currentFrame.sourceSizeH;
|
this.sourceHeight = sprite.currentFrame.sourceSizeH;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} width - The calculated width of the physics body.
|
* @property {number} width - The calculated width of the physics body.
|
||||||
*/
|
*/
|
||||||
this.width = sprite.currentFrame.sourceSizeW;
|
this.width = sprite.currentFrame.sourceSizeW;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property .numInternal ID cache
|
* @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.
|
* @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.
|
* @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.
|
* @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.
|
* @property {number} _sx - Internal cache var.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._sx = sprite.scale.x;
|
this._sx = sprite.scale.x;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} _sy - Internal cache var.
|
* @property {number} _sy - Internal cache var.
|
||||||
* @private
|
* @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.
|
* @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.
|
* @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.
|
* @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.
|
* @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.
|
* @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.
|
* @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;
|
this.quadTreeIndex = -1;
|
||||||
|
|
||||||
// Allow collision
|
// Allow collision
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the allowCollision properties to control which directions collision is processed for this Body.
|
* 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
|
* @method Phaser.Physics.Arcade#updateBounds
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
updateBounds: function (centerX, centerY, scaleX, scaleY) {
|
updateBounds: function (centerX, centerY, scaleX, scaleY) {
|
||||||
|
|
||||||
if (scaleX != this._sx || scaleY != this._sy)
|
if (scaleX != this._sx || scaleY != this._sy)
|
||||||
{
|
{
|
||||||
this.width = this.sourceWidth * scaleX;
|
this.width = this.sourceWidth * scaleX;
|
||||||
this.height = this.sourceHeight * scaleY;
|
this.height = this.sourceHeight * scaleY;
|
||||||
this.halfWidth = Math.floor(this.width / 2);
|
this.halfWidth = Math.floor(this.width / 2);
|
||||||
this.halfHeight = Math.floor(this.height / 2);
|
this.halfHeight = Math.floor(this.height / 2);
|
||||||
this._sx = scaleX;
|
this._sx = scaleX;
|
||||||
this._sy = scaleY;
|
this._sy = scaleY;
|
||||||
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
|
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal method.
|
* Internal method.
|
||||||
|
@ -339,55 +339,55 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||||
* @method Phaser.Physics.Arcade#preUpdate
|
* @method Phaser.Physics.Arcade#preUpdate
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
preUpdate: function () {
|
preUpdate: function () {
|
||||||
|
|
||||||
// Store and reset collision flags
|
// Store and reset collision flags
|
||||||
this.wasTouching.none = this.touching.none;
|
this.wasTouching.none = this.touching.none;
|
||||||
this.wasTouching.up = this.touching.up;
|
this.wasTouching.up = this.touching.up;
|
||||||
this.wasTouching.down = this.touching.down;
|
this.wasTouching.down = this.touching.down;
|
||||||
this.wasTouching.left = this.touching.left;
|
this.wasTouching.left = this.touching.left;
|
||||||
this.wasTouching.right = this.touching.right;
|
this.wasTouching.right = this.touching.right;
|
||||||
|
|
||||||
this.touching.none = true;
|
this.touching.none = true;
|
||||||
this.touching.up = false;
|
this.touching.up = false;
|
||||||
this.touching.down = false;
|
this.touching.down = false;
|
||||||
this.touching.left = false;
|
this.touching.left = false;
|
||||||
this.touching.right = 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.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.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.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.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.x = this.preX;
|
||||||
this.y = this.preY;
|
this.y = this.preY;
|
||||||
this.rotation = this.preRotation;
|
this.rotation = this.preRotation;
|
||||||
|
|
||||||
if (this.moves)
|
if (this.moves)
|
||||||
{
|
{
|
||||||
this.game.physics.updateMotion(this);
|
this.game.physics.updateMotion(this);
|
||||||
|
|
||||||
if (this.collideWorldBounds)
|
if (this.collideWorldBounds)
|
||||||
{
|
{
|
||||||
this.checkWorldBounds();
|
this.checkWorldBounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateHulls();
|
this.updateHulls();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.skipQuadTree === false && this.allowCollision.none === false && this.sprite.visible && this.sprite.alive)
|
if (this.skipQuadTree === false && this.allowCollision.none === false && this.sprite.visible && this.sprite.alive)
|
||||||
{
|
{
|
||||||
this.quadTreeIDs = [];
|
this.quadTreeIDs = [];
|
||||||
this.quadTreeIndex = -1;
|
this.quadTreeIndex = -1;
|
||||||
this.game.physics.quadTree.insert(this);
|
this.game.physics.quadTree.insert(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal method.
|
* Internal method.
|
||||||
|
@ -395,25 +395,25 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||||
* @method Phaser.Physics.Arcade#postUpdate
|
* @method Phaser.Physics.Arcade#postUpdate
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
postUpdate: function () {
|
postUpdate: function () {
|
||||||
|
|
||||||
if (this.deltaX() < 0)
|
if (this.deltaX() < 0)
|
||||||
{
|
{
|
||||||
this.facing = Phaser.LEFT;
|
this.facing = Phaser.LEFT;
|
||||||
}
|
}
|
||||||
else if (this.deltaX() > 0)
|
else if (this.deltaX() > 0)
|
||||||
{
|
{
|
||||||
this.facing = Phaser.RIGHT;
|
this.facing = Phaser.RIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.deltaY() < 0)
|
if (this.deltaY() < 0)
|
||||||
{
|
{
|
||||||
this.facing = Phaser.UP;
|
this.facing = Phaser.UP;
|
||||||
}
|
}
|
||||||
else if (this.deltaY() > 0)
|
else if (this.deltaY() > 0)
|
||||||
{
|
{
|
||||||
this.facing = Phaser.DOWN;
|
this.facing = Phaser.DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.deltaX() !== 0 || this.deltaY() !== 0)
|
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);
|
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.allowRotation)
|
if (this.allowRotation)
|
||||||
{
|
{
|
||||||
this.sprite.angle += this.deltaZ();
|
this.sprite.angle += this.deltaZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal method.
|
* Internal method.
|
||||||
|
@ -435,12 +435,12 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||||
* @method Phaser.Physics.Arcade#updateHulls
|
* @method Phaser.Physics.Arcade#updateHulls
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
updateHulls: function () {
|
updateHulls: function () {
|
||||||
|
|
||||||
this.hullX.setTo(this.x, this.preY, 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);
|
this.hullY.setTo(this.preX, this.y, this.width, this.height);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal method.
|
* Internal method.
|
||||||
|
@ -448,31 +448,31 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||||
* @method Phaser.Physics.Arcade#checkWorldBounds
|
* @method Phaser.Physics.Arcade#checkWorldBounds
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
checkWorldBounds: function () {
|
checkWorldBounds: function () {
|
||||||
|
|
||||||
if (this.x < this.game.world.bounds.x)
|
if (this.x < this.game.world.bounds.x)
|
||||||
{
|
{
|
||||||
this.x = this.game.world.bounds.x;
|
this.x = this.game.world.bounds.x;
|
||||||
this.velocity.x *= -this.bounce.x;
|
this.velocity.x *= -this.bounce.x;
|
||||||
}
|
}
|
||||||
else if (this.right > this.game.world.bounds.right)
|
else if (this.right > this.game.world.bounds.right)
|
||||||
{
|
{
|
||||||
this.x = this.game.world.bounds.right - this.width;
|
this.x = this.game.world.bounds.right - this.width;
|
||||||
this.velocity.x *= -this.bounce.x;
|
this.velocity.x *= -this.bounce.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.y < this.game.world.bounds.y)
|
if (this.y < this.game.world.bounds.y)
|
||||||
{
|
{
|
||||||
this.y = this.game.world.bounds.y;
|
this.y = this.game.world.bounds.y;
|
||||||
this.velocity.y *= -this.bounce.y;
|
this.velocity.y *= -this.bounce.y;
|
||||||
}
|
}
|
||||||
else if (this.bottom > this.game.world.bounds.bottom)
|
else if (this.bottom > this.game.world.bounds.bottom)
|
||||||
{
|
{
|
||||||
this.y = this.game.world.bounds.bottom - this.height;
|
this.y = this.game.world.bounds.bottom - this.height;
|
||||||
this.velocity.y *= -this.bounce.y;
|
this.velocity.y *= -this.bounce.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* You can modify the size of the physics Body to be any dimension you need.
|
* 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} offsetX - The X offset of the Body from the Sprite position.
|
||||||
* @param {number} offsetY - The Y 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;
|
offsetX = offsetX || this.offset.x;
|
||||||
offsetY = offsetY || this.offset.y;
|
offsetY = offsetY || this.offset.y;
|
||||||
|
|
||||||
this.sourceWidth = width;
|
this.sourceWidth = width;
|
||||||
this.sourceHeight = height;
|
this.sourceHeight = height;
|
||||||
this.width = this.sourceWidth * this._sx;
|
this.width = this.sourceWidth * this._sx;
|
||||||
this.height = this.sourceHeight * this._sy;
|
this.height = this.sourceHeight * this._sy;
|
||||||
this.halfWidth = Math.floor(this.width / 2);
|
this.halfWidth = Math.floor(this.width / 2);
|
||||||
this.halfHeight = Math.floor(this.height / 2);
|
this.halfHeight = Math.floor(this.height / 2);
|
||||||
this.offset.setTo(offsetX, offsetY);
|
this.offset.setTo(offsetX, offsetY);
|
||||||
|
|
||||||
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
|
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets all Body values (velocity, acceleration, rotation, etc)
|
* Resets all Body values (velocity, acceleration, rotation, etc)
|
||||||
*
|
*
|
||||||
* @method Phaser.Physics.Arcade#reset
|
* @method Phaser.Physics.Arcade#reset
|
||||||
*/
|
*/
|
||||||
reset: function () {
|
reset: function () {
|
||||||
|
|
||||||
this.velocity.setTo(0, 0);
|
this.velocity.setTo(0, 0);
|
||||||
this.acceleration.setTo(0, 0);
|
this.acceleration.setTo(0, 0);
|
||||||
|
|
||||||
this.angularVelocity = 0;
|
this.angularVelocity = 0;
|
||||||
this.angularAcceleration = 0;
|
this.angularAcceleration = 0;
|
||||||
this.preX = (this.sprite.world.x - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
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.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.x = this.preX;
|
||||||
this.y = this.preY;
|
this.y = this.preY;
|
||||||
this.rotation = this.preRotation;
|
this.rotation = this.preRotation;
|
||||||
|
|
||||||
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
|
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the absolute delta x value.
|
* Returns the absolute delta x value.
|
||||||
|
|
|
@ -14,24 +14,24 @@
|
||||||
PIXI.Circle = function(x, y, radius)
|
PIXI.Circle = function(x, y, radius)
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @property x
|
* @property x
|
||||||
* @type Number
|
* @type Number
|
||||||
* @default 0
|
* @default 0
|
||||||
*/
|
*/
|
||||||
this.x = x || 0;
|
this.x = x || 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property y
|
* @property y
|
||||||
* @type Number
|
* @type Number
|
||||||
* @default 0
|
* @default 0
|
||||||
*/
|
*/
|
||||||
this.y = y || 0;
|
this.y = y || 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property radius
|
* @property radius
|
||||||
* @type Number
|
* @type Number
|
||||||
* @default 0
|
* @default 0
|
||||||
*/
|
*/
|
||||||
this.radius = radius || 0;
|
this.radius = radius || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,31 +15,31 @@
|
||||||
PIXI.Ellipse = function(x, y, width, height)
|
PIXI.Ellipse = function(x, y, width, height)
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @property x
|
* @property x
|
||||||
* @type Number
|
* @type Number
|
||||||
* @default 0
|
* @default 0
|
||||||
*/
|
*/
|
||||||
this.x = x || 0;
|
this.x = x || 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property y
|
* @property y
|
||||||
* @type Number
|
* @type Number
|
||||||
* @default 0
|
* @default 0
|
||||||
*/
|
*/
|
||||||
this.y = y || 0;
|
this.y = y || 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property width
|
* @property width
|
||||||
* @type Number
|
* @type Number
|
||||||
* @default 0
|
* @default 0
|
||||||
*/
|
*/
|
||||||
this.width = width || 0;
|
this.width = width || 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property height
|
* @property height
|
||||||
* @type Number
|
* @type Number
|
||||||
* @default 0
|
* @default 0
|
||||||
*/
|
*/
|
||||||
this.height = height || 0;
|
this.height = height || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,9 @@ PIXI.Sprite = function(texture)
|
||||||
* Setting than anchor to 0.5,0.5 means the textures origin is centered
|
* 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
|
* Setting the anchor to 1,1 would mean the textures origin points will be the bottom right
|
||||||
*
|
*
|
||||||
* @property anchor
|
* @property anchor
|
||||||
* @type Point
|
* @type Point
|
||||||
*/
|
*/
|
||||||
this.anchor = new PIXI.Point();
|
this.anchor = new PIXI.Point();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,26 +24,26 @@ PIXI.AssetLoader = function(assetURLs, crossorigin)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The array of asset URLs that are going to be loaded
|
* The array of asset URLs that are going to be loaded
|
||||||
*
|
*
|
||||||
* @property assetURLs
|
* @property assetURLs
|
||||||
* @type Array<String>
|
* @type Array<String>
|
||||||
*/
|
*/
|
||||||
this.assetURLs = assetURLs;
|
this.assetURLs = assetURLs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the requests should be treated as cross origin
|
* Whether the requests should be treated as cross origin
|
||||||
*
|
*
|
||||||
* @property crossorigin
|
* @property crossorigin
|
||||||
* @type Boolean
|
* @type Boolean
|
||||||
*/
|
*/
|
||||||
this.crossorigin = crossorigin;
|
this.crossorigin = crossorigin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps file extension to loader types
|
* Maps file extension to loader types
|
||||||
*
|
*
|
||||||
* @property loadersByType
|
* @property loadersByType
|
||||||
* @type Object
|
* @type Object
|
||||||
*/
|
*/
|
||||||
this.loadersByType = {
|
this.loadersByType = {
|
||||||
"jpg": PIXI.ImageLoader,
|
"jpg": PIXI.ImageLoader,
|
||||||
"jpeg": PIXI.ImageLoader,
|
"jpeg": PIXI.ImageLoader,
|
||||||
|
|
|
@ -17,43 +17,43 @@
|
||||||
PIXI.BitmapFontLoader = function(url, crossorigin)
|
PIXI.BitmapFontLoader = function(url, crossorigin)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* i use texture packer to load the assets..
|
* i use texture packer to load the assets..
|
||||||
* http://www.codeandweb.com/texturepacker
|
* http://www.codeandweb.com/texturepacker
|
||||||
* make sure to set the format as "JSON"
|
* make sure to set the format as "JSON"
|
||||||
*/
|
*/
|
||||||
PIXI.EventTarget.call(this);
|
PIXI.EventTarget.call(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The url of the bitmap font data
|
* The url of the bitmap font data
|
||||||
*
|
*
|
||||||
* @property url
|
* @property url
|
||||||
* @type String
|
* @type String
|
||||||
*/
|
*/
|
||||||
this.url = url;
|
this.url = url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the requests should be treated as cross origin
|
* Whether the requests should be treated as cross origin
|
||||||
*
|
*
|
||||||
* @property crossorigin
|
* @property crossorigin
|
||||||
* @type Boolean
|
* @type Boolean
|
||||||
*/
|
*/
|
||||||
this.crossorigin = crossorigin;
|
this.crossorigin = crossorigin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [read-only] The base url of the bitmap font data
|
* [read-only] The base url of the bitmap font data
|
||||||
*
|
*
|
||||||
* @property baseUrl
|
* @property baseUrl
|
||||||
* @type String
|
* @type String
|
||||||
* @readOnly
|
* @readOnly
|
||||||
*/
|
*/
|
||||||
this.baseUrl = url.replace(/[^\/]*$/, "");
|
this.baseUrl = url.replace(/[^\/]*$/, "");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [read-only] The texture of the bitmap font
|
* [read-only] The texture of the bitmap font
|
||||||
*
|
*
|
||||||
* @property baseUrl
|
* @property baseUrl
|
||||||
* @type String
|
* @type String
|
||||||
*/
|
*/
|
||||||
this.texture = null;
|
this.texture = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -18,18 +18,18 @@ PIXI.ImageLoader = function(url, crossorigin)
|
||||||
PIXI.EventTarget.call(this);
|
PIXI.EventTarget.call(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The texture being loaded
|
* The texture being loaded
|
||||||
*
|
*
|
||||||
* @property texture
|
* @property texture
|
||||||
* @type Texture
|
* @type Texture
|
||||||
*/
|
*/
|
||||||
this.texture = PIXI.Texture.fromImage(url, crossorigin);
|
this.texture = PIXI.Texture.fromImage(url, crossorigin);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* if the image is loaded with loadFramedSpriteSheet
|
* if the image is loaded with loadFramedSpriteSheet
|
||||||
* frames will contain the sprite sheet frames
|
* frames will contain the sprite sheet frames
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
this.frames = [];
|
this.frames = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -52,19 +52,19 @@ PIXI.SpriteSheetLoader = function (url, crossorigin) {
|
||||||
this.baseUrl = url.replace(/[^\/]*$/, "");
|
this.baseUrl = url.replace(/[^\/]*$/, "");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The texture being loaded
|
* The texture being loaded
|
||||||
*
|
*
|
||||||
* @property texture
|
* @property texture
|
||||||
* @type Texture
|
* @type Texture
|
||||||
*/
|
*/
|
||||||
this.texture = null;
|
this.texture = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The frames of the sprite sheet
|
* The frames of the sprite sheet
|
||||||
*
|
*
|
||||||
* @property frames
|
* @property frames
|
||||||
* @type Object
|
* @type Object
|
||||||
*/
|
*/
|
||||||
this.frames = {};
|
this.frames = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,45 +19,45 @@ PIXI.Graphics = function()
|
||||||
this.renderable = true;
|
this.renderable = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The alpha of the fill of this graphics object
|
* The alpha of the fill of this graphics object
|
||||||
*
|
*
|
||||||
* @property fillAlpha
|
* @property fillAlpha
|
||||||
* @type Number
|
* @type Number
|
||||||
*/
|
*/
|
||||||
this.fillAlpha = 1;
|
this.fillAlpha = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The width of any lines drawn
|
* The width of any lines drawn
|
||||||
*
|
*
|
||||||
* @property lineWidth
|
* @property lineWidth
|
||||||
* @type Number
|
* @type Number
|
||||||
*/
|
*/
|
||||||
this.lineWidth = 0;
|
this.lineWidth = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The color of any lines drawn
|
* The color of any lines drawn
|
||||||
*
|
*
|
||||||
* @property lineColor
|
* @property lineColor
|
||||||
* @type String
|
* @type String
|
||||||
*/
|
*/
|
||||||
this.lineColor = "black";
|
this.lineColor = "black";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Graphics data
|
* Graphics data
|
||||||
*
|
*
|
||||||
* @property graphicsData
|
* @property graphicsData
|
||||||
* @type Array
|
* @type Array
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.graphicsData = [];
|
this.graphicsData = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current path
|
* Current path
|
||||||
*
|
*
|
||||||
* @property currentPath
|
* @property currentPath
|
||||||
* @type Object
|
* @type Object
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.currentPath = {points:[]};
|
this.currentPath = {points:[]};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
Phaser.Sound = function (game, key, volume, loop) {
|
Phaser.Sound = function (game, key, volume, loop) {
|
||||||
|
|
||||||
if (typeof volume == 'undefined') { volume = 1; }
|
if (typeof volume == 'undefined') { volume = 1; }
|
||||||
if (typeof loop == 'undefined') { loop = false; }
|
if (typeof loop == 'undefined') { loop = false; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A reference to the currently running Game.
|
* A reference to the currently running Game.
|
||||||
|
@ -27,157 +27,128 @@ Phaser.Sound = function (game, key, volume, loop) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of the sound.
|
* @property {string} name - Name of the sound.
|
||||||
* @property {string} name
|
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this.name = key;
|
this.name = key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asset key for the sound.
|
* @property {string} key - Asset key for the sound.
|
||||||
* @property {string} key
|
|
||||||
*/
|
*/
|
||||||
this.key = key;
|
this.key = key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the sound will loop.
|
* @property {boolean} loop - Whether or not the sound will loop.
|
||||||
* @property {boolean} loop
|
|
||||||
*/
|
*/
|
||||||
this.loop = loop;
|
this.loop = loop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global audio volume. A value between 0 (silence) and 1 (full volume).
|
* @property {number} _volume - The global audio volume. A value between 0 (silence) and 1 (full volume).
|
||||||
* @property {number} _volume
|
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._volume = volume;
|
this._volume = volume;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The sound markers, empty by default.
|
* @property {object} markers - The sound markers.
|
||||||
* @property {object} markers
|
|
||||||
*/
|
*/
|
||||||
this.markers = {};
|
this.markers = {};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reference to AudioContext instance.
|
* @property {AudioContext} context - Reference to the AudioContext instance.
|
||||||
* @property {AudioContext} context
|
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this.context = null;
|
this.context = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decoded data buffer / Audio tag.
|
* @property {Description} _buffer - Decoded data buffer / Audio tag.
|
||||||
* @property {Description} _buffer
|
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._buffer = null;
|
this._buffer = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Boolean indicating whether the game is on "mute".
|
* @property {boolean} _muted - Boolean indicating whether the sound is muted or not.
|
||||||
* @property {boolean} _muted
|
|
||||||
* @private
|
* @private
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this._muted = false;
|
this._muted = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Boolean indicating whether the sound should start automatically.
|
* @property {boolean} autoplay - Boolean indicating whether the sound should start automatically.
|
||||||
* @property {boolean} autoplay
|
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
this.autoplay = false;
|
this.autoplay = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The total duration of the sound, in milliseconds
|
* @property {number} totalDuration - The total duration of the sound, in milliseconds
|
||||||
* @property {number} totalDuration
|
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this.totalDuration = 0;
|
this.totalDuration = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* @property {number} startTime - The time the Sound starts at (typically 0 unless starting from a marker)
|
||||||
* @property {number} startTime
|
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.startTime = 0;
|
this.startTime = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* @property {number} currentTime - The current time the sound is at.
|
||||||
* @property {number} currentTime
|
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this.currentTime = 0;
|
this.currentTime = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* @property {number} duration - The duration of the sound.
|
||||||
* @property {number} duration
|
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this.duration = 0;
|
this.duration = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* @property {number} stopTime - The time the sound stopped.
|
||||||
* @property {number} stopTime
|
|
||||||
*/
|
*/
|
||||||
this.stopTime = 0;
|
this.stopTime = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* @property {boolean} paused - true if the sound is paused, otherwise false.
|
||||||
* @property {boolean} paused
|
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.paused = false;
|
this.paused = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* @property {number} pausedPosition - The position the sound had reached when it was paused.
|
||||||
* @property {number} pausedPosition
|
|
||||||
*/
|
*/
|
||||||
this.pausedPosition = 0;
|
this.pausedPosition = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* @property {number} pausedTime - The game time at which the sound was paused.
|
||||||
* @property {number} pausedTime
|
|
||||||
*/
|
*/
|
||||||
this.pausedTime = 0;
|
this.pausedTime = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* @property {boolean} isPlaying - true if the sound is currently playing, otherwise false.
|
||||||
* @property {boolean} isPlaying
|
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.isPlaying = false;
|
this.isPlaying = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* @property {string} currentMarker - The string ID of the currently playing marker, if any.
|
||||||
* @property {string} currentMarker
|
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.currentMarker = '';
|
this.currentMarker = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* @property {boolean} pendingPlayback - true if the sound file is pending playback
|
||||||
* @property {boolean} pendingPlayback
|
* @readonly
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this.pendingPlayback = false;
|
this.pendingPlayback = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* @property {boolean} override - if true when you play this sound it will always start from the beginning.
|
||||||
* @property {boolean} override
|
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.override = false;
|
this.override = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* @property {boolean} usingWebAudio - true if this sound is being played with Web Audio.
|
||||||
* @property {boolean} usingWebAudio
|
* @readonly
|
||||||
*/
|
*/
|
||||||
this.usingWebAudio = this.game.sound.usingWebAudio;
|
this.usingWebAudio = this.game.sound.usingWebAudio;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* @property {boolean} usingAudioTag - true if the sound is being played via the Audio tag.
|
||||||
* @property {Description} usingAudioTag
|
|
||||||
*/
|
*/
|
||||||
this.usingAudioTag = this.game.sound.usingAudioTag;
|
this.usingAudioTag = this.game.sound.usingAudioTag;
|
||||||
|
|
||||||
|
@ -217,63 +188,55 @@ Phaser.Sound = function (game, key, volume, loop) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* @property {Phaser.Signal} onDecoded - The onDecoded event is dispatched when the sound has finished decoding (typically for mp3 files)
|
||||||
* @property {Phaser.Signal} onDecoded
|
|
||||||
*/
|
*/
|
||||||
this.onDecoded = new Phaser.Signal;
|
this.onDecoded = new Phaser.Signal();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* @property {Phaser.Signal} onPlay - The onPlay event is dispatched each time this sound is played.
|
||||||
* @property {Phaser.Signal} onPlay
|
|
||||||
*/
|
*/
|
||||||
this.onPlay = new Phaser.Signal;
|
this.onPlay = new Phaser.Signal();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* @property {Phaser.Signal} onPause - The onPause event is dispatched when this sound is paused.
|
||||||
* @property {Phaser.Signal} onPause
|
|
||||||
*/
|
*/
|
||||||
this.onPause = new Phaser.Signal;
|
this.onPause = new Phaser.Signal();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* @property {Phaser.Signal} onResume - The onResume event is dispatched when this sound is resumed from a paused state.
|
||||||
* @property {Phaser.Signal} onResume
|
|
||||||
*/
|
*/
|
||||||
this.onResume = new Phaser.Signal;
|
this.onResume = new Phaser.Signal();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* @property {Phaser.Signal} onLoop - The onLoop event is dispatched when this sound loops during playback.
|
||||||
* @property {Phaser.Signal} onLoop
|
|
||||||
*/
|
*/
|
||||||
this.onLoop = new Phaser.Signal;
|
this.onLoop = new Phaser.Signal();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* @property {Phaser.Signal} onStop - The onStop event is dispatched when this sound stops playback.
|
||||||
* @property {Phaser.Signal} onStop
|
|
||||||
*/
|
*/
|
||||||
this.onStop = new Phaser.Signal;
|
this.onStop = new Phaser.Signal();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* @property {Phaser.Signal} onMute - The onMouse event is dispatched when this sound is muted.
|
||||||
* @property {Phaser.Signal} onMute
|
|
||||||
*/
|
*/
|
||||||
this.onMute = new Phaser.Signal;
|
this.onMute = new Phaser.Signal();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* @property {Phaser.Signal} onMarkerComplete - The onMarkerComplete event is dispatched when a marker within this sound completes playback.
|
||||||
* @property {Phaser.Signal} onMarkerComplete
|
|
||||||
*/
|
*/
|
||||||
this.onMarkerComplete = new Phaser.Signal;
|
this.onMarkerComplete = new Phaser.Signal();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Phaser.Sound.prototype = {
|
Phaser.Sound.prototype = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called automatically when this sound is unlocked.
|
* Called automatically when this sound is unlocked.
|
||||||
* @method Phaser.Sound#soundHasUnlocked
|
* @method Phaser.Sound#soundHasUnlocked
|
||||||
* @param {string} key - Description.
|
* @param {string} key - The Phaser.Cache key of the sound file to check for decoding.
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
soundHasUnlocked: function (key) {
|
soundHasUnlocked: function (key) {
|
||||||
|
|
||||||
if (key == this.key)
|
if (key == this.key)
|
||||||
|
@ -281,22 +244,22 @@ Phaser.Sound.prototype = {
|
||||||
this._sound = this.game.cache.getSoundData(this.key);
|
this._sound = this.game.cache.getSoundData(this.key);
|
||||||
this.totalDuration = this._sound.duration;
|
this.totalDuration = this._sound.duration;
|
||||||
// console.log('sound has unlocked' + this._sound);
|
// console.log('sound has unlocked' + this._sound);
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description.
|
* Description.
|
||||||
* @method Phaser.Sound#addMarker
|
* @method Phaser.Sound#addMarker
|
||||||
* @param {string} name - Description.
|
* @param {string} name - Description.
|
||||||
* @param {Description} start - Description.
|
* @param {Description} start - Description.
|
||||||
* @param {Description} stop - Description.
|
* @param {Description} stop - Description.
|
||||||
* @param {Description} volume - Description.
|
* @param {Description} volume - Description.
|
||||||
* @param {Description} loop - Description.
|
* @param {Description} loop - Description.
|
||||||
addMarker: function (name, start, stop, volume, loop) {
|
addMarker: function (name, start, stop, volume, loop) {
|
||||||
|
|
||||||
volume = volume || 1;
|
volume = volume || 1;
|
||||||
if (typeof loop == 'undefined') { loop = false; }
|
if (typeof loop == 'undefined') { loop = false; }
|
||||||
|
|
||||||
this.markers[name] = {
|
this.markers[name] = {
|
||||||
name: name,
|
name: name,
|
||||||
|
@ -338,22 +301,22 @@ Phaser.Sound.prototype = {
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a marker from the sound.
|
* Removes a marker from the sound.
|
||||||
* @method Phaser.Sound#removeMarker
|
* @method Phaser.Sound#removeMarker
|
||||||
* @param {string} name - The key of the marker to remove.
|
* @param {string} name - The key of the marker to remove.
|
||||||
*/
|
*/
|
||||||
removeMarker: function (name) {
|
removeMarker: function (name) {
|
||||||
|
|
||||||
delete this.markers[name];
|
delete this.markers[name];
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called automatically by Phaser.SoundManager.
|
* Called automatically by Phaser.SoundManager.
|
||||||
* @method Phaser.Sound#update
|
* @method Phaser.Sound#update
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
update: function () {
|
update: function () {
|
||||||
|
|
||||||
if (this.pendingPlayback && this.game.cache.isSoundReady(this.key))
|
if (this.pendingPlayback && this.game.cache.isSoundReady(this.key))
|
||||||
|
@ -377,7 +340,7 @@ Phaser.Sound.prototype = {
|
||||||
// won't work with markers, needs to reset the position
|
// won't work with markers, needs to reset the position
|
||||||
this.onLoop.dispatch(this);
|
this.onLoop.dispatch(this);
|
||||||
|
|
||||||
if (this.currentMarker == '')
|
if (this.currentMarker === '')
|
||||||
{
|
{
|
||||||
//console.log('loop2');
|
//console.log('loop2');
|
||||||
this.currentTime = 0;
|
this.currentTime = 0;
|
||||||
|
@ -411,7 +374,7 @@ Phaser.Sound.prototype = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Play this sound, or a marked section of it.
|
* Play this sound, or a marked section of it.
|
||||||
* @method Phaser.Sound#play
|
* @method Phaser.Sound#play
|
||||||
* @param {string} [marker=''] - If you want to play a marker then give the key here, otherwise leave blank to play the full sound.
|
* @param {string} [marker=''] - If you want to play a marker then give the key here, otherwise leave blank to play the full sound.
|
||||||
|
@ -423,12 +386,12 @@ Phaser.Sound.prototype = {
|
||||||
*/
|
*/
|
||||||
play: function (marker, position, volume, loop, forceRestart) {
|
play: function (marker, position, volume, loop, forceRestart) {
|
||||||
|
|
||||||
marker = marker || '';
|
marker = marker || '';
|
||||||
position = position || 0;
|
position = position || 0;
|
||||||
|
|
||||||
if (typeof volume === 'undefined') { volume = this._volume; }
|
if (typeof volume === 'undefined') { volume = this._volume; }
|
||||||
if (typeof loop === 'undefined') { loop = false; }
|
if (typeof loop === 'undefined') { loop = false; }
|
||||||
if (typeof forceRestart === 'undefined') { forceRestart = true; }
|
if (typeof forceRestart === 'undefined') { forceRestart = true; }
|
||||||
|
|
||||||
// console.log(this.name + ' play ' + marker + ' position ' + position + ' volume ' + volume + ' loop ' + loop, 'force', forceRestart);
|
// console.log(this.name + ' play ' + marker + ' position ' + position + ' volume ' + volume + ' loop ' + loop, 'force', forceRestart);
|
||||||
|
|
||||||
|
@ -524,7 +487,7 @@ Phaser.Sound.prototype = {
|
||||||
this.durationMS = this.totalDuration * 1000;
|
this.durationMS = this.totalDuration * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.loop && marker == '')
|
if (this.loop && marker === '')
|
||||||
{
|
{
|
||||||
this._sound.loop = true;
|
this._sound.loop = true;
|
||||||
}
|
}
|
||||||
|
@ -535,9 +498,9 @@ Phaser.Sound.prototype = {
|
||||||
this._sound.noteGrainOn(0, this.position, this.duration);
|
this._sound.noteGrainOn(0, this.position, this.duration);
|
||||||
// this._sound.noteGrainOn(0, this.position, this.duration / 1000);
|
// this._sound.noteGrainOn(0, this.position, this.duration / 1000);
|
||||||
//this._sound.noteOn(0); // the zero is vitally important, crashes iOS6 without it
|
//this._sound.noteOn(0); // the zero is vitally important, crashes iOS6 without it
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// this._sound.start(0, this.position, this.duration / 1000);
|
// this._sound.start(0, this.position, this.duration / 1000);
|
||||||
this._sound.start(0, this.position, this.duration);
|
this._sound.start(0, this.position, this.duration);
|
||||||
}
|
}
|
||||||
|
@ -547,9 +510,9 @@ Phaser.Sound.prototype = {
|
||||||
this.currentTime = 0;
|
this.currentTime = 0;
|
||||||
this.stopTime = this.startTime + this.durationMS;
|
this.stopTime = this.startTime + this.durationMS;
|
||||||
this.onPlay.dispatch(this);
|
this.onPlay.dispatch(this);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.pendingPlayback = true;
|
this.pendingPlayback = true;
|
||||||
|
|
||||||
if (this.game.cache.getSound(this.key) && this.game.cache.getSound(this.key).isDecoding === false)
|
if (this.game.cache.getSound(this.key) && this.game.cache.getSound(this.key).isDecoding === false)
|
||||||
|
@ -619,10 +582,10 @@ Phaser.Sound.prototype = {
|
||||||
*/
|
*/
|
||||||
restart: function (marker, position, volume, loop) {
|
restart: function (marker, position, volume, loop) {
|
||||||
|
|
||||||
marker = marker || '';
|
marker = marker || '';
|
||||||
position = position || 0;
|
position = position || 0;
|
||||||
volume = volume || 1;
|
volume = volume || 1;
|
||||||
if (typeof loop == 'undefined') { loop = false; }
|
if (typeof loop == 'undefined') { loop = false; }
|
||||||
|
|
||||||
this.play(marker, position, volume, loop, true);
|
this.play(marker, position, volume, loop, true);
|
||||||
|
|
||||||
|
@ -666,9 +629,9 @@ Phaser.Sound.prototype = {
|
||||||
{
|
{
|
||||||
this._sound.noteGrainOn(0, p, this.duration);
|
this._sound.noteGrainOn(0, p, this.duration);
|
||||||
//this._sound.noteOn(0); // the zero is vitally important, crashes iOS6 without it
|
//this._sound.noteOn(0); // the zero is vitally important, crashes iOS6 without it
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this._sound.start(0, p, this.duration);
|
this._sound.start(0, p, this.duration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -685,7 +648,7 @@ Phaser.Sound.prototype = {
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop playing this sound.
|
* Stop playing this sound.
|
||||||
* @method Phaser.Sound#stop
|
* @method Phaser.Sound#stop
|
||||||
*/
|
*/
|
||||||
|
@ -759,7 +722,7 @@ Object.defineProperty(Phaser.Sound.prototype, "mute", {
|
||||||
|
|
||||||
set: function (value) {
|
set: function (value) {
|
||||||
|
|
||||||
value = value || null;
|
value = value || null;
|
||||||
|
|
||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,28 +16,28 @@
|
||||||
*/
|
*/
|
||||||
Phaser.SoundManager = function (game) {
|
Phaser.SoundManager = function (game) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Phaser.Game} game - Local reference to game.
|
* @property {Phaser.Game} game - Local reference to game.
|
||||||
*/
|
*/
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Phaser.Signal} onSoundDecode - Description.
|
* @property {Phaser.Signal} onSoundDecode - The event dispatched when a sound decodes (typically only for mp3 files)
|
||||||
*/
|
*/
|
||||||
this.onSoundDecode = new Phaser.Signal;
|
this.onSoundDecode = new Phaser.Signal();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {boolean} _muted - Description.
|
* @property {boolean} _muted - Internal mute tracking var.
|
||||||
* @private
|
* @private
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this._muted = false;
|
this._muted = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Description} _unlockSource - Description.
|
* @property {Description} _unlockSource - Internal unlock tracking var.
|
||||||
* @private
|
* @private
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this._unlockSource = null;
|
this._unlockSource = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,39 +55,39 @@ Phaser.SoundManager = function (game) {
|
||||||
this._sounds = [];
|
this._sounds = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Description} context - Description.
|
* @property {AudioContext} context - The AudioContext being used for playback.
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.context = null;
|
this.context = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {boolean} usingWebAudio - Description.
|
* @property {boolean} usingWebAudio - true if this sound is being played with Web Audio.
|
||||||
* @default
|
* @readonly
|
||||||
*/
|
*/
|
||||||
this.usingWebAudio = true;
|
this.usingWebAudio = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {boolean} usingAudioTag - Description.
|
* @property {boolean} usingAudioTag - true if the sound is being played via the Audio tag.
|
||||||
* @default
|
* @readonly
|
||||||
*/
|
*/
|
||||||
this.usingAudioTag = false;
|
this.usingAudioTag = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {boolean} noAudio - Description.
|
* @property {boolean} noAudio - Has audio been disabled via the PhaserGlobal object? Useful if you need to use a 3rd party audio library instead.
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.noAudio = false;
|
this.noAudio = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {boolean} touchLocked - Description.
|
* @property {boolean} touchLocked - true if the audio system is currently locked awaiting a touch event.
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.touchLocked = false;
|
this.touchLocked = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} channels - Description.
|
* @property {number} channels - The number of audio channels to use in playback.
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.channels = 32;
|
this.channels = 32;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -257,9 +257,9 @@ Phaser.SoundManager.prototype = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decode a sound by its assets key.
|
* Decode a sound by its assets key.
|
||||||
* @method Phaser.SoundManager#decode
|
* @method Phaser.SoundManager#decode
|
||||||
* @param {string} key - Assets key of the sound to be decoded.
|
* @param {string} key - Assets key of the sound to be decoded.
|
||||||
|
@ -329,7 +329,7 @@ Phaser.SoundManager.prototype = {
|
||||||
add: function (key, volume, loop) {
|
add: function (key, volume, loop) {
|
||||||
|
|
||||||
if (typeof volume === 'undefined') { volume = 1; }
|
if (typeof volume === 'undefined') { volume = 1; }
|
||||||
if (typeof loop === 'undefined') { loop = false; }
|
if (typeof loop === 'undefined') { loop = false; }
|
||||||
|
|
||||||
var sound = new Phaser.Sound(this.game, key, volume, loop);
|
var sound = new Phaser.Sound(this.game, key, volume, loop);
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ Phaser.Canvas = {
|
||||||
*/
|
*/
|
||||||
getOffset: function (element, point) {
|
getOffset: function (element, point) {
|
||||||
|
|
||||||
point = point || new Phaser.Point;
|
point = point || new Phaser.Point();
|
||||||
|
|
||||||
var box = element.getBoundingClientRect();
|
var box = element.getBoundingClientRect();
|
||||||
var clientTop = element.clientTop || document.body.clientTop || 0;
|
var clientTop = element.clientTop || document.body.clientTop || 0;
|
||||||
|
|
|
@ -387,7 +387,7 @@ Phaser.Device.prototype = {
|
||||||
this.mobileSafari = true;
|
this.mobileSafari = true;
|
||||||
} else if (/MSIE (\d+\.\d+);/.test(ua)) {
|
} else if (/MSIE (\d+\.\d+);/.test(ua)) {
|
||||||
this.ie = true;
|
this.ie = true;
|
||||||
this.ieVersion = parseInt(RegExp.$1);
|
this.ieVersion = parseInt(RegExp.$1, 10);
|
||||||
} else if (/Midori/.test(ua)) {
|
} else if (/Midori/.test(ua)) {
|
||||||
this.midori = true;
|
this.midori = true;
|
||||||
} else if (/Opera/.test(ua)) {
|
} else if (/Opera/.test(ua)) {
|
||||||
|
|
|
@ -13,145 +13,145 @@
|
||||||
*/
|
*/
|
||||||
Phaser.RequestAnimationFrame = function(game) {
|
Phaser.RequestAnimationFrame = function(game) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Phaser.Game} game - The currently running game.
|
* @property {Phaser.Game} game - The currently running game.
|
||||||
*/
|
*/
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {boolean} isRunning - true if RequestAnimationFrame is running, otherwise false.
|
* @property {boolean} isRunning - true if RequestAnimationFrame is running, otherwise false.
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.isRunning = false;
|
this.isRunning = false;
|
||||||
|
|
||||||
var vendors = [
|
var vendors = [
|
||||||
'ms',
|
'ms',
|
||||||
'moz',
|
'moz',
|
||||||
'webkit',
|
'webkit',
|
||||||
'o'
|
'o'
|
||||||
];
|
];
|
||||||
|
|
||||||
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; x++)
|
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; x++)
|
||||||
{
|
{
|
||||||
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
|
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
|
||||||
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'];
|
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {boolean} _isSetTimeOut - true if the browser is using setTimeout instead of raf.
|
* @property {boolean} _isSetTimeOut - true if the browser is using setTimeout instead of raf.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._isSetTimeOut = false;
|
this._isSetTimeOut = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {function} _onLoop - The function called by the update.
|
* @property {function} _onLoop - The function called by the update.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._onLoop = null;
|
this._onLoop = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} _timeOutID - The callback ID used when calling cancel.
|
* @property {number} _timeOutID - The callback ID used when calling cancel.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._timeOutID = null;
|
this._timeOutID = null;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Phaser.RequestAnimationFrame.prototype = {
|
Phaser.RequestAnimationFrame.prototype = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the requestAnimatioFrame running or setTimeout if unavailable in browser
|
* Starts the requestAnimatioFrame running or setTimeout if unavailable in browser
|
||||||
* @method Phaser.RequestAnimationFrame#start
|
* @method Phaser.RequestAnimationFrame#start
|
||||||
*/
|
*/
|
||||||
start: function () {
|
start: function () {
|
||||||
|
|
||||||
this.isRunning = true;
|
this.isRunning = true;
|
||||||
|
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
if (!window.requestAnimationFrame)
|
if (!window.requestAnimationFrame)
|
||||||
{
|
{
|
||||||
this._isSetTimeOut = true;
|
this._isSetTimeOut = true;
|
||||||
|
|
||||||
this._onLoop = function () {
|
this._onLoop = function () {
|
||||||
return _this.updateSetTimeout();
|
return _this.updateSetTimeout();
|
||||||
};
|
};
|
||||||
|
|
||||||
this._timeOutID = window.setTimeout(this._onLoop, 0);
|
this._timeOutID = window.setTimeout(this._onLoop, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this._isSetTimeOut = false;
|
this._isSetTimeOut = false;
|
||||||
|
|
||||||
this._onLoop = function (time) {
|
this._onLoop = function (time) {
|
||||||
return _this.updateRAF(time);
|
return _this.updateRAF(time);
|
||||||
};
|
};
|
||||||
|
|
||||||
this._timeOutID = window.requestAnimationFrame(this._onLoop);
|
this._timeOutID = window.requestAnimationFrame(this._onLoop);
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The update method for the requestAnimationFrame
|
* The update method for the requestAnimationFrame
|
||||||
* @method Phaser.RequestAnimationFrame#updateRAF
|
* @method Phaser.RequestAnimationFrame#updateRAF
|
||||||
* @param {number} time - A timestamp, either from RAF or setTimeOut
|
* @param {number} time - A timestamp, either from RAF or setTimeOut
|
||||||
*/
|
*/
|
||||||
updateRAF: function (time) {
|
updateRAF: function (time) {
|
||||||
|
|
||||||
this.game.update(time);
|
this.game.update(time);
|
||||||
|
|
||||||
this._timeOutID = window.requestAnimationFrame(this._onLoop);
|
this._timeOutID = window.requestAnimationFrame(this._onLoop);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The update method for the setTimeout.
|
* The update method for the setTimeout.
|
||||||
* @method Phaser.RequestAnimationFrame#updateSetTimeout
|
* @method Phaser.RequestAnimationFrame#updateSetTimeout
|
||||||
*/
|
*/
|
||||||
updateSetTimeout: function () {
|
updateSetTimeout: function () {
|
||||||
|
|
||||||
this.game.update(Date.now());
|
this.game.update(Date.now());
|
||||||
|
|
||||||
this._timeOutID = window.setTimeout(this._onLoop, this.game.time.timeToCall);
|
this._timeOutID = window.setTimeout(this._onLoop, this.game.time.timeToCall);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops the requestAnimationFrame from running.
|
* Stops the requestAnimationFrame from running.
|
||||||
* @method Phaser.RequestAnimationFrame#stop
|
* @method Phaser.RequestAnimationFrame#stop
|
||||||
*/
|
*/
|
||||||
stop: function () {
|
stop: function () {
|
||||||
|
|
||||||
if (this._isSetTimeOut)
|
if (this._isSetTimeOut)
|
||||||
{
|
{
|
||||||
clearTimeout(this._timeOutID);
|
clearTimeout(this._timeOutID);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
window.cancelAnimationFrame(this._timeOutID);
|
window.cancelAnimationFrame(this._timeOutID);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isRunning = false;
|
this.isRunning = false;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the browser using setTimeout?
|
* Is the browser using setTimeout?
|
||||||
* @method Phaser.RequestAnimationFrame#isSetTimeOut
|
* @method Phaser.RequestAnimationFrame#isSetTimeOut
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
isSetTimeOut: function () {
|
isSetTimeOut: function () {
|
||||||
return this._isSetTimeOut;
|
return this._isSetTimeOut;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the browser using requestAnimationFrame?
|
* Is the browser using requestAnimationFrame?
|
||||||
* @method Phaser.RequestAnimationFrame#isRAF
|
* @method Phaser.RequestAnimationFrame#isRAF
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
isRAF: function () {
|
isRAF: function () {
|
||||||
return (this._isSetTimeOut === false);
|
return (this._isSetTimeOut === false);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
|
@ -73,7 +73,7 @@ Phaser.StageScaleMode = function (game, width, height) {
|
||||||
* @property {boolean} forcePortrait - If the game should be forced to use Portrait mode, this is set to true by Game.Stage
|
* @property {boolean} forcePortrait - If the game should be forced to use Portrait mode, this is set to true by Game.Stage
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.forcePortrait = false;
|
this.forcePortrait = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {boolean} incorrectOrientation - If the game should be forced to use a specific orientation and the device currently isn't in that orientation this is set to true.
|
* @property {boolean} incorrectOrientation - If the game should be forced to use a specific orientation and the device currently isn't in that orientation this is set to true.
|
||||||
|
@ -188,6 +188,11 @@ Phaser.StageScaleMode = function (game, width, height) {
|
||||||
*/
|
*/
|
||||||
this.aspectRatio = 0;
|
this.aspectRatio = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {any} event- The native browser events from full screen API changes.
|
||||||
|
*/
|
||||||
|
this.event = null;
|
||||||
|
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
window.addEventListener('orientationchange', function (event) {
|
window.addEventListener('orientationchange', function (event) {
|
||||||
|
@ -301,6 +306,8 @@ Phaser.StageScaleMode.prototype = {
|
||||||
*/
|
*/
|
||||||
fullScreenChange: function (event) {
|
fullScreenChange: function (event) {
|
||||||
|
|
||||||
|
this.event = event;
|
||||||
|
|
||||||
if (this.isFullScreen)
|
if (this.isFullScreen)
|
||||||
{
|
{
|
||||||
this.game.stage.canvas.style['width'] = '100%';
|
this.game.stage.canvas.style['width'] = '100%';
|
||||||
|
@ -429,6 +436,8 @@ Phaser.StageScaleMode.prototype = {
|
||||||
*/
|
*/
|
||||||
checkOrientation: function (event) {
|
checkOrientation: function (event) {
|
||||||
|
|
||||||
|
this.event = event;
|
||||||
|
|
||||||
this.orientation = window['orientation'];
|
this.orientation = window['orientation'];
|
||||||
|
|
||||||
if (this.isLandscape)
|
if (this.isLandscape)
|
||||||
|
@ -454,6 +463,8 @@ Phaser.StageScaleMode.prototype = {
|
||||||
*/
|
*/
|
||||||
checkResize: function (event) {
|
checkResize: function (event) {
|
||||||
|
|
||||||
|
this.event = event;
|
||||||
|
|
||||||
if (window.outerWidth > window.outerHeight)
|
if (window.outerWidth > window.outerHeight)
|
||||||
{
|
{
|
||||||
this.orientation = 90;
|
this.orientation = 90;
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
* @module Phaser.Tile
|
* @module Phaser.Tile
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new <code>Tile</code>.
|
* Create a new <code>Tile</code>.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
Phaser.Tilemap = function (game, key) {
|
Phaser.Tilemap = function (game, key) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Phaser.Game} game - Description.
|
* @property {Phaser.Game} game - Description.
|
||||||
*/
|
*/
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {array} layers - Description.
|
* @property {array} layers - Description.
|
||||||
*/
|
*/
|
||||||
this.layers;
|
this.layers = null;
|
||||||
|
|
||||||
if (typeof key === 'string')
|
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();
|
this.calculateIndexes();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.layers = [];
|
this.layers = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currentLayer = 0;
|
this.currentLayer = 0;
|
||||||
|
@ -55,15 +55,15 @@ Phaser.Tilemap.prototype = {
|
||||||
|
|
||||||
this.currentLayer = this.layers.push({
|
this.currentLayer = this.layers.push({
|
||||||
|
|
||||||
name: name,
|
name: name,
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
alpha: 1,
|
alpha: 1,
|
||||||
visible: true,
|
visible: true,
|
||||||
tileMargin: 0,
|
tileMargin: 0,
|
||||||
tileSpacing: 0,
|
tileSpacing: 0,
|
||||||
format: Phaser.Tilemap.CSV,
|
format: Phaser.Tilemap.CSV,
|
||||||
data: data,
|
data: data,
|
||||||
indexes: []
|
indexes: []
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -96,10 +96,10 @@ Phaser.Tilemap.prototype = {
|
||||||
|
|
||||||
setLayer: function (layer) {
|
setLayer: function (layer) {
|
||||||
|
|
||||||
if (this.layers[layer])
|
if (this.layers[layer])
|
||||||
{
|
{
|
||||||
this.currentLayer = layer;
|
this.currentLayer = layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -114,10 +114,10 @@ Phaser.Tilemap.prototype = {
|
||||||
|
|
||||||
if (typeof layer === "undefined") { layer = this.currentLayer; }
|
if (typeof layer === "undefined") { layer = this.currentLayer; }
|
||||||
|
|
||||||
if (x >= 0 && x < this.layers[layer].width && y >= 0 && y < this.layers[layer].height)
|
if (x >= 0 && x < this.layers[layer].width && y >= 0 && y < this.layers[layer].height)
|
||||||
{
|
{
|
||||||
this.layers[layer].data[y][x] = index;
|
this.layers[layer].data[y][x] = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.dirty = true;
|
this.dirty = true;
|
||||||
|
|
||||||
|
@ -273,7 +273,7 @@ Phaser.Tilemap.prototype = {
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
swapHandler: function (value, index, array) {
|
swapHandler: function (value, index) {
|
||||||
|
|
||||||
if (value.index === this._tempA)
|
if (value.index === this._tempA)
|
||||||
{
|
{
|
||||||
|
@ -462,14 +462,14 @@ Phaser.Tilemap.prototype = {
|
||||||
|
|
||||||
if (this.layers[this.currentLayer].data[y][x] > 1)
|
if (this.layers[this.currentLayer].data[y][x] > 1)
|
||||||
{
|
{
|
||||||
if (this.debugMap[this.layers[this.currentLayer].data[y][x]])
|
if (this.debugMap[this.layers[this.currentLayer].data[y][x]])
|
||||||
{
|
{
|
||||||
args.push("background: " + this.debugMap[this.layers[this.currentLayer].data[y][x]]);
|
args.push("background: " + this.debugMap[this.layers[this.currentLayer].data[y][x]]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
args.push("background: #ffffff");
|
args.push("background: #ffffff");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,33 +1,33 @@
|
||||||
// Maybe should extend Sprite?
|
// Maybe should extend Sprite?
|
||||||
Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset, tilemap, layer) {
|
Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset, tilemap, layer) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Phaser.Game} game - Description.
|
* @property {Phaser.Game} game - Description.
|
||||||
*/
|
*/
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Description} canvas - Description.
|
* @property {Description} canvas - Description.
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.canvas = Phaser.Canvas.create(renderWidth, renderHeight);
|
this.canvas = Phaser.Canvas.create(renderWidth, renderHeight);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Description} context - Description.
|
* @property {Description} context - Description.
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.context = this.canvas.getContext('2d');
|
this.context = this.canvas.getContext('2d');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Description} baseTexture - Description.
|
* @property {Description} baseTexture - Description.
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.baseTexture = new PIXI.BaseTexture(this.canvas);
|
this.baseTexture = new PIXI.BaseTexture(this.canvas);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Description} texture - Description.
|
* @property {Description} texture - Description.
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.texture = new PIXI.Texture(this.baseTexture);
|
this.texture = new PIXI.Texture(this.baseTexture);
|
||||||
|
|
||||||
this.textureFrame = new Phaser.Frame(0, 0, 0, renderWidth, renderHeight, 'tilemaplayer', game.rnd.uuid());
|
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
|
* @property {number} scrollFactorX - speed at which this layer scrolls
|
||||||
* horizontally, relative to the camera (e.g. scrollFactorX of 0.5 scrolls
|
* horizontally, relative to the camera (e.g. scrollFactorX of 0.5 scrolls
|
||||||
* half as quickly as the 'normal' camera-locked layers do)
|
* half as quickly as the 'normal' camera-locked layers do)
|
||||||
* @default 1
|
* @default 1
|
||||||
*/
|
*/
|
||||||
this.scrollFactorX = 1;
|
this.scrollFactorX = 1;
|
||||||
/**
|
/**
|
||||||
* @property {number} scrollFactorY - speed at which this layer scrolls
|
* @property {number} scrollFactorY - speed at which this layer scrolls
|
||||||
* vertically, relative to the camera (e.g. scrollFactorY of 0.5 scrolls
|
* vertically, relative to the camera (e.g. scrollFactorY of 0.5 scrolls
|
||||||
* half as quickly as the 'normal' camera-locked layers do)
|
* half as quickly as the 'normal' camera-locked layers do)
|
||||||
* @default 1
|
* @default 1
|
||||||
*/
|
*/
|
||||||
this.scrollFactorY = 1;
|
this.scrollFactorY = 1;
|
||||||
|
|
||||||
this.tilemap = null;
|
this.tilemap = null;
|
||||||
this.layer = null;
|
this.layer = null;
|
||||||
|
@ -251,14 +251,14 @@ Phaser.TilemapLayer.prototype.updateMapData = function (tilemap, layer) {
|
||||||
*/
|
*/
|
||||||
Phaser.TilemapLayer.prototype._fixX = function(x) {
|
Phaser.TilemapLayer.prototype._fixX = function(x) {
|
||||||
|
|
||||||
if (this.scrollFactorX === 1)
|
if (this.scrollFactorX === 1)
|
||||||
{
|
{
|
||||||
return x;
|
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) {
|
Phaser.TilemapLayer.prototype._unfixX = function(x) {
|
||||||
|
|
||||||
if (this.scrollFactorX === 1)
|
if (this.scrollFactorX === 1)
|
||||||
{
|
{
|
||||||
return x;
|
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) {
|
Phaser.TilemapLayer.prototype._fixY = function(y) {
|
||||||
|
|
||||||
if (this.scrollFactorY === 1)
|
if (this.scrollFactorY === 1)
|
||||||
{
|
{
|
||||||
return y;
|
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) {
|
Phaser.TilemapLayer.prototype._unfixY = function(y) {
|
||||||
|
|
||||||
if (this.scrollFactorY === 1)
|
if (this.scrollFactorY === 1)
|
||||||
{
|
{
|
||||||
return y;
|
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;
|
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;
|
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;
|
y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// adjust the x,y coordinates for scrollFactor
|
// adjust the x,y coordinates for scrollFactor
|
||||||
x = this._fixX( x );
|
x = this._fixX( x );
|
||||||
y = this._fixY( y );
|
y = this._fixY( y );
|
||||||
|
|
||||||
if (width > this.widthInPixels)
|
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))
|
if (collides === false || (collides && _tile.collideNone === false))
|
||||||
{
|
{
|
||||||
// convert tile coordinates back to camera space for return
|
// convert tile coordinates back to camera space for return
|
||||||
var _wx = this._unfixX( wx*sx ) / tileWidth;
|
var _wx = this._unfixX( wx*sx ) / tileWidth;
|
||||||
var _wy = this._unfixY( wy*sy ) / tileHeight;
|
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 });
|
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 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,183 +1,183 @@
|
||||||
Phaser.TilemapParser = {
|
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?
|
// How big is our image?
|
||||||
var img = game.cache.getTilesetImage(key);
|
var img = game.cache.getTilesetImage(key);
|
||||||
|
|
||||||
if (img == null)
|
if (img == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var width = img.width;
|
var width = img.width;
|
||||||
var height = img.height;
|
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 no tile width/height is given, try and figure it out (won't work if the tileset has margin/spacing)
|
||||||
if (tileWidth <= 0)
|
if (tileWidth <= 0)
|
||||||
{
|
{
|
||||||
tileWidth = Math.floor(-width / Math.min(-1, tileWidth));
|
tileWidth = Math.floor(-width / Math.min(-1, tileWidth));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tileHeight <= 0)
|
if (tileHeight <= 0)
|
||||||
{
|
{
|
||||||
tileHeight = Math.floor(-height / Math.min(-1, tileHeight));
|
tileHeight = Math.floor(-height / Math.min(-1, tileHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
var row = Math.round(width / tileWidth);
|
var row = Math.round(width / tileWidth);
|
||||||
var column = Math.round(height / tileHeight);
|
var column = Math.round(height / tileHeight);
|
||||||
var total = row * column;
|
var total = row * column;
|
||||||
|
|
||||||
if (tileMax !== -1)
|
if (tileMax !== -1)
|
||||||
{
|
{
|
||||||
total = tileMax;
|
total = tileMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Zero or smaller than tile sizes?
|
// Zero or smaller than tile sizes?
|
||||||
if (width === 0 || height === 0 || width < tileWidth || height < tileHeight || total === 0)
|
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");
|
console.warn("Phaser.TilemapParser.tileSet: width/height zero or width/height < given tileWidth/tileHeight");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let's create some tiles
|
// Let's create some tiles
|
||||||
var x = tileMargin;
|
var x = tileMargin;
|
||||||
var y = 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++)
|
for (var i = 0; i < total; i++)
|
||||||
{
|
{
|
||||||
tileset.addTile(new Phaser.Tile(tileset, i, x, y, tileWidth, tileHeight));
|
tileset.addTile(new Phaser.Tile(tileset, i, x, y, tileWidth, tileHeight));
|
||||||
|
|
||||||
x += tileWidth + tileSpacing;
|
x += tileWidth + tileSpacing;
|
||||||
|
|
||||||
if (x === width)
|
if (x === width)
|
||||||
{
|
{
|
||||||
x = tileMargin;
|
x = tileMargin;
|
||||||
y += tileHeight + tileSpacing;
|
y += tileHeight + tileSpacing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return tileset;
|
return tileset;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
parse: function (game, data, format) {
|
parse: function (game, data, format) {
|
||||||
|
|
||||||
if (format === Phaser.Tilemap.CSV)
|
if (format === Phaser.Tilemap.CSV)
|
||||||
{
|
{
|
||||||
return this.parseCSV(data);
|
return this.parseCSV(data);
|
||||||
}
|
}
|
||||||
else if (format === Phaser.Tilemap.TILED_JSON)
|
else if (format === Phaser.Tilemap.TILED_JSON)
|
||||||
{
|
{
|
||||||
return this.parseTiledJSON(data);
|
return this.parseTiledJSON(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse csv map data and generate tiles.
|
* Parse csv map data and generate tiles.
|
||||||
*
|
*
|
||||||
* @method Phaser.Tilemap.prototype.parseCSV
|
* @method Phaser.Tilemap.prototype.parseCSV
|
||||||
* @param {string} data - CSV map data.
|
* @param {string} data - CSV map data.
|
||||||
*/
|
*/
|
||||||
parseCSV: function (data) {
|
parseCSV: function (data) {
|
||||||
|
|
||||||
// Trim any rogue whitespace from the data
|
// Trim any rogue whitespace from the data
|
||||||
data = data.trim();
|
data = data.trim();
|
||||||
|
|
||||||
var output = [];
|
var output = [];
|
||||||
var rows = data.split("\n");
|
var rows = data.split("\n");
|
||||||
var height = rows.length;
|
var height = rows.length;
|
||||||
var width = 0;
|
var width = 0;
|
||||||
|
|
||||||
for (var i = 0; i < rows.length; i++)
|
for (var i = 0; i < rows.length; i++)
|
||||||
{
|
{
|
||||||
output[i] = [];
|
output[i] = [];
|
||||||
|
|
||||||
var column = rows[i].split(",");
|
var column = rows[i].split(",");
|
||||||
|
|
||||||
for (var c = 0; c < column.length; c++)
|
for (var c = 0; c < column.length; c++)
|
||||||
{
|
{
|
||||||
output[i][c] = parseInt(column[c]);
|
output[i][c] = parseInt(column[c], 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (width === 0)
|
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.
|
* Parse JSON map data and generate tiles.
|
||||||
*
|
*
|
||||||
* @method Phaser.Tilemap.prototype.parseTiledJSON
|
* @method Phaser.Tilemap.prototype.parseTiledJSON
|
||||||
* @param {string} data - JSON map data.
|
* @param {string} data - JSON map data.
|
||||||
* @param {string} key - Asset key for tileset image.
|
* @param {string} key - Asset key for tileset image.
|
||||||
*/
|
*/
|
||||||
parseTiledJSON: function (json) {
|
parseTiledJSON: function (json) {
|
||||||
|
|
||||||
var layers = [];
|
var layers = [];
|
||||||
|
|
||||||
for (var i = 0; i < json.layers.length; i++)
|
for (var i = 0; i < json.layers.length; i++)
|
||||||
{
|
{
|
||||||
// Check it's a data layer
|
// Check it's a data layer
|
||||||
if (!json.layers[i].data)
|
if (!json.layers[i].data)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// json.tilewidth
|
// json.tilewidth
|
||||||
// json.tileheight
|
// json.tileheight
|
||||||
|
|
||||||
var layer = {
|
var layer = {
|
||||||
|
|
||||||
name: json.layers[i].name,
|
name: json.layers[i].name,
|
||||||
width: json.layers[i].width,
|
width: json.layers[i].width,
|
||||||
height: json.layers[i].height,
|
height: json.layers[i].height,
|
||||||
alpha: json.layers[i].opacity,
|
alpha: json.layers[i].opacity,
|
||||||
visible: json.layers[i].visible,
|
visible: json.layers[i].visible,
|
||||||
indexes: [],
|
indexes: [],
|
||||||
|
|
||||||
tileMargin: json.tilesets[0].margin,
|
tileMargin: json.tilesets[0].margin,
|
||||||
tileSpacing: json.tilesets[0].spacing,
|
tileSpacing: json.tilesets[0].spacing
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var output = [];
|
var output = [];
|
||||||
var c = 0;
|
var c = 0;
|
||||||
var row;
|
var row;
|
||||||
|
|
||||||
for (var t = 0; t < json.layers[i].data.length; t++)
|
for (var t = 0; t < json.layers[i].data.length; t++)
|
||||||
{
|
{
|
||||||
if (c === 0)
|
if (c === 0)
|
||||||
{
|
{
|
||||||
row = [];
|
row = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
row.push(json.layers[i].data[t]);
|
row.push(json.layers[i].data[t]);
|
||||||
c++;
|
c++;
|
||||||
|
|
||||||
if (c == json.layers[i].width)
|
if (c == json.layers[i].width)
|
||||||
{
|
{
|
||||||
output.push(row);
|
output.push(row);
|
||||||
c = 0;
|
c = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
layer.data = output;
|
layer.data = output;
|
||||||
|
|
||||||
layers.push(layer);
|
layers.push(layer);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return layers;
|
return layers;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ Phaser.Tileset.prototype = {
|
||||||
|
|
||||||
checkTileIndex: function (index) {
|
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);
|
this.tiles[index].setCollision(left, right, up, down);
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,124 +20,91 @@ Phaser.Time = function (game) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The time at which the Game instance started.
|
* @property {number} _started - The time at which the Game instance started.
|
||||||
* @property {number} _started
|
|
||||||
* @private
|
* @private
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this._started = 0;
|
this._started = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The time (in ms) that the last second counter ticked over.
|
* @property {number} _timeLastSecond - The time (in ms) that the last second counter ticked over.
|
||||||
* @property {number} _timeLastSecond
|
|
||||||
* @private
|
* @private
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this._timeLastSecond = 0;
|
this._timeLastSecond = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The time the game started being paused.
|
* @property {number} _pauseStarted - The time the game started being paused.
|
||||||
* @property {number} _pauseStarted
|
|
||||||
* @private
|
* @private
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this._pauseStarted = 0;
|
this._pauseStarted = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The elapsed time calculated for the physics motion updates.
|
* @property {number} physicsElapsed - The elapsed time calculated for the physics motion updates.
|
||||||
* @property {number} physicsElapsed
|
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this.physicsElapsed = 0;
|
this.physicsElapsed = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Game time counter.
|
* @property {number} time - Game time counter.
|
||||||
* @property {number} time
|
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this.time = 0;
|
this.time = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Records how long the game has been paused for. Is reset each time the game pauses.
|
* @property {number} pausedTime - Records how long the game has been paused for. Is reset each time the game pauses.
|
||||||
* @property {number} pausedTime
|
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this.pausedTime = 0;
|
this.pausedTime = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The time right now.
|
* @property {number} now - The time right now.
|
||||||
* @property {number} now
|
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this.now = 0;
|
this.now = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Elapsed time since the last frame.
|
* @property {number} elapsed - Elapsed time since the last frame.
|
||||||
* @property {number} elapsed
|
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this.elapsed = 0;
|
this.elapsed = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Frames per second.
|
* @property {number} fps - Frames per second.
|
||||||
* @property {number} fps
|
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this.fps = 0;
|
this.fps = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The lowest rate the fps has dropped to.
|
* @property {number} fpsMin - The lowest rate the fps has dropped to.
|
||||||
* @property {number} fpsMin
|
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this.fpsMin = 1000;
|
this.fpsMin = 1000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The highest rate the fps has reached (usually no higher than 60fps).
|
* @property {number} fpsMax - The highest rate the fps has reached (usually no higher than 60fps).
|
||||||
* @property {number} fpsMax
|
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this.fpsMax = 0;
|
this.fpsMax = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The minimum amount of time the game has taken between two frames.
|
* @property {number} msMin - The minimum amount of time the game has taken between two frames.
|
||||||
* @property {number} msMin
|
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.msMin = 1000;
|
this.msMin = 1000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum amount of time the game has taken between two frames.
|
* @property {number} msMax - The maximum amount of time the game has taken between two frames.
|
||||||
* @property {number} msMax
|
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this.msMax = 0;
|
this.msMax = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of frames record in the last second.
|
* @property {number} frames - The number of frames record in the last second.
|
||||||
* @property {number} frames
|
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this.frames = 0;
|
this.frames = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Records how long the game was paused for in miliseconds.
|
* @property {number} pauseDuration - Records how long the game was paused for in miliseconds.
|
||||||
* @property {number} pauseDuration
|
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this.pauseDuration = 0;
|
this.pauseDuration = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The value that setTimeout needs to work out when to next update
|
* @property {number} timeToCall - The value that setTimeout needs to work out when to next update
|
||||||
* @property {number} timeToCall
|
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this.timeToCall = 0;
|
this.timeToCall = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal value used by timeToCall as part of the setTimeout loop
|
* @property {number} lastTime - Internal value used by timeToCall as part of the setTimeout loop
|
||||||
* @property {number} lastTime
|
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this.lastTime = 0;
|
this.lastTime = 0;
|
||||||
|
|
||||||
|
@ -146,9 +113,8 @@ Phaser.Time = function (game) {
|
||||||
this.game.onResume.add(this.gameResumed, this);
|
this.game.onResume.add(this.gameResumed, this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal value used to recover from the game pause state.
|
* @property {boolean} _justResumed - Internal value used to recover from the game pause state.
|
||||||
* @property {boolean} _justResumed
|
* @private
|
||||||
* @default
|
|
||||||
*/
|
*/
|
||||||
this._justResumed = false;
|
this._justResumed = false;
|
||||||
|
|
||||||
|
|
|
@ -14,104 +14,104 @@
|
||||||
*/
|
*/
|
||||||
Phaser.Timer = function (game) {
|
Phaser.Timer = function (game) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Phaser.Game} game - Local reference to game.
|
* @property {Phaser.Game} game - Local reference to game.
|
||||||
*/
|
*/
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The time at which this Timer instance started.
|
* The time at which this Timer instance started.
|
||||||
* @property {number} _started
|
* @property {number} _started
|
||||||
* @private
|
* @private
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this._started = 0;
|
this._started = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The time (in ms) that the last second counter ticked over.
|
* The time (in ms) that the last second counter ticked over.
|
||||||
* @property {number} _timeLastSecond
|
* @property {number} _timeLastSecond
|
||||||
* @private
|
* @private
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this._timeLastSecond = 0;
|
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 = {
|
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, callback, callbackContext) {
|
||||||
add: function (delay) {
|
add: function (delay) {
|
||||||
|
|
||||||
this.events.push({
|
this.events.push({
|
||||||
delay: delay,
|
delay: delay,
|
||||||
dispatched: false,
|
dispatched: false,
|
||||||
args: Array.prototype.splice.call(arguments, 1)
|
args: Array.prototype.splice.call(arguments, 1)
|
||||||
});
|
});
|
||||||
|
|
||||||
// this.events.push({
|
// this.events.push({
|
||||||
// delay: delay,
|
// delay: delay,
|
||||||
// dispatched: false,
|
// dispatched: false,
|
||||||
// callback: callback,
|
// callback: callback,
|
||||||
// callbackContext: callbackContext,
|
// callbackContext: callbackContext,
|
||||||
// args: Array.prototype.splice.call(arguments, 3)
|
// args: Array.prototype.splice.call(arguments, 3)
|
||||||
// });
|
// });
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
start: function() {
|
start: function() {
|
||||||
|
|
||||||
this._started = this.game.time.now;
|
this._started = this.game.time.now;
|
||||||
this.running = true;
|
this.running = true;
|
||||||
|
|
||||||
// sort the events based on delay here, also don't run unless events is populated
|
// 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 ability to auto-stop once all events are done
|
||||||
// add support for maximum duration
|
// add support for maximum duration
|
||||||
// add support for delay before starting
|
// add support for delay before starting
|
||||||
// add signals?
|
// add signals?
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
stop: function() {
|
stop: function() {
|
||||||
|
|
||||||
this.running = false;
|
this.running = false;
|
||||||
this.events.length = 0;
|
this.events.length = 0;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
update: function() {
|
update: function() {
|
||||||
|
|
||||||
// TODO: Game Paused support
|
// TODO: Game Paused support
|
||||||
|
|
||||||
if (this.running)
|
if (this.running)
|
||||||
{
|
{
|
||||||
var seconds = this.seconds();
|
var seconds = this.seconds();
|
||||||
|
|
||||||
for (var i = 0, len = this.events.length; i < len; i++)
|
for (var i = 0, len = this.events.length; i < len; i++)
|
||||||
{
|
{
|
||||||
if (this.events[i].dispatched === false && seconds >= this.events[i].delay)
|
if (this.events[i].dispatched === false && seconds >= this.events[i].delay)
|
||||||
{
|
{
|
||||||
this.events[i].dispatched = true;
|
this.events[i].dispatched = true;
|
||||||
// this.events[i].callback.apply(this.events[i].callbackContext, this.events[i].args);
|
// this.events[i].callback.apply(this.events[i].callbackContext, this.events[i].args);
|
||||||
this.onEvent.dispatch.apply(this, this.events[i].args);
|
this.onEvent.dispatch.apply(this, this.events[i].args);
|
||||||
// ought to slice it now
|
// ought to slice it now
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
seconds: function() {
|
seconds: function() {
|
||||||
return (this.game.time.now - this._started) * 0.001;
|
return (this.game.time.now - this._started) * 0.001;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* jshint curly: false */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Richard Davey <rich@photonstorm.com>
|
* @author Richard Davey <rich@photonstorm.com>
|
||||||
* @copyright 2013 Photon Storm Ltd.
|
* @copyright 2013 Photon Storm Ltd.
|
||||||
|
@ -16,546 +18,546 @@ Phaser.Easing = {
|
||||||
*
|
*
|
||||||
* @class Phaser.Easing.Linear
|
* @class Phaser.Easing.Linear
|
||||||
*/
|
*/
|
||||||
Linear: {
|
Linear: {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ease-in.
|
* Ease-in.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Linear#In
|
* @method Phaser.Easing.Linear#In
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} k^2.
|
* @returns {number} k^2.
|
||||||
*/
|
*/
|
||||||
None: function ( k ) {
|
None: function ( k ) {
|
||||||
|
|
||||||
return k;
|
return k;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quadratic easing.
|
* Quadratic easing.
|
||||||
*
|
*
|
||||||
* @class Phaser.Easing.Quadratic
|
* @class Phaser.Easing.Quadratic
|
||||||
*/
|
*/
|
||||||
Quadratic: {
|
Quadratic: {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ease-in.
|
* Ease-in.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Quadratic#In
|
* @method Phaser.Easing.Quadratic#In
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} k^2.
|
* @returns {number} k^2.
|
||||||
*/
|
*/
|
||||||
In: function ( k ) {
|
In: function ( k ) {
|
||||||
|
|
||||||
return k * k;
|
return k * k;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ease-out.
|
* Ease-out.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Quadratic#Out
|
* @method Phaser.Easing.Quadratic#Out
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} k* (2-k).
|
* @returns {number} k* (2-k).
|
||||||
*/
|
*/
|
||||||
Out: function ( k ) {
|
Out: function ( k ) {
|
||||||
|
|
||||||
return k * ( 2 - k );
|
return k * ( 2 - k );
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ease-in/out.
|
* Ease-in/out.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Quadratic#InOut
|
* @method Phaser.Easing.Quadratic#InOut
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
InOut: function ( k ) {
|
InOut: function ( k ) {
|
||||||
|
|
||||||
if ( ( k *= 2 ) < 1 ) return 0.5 * k * k;
|
if ( ( k *= 2 ) < 1 ) return 0.5 * k * k;
|
||||||
return - 0.5 * ( --k * ( k - 2 ) - 1 );
|
return - 0.5 * ( --k * ( k - 2 ) - 1 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cubic easing.
|
* Cubic easing.
|
||||||
*
|
*
|
||||||
* @class Phaser.Easing.Cubic
|
* @class Phaser.Easing.Cubic
|
||||||
*/
|
*/
|
||||||
Cubic: {
|
Cubic: {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cubic ease-in.
|
* Cubic ease-in.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Cubic#In
|
* @method Phaser.Easing.Cubic#In
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
In: function ( k ) {
|
In: function ( k ) {
|
||||||
|
|
||||||
return k * k * k;
|
return k * k * k;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cubic ease-out.
|
* Cubic ease-out.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Cubic#Out
|
* @method Phaser.Easing.Cubic#Out
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
Out: function ( k ) {
|
Out: function ( k ) {
|
||||||
|
|
||||||
return --k * k * k + 1;
|
return --k * k * k + 1;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cubic ease-in/out.
|
* Cubic ease-in/out.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Cubic#InOut
|
* @method Phaser.Easing.Cubic#InOut
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
InOut: function ( k ) {
|
InOut: function ( k ) {
|
||||||
|
|
||||||
if ( ( k *= 2 ) < 1 ) return 0.5 * k * k * k;
|
if ( ( k *= 2 ) < 1 ) return 0.5 * k * k * k;
|
||||||
return 0.5 * ( ( k -= 2 ) * k * k + 2 );
|
return 0.5 * ( ( k -= 2 ) * k * k + 2 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quartic easing.
|
* Quartic easing.
|
||||||
*
|
*
|
||||||
* @class Phaser.Easing.Quartic
|
* @class Phaser.Easing.Quartic
|
||||||
*/
|
*/
|
||||||
Quartic: {
|
Quartic: {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quartic ease-in.
|
* Quartic ease-in.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Quartic#In
|
* @method Phaser.Easing.Quartic#In
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
In: function ( k ) {
|
In: function ( k ) {
|
||||||
|
|
||||||
return k * k * k * k;
|
return k * k * k * k;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quartic ease-out.
|
* Quartic ease-out.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Quartic#Out
|
* @method Phaser.Easing.Quartic#Out
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
Out: function ( k ) {
|
Out: function ( k ) {
|
||||||
|
|
||||||
return 1 - ( --k * k * k * k );
|
return 1 - ( --k * k * k * k );
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quartic ease-in/out.
|
* Quartic ease-in/out.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Quartic#InOut
|
* @method Phaser.Easing.Quartic#InOut
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
InOut: function ( k ) {
|
InOut: function ( k ) {
|
||||||
|
|
||||||
if ( ( k *= 2 ) < 1) return 0.5 * k * k * k * k;
|
if ( ( k *= 2 ) < 1) return 0.5 * k * k * k * k;
|
||||||
return - 0.5 * ( ( k -= 2 ) * k * k * k - 2 );
|
return - 0.5 * ( ( k -= 2 ) * k * k * k - 2 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quintic easing.
|
* Quintic easing.
|
||||||
*
|
*
|
||||||
* @class Phaser.Easing.Quintic
|
* @class Phaser.Easing.Quintic
|
||||||
*/
|
*/
|
||||||
Quintic: {
|
Quintic: {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quintic ease-in.
|
* Quintic ease-in.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Quintic#In
|
* @method Phaser.Easing.Quintic#In
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
In: function ( k ) {
|
In: function ( k ) {
|
||||||
|
|
||||||
return k * k * k * k * k;
|
return k * k * k * k * k;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quintic ease-out.
|
* Quintic ease-out.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Quintic#Out
|
* @method Phaser.Easing.Quintic#Out
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
Out: function ( k ) {
|
Out: function ( k ) {
|
||||||
|
|
||||||
return --k * k * k * k * k + 1;
|
return --k * k * k * k * k + 1;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quintic ease-in/out.
|
* Quintic ease-in/out.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Quintic#InOut
|
* @method Phaser.Easing.Quintic#InOut
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
InOut: function ( k ) {
|
InOut: function ( k ) {
|
||||||
|
|
||||||
if ( ( k *= 2 ) < 1 ) return 0.5 * k * k * k * k * k;
|
if ( ( k *= 2 ) < 1 ) return 0.5 * k * k * k * k * k;
|
||||||
return 0.5 * ( ( k -= 2 ) * k * k * k * k + 2 );
|
return 0.5 * ( ( k -= 2 ) * k * k * k * k + 2 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sinusoidal easing.
|
* Sinusoidal easing.
|
||||||
*
|
*
|
||||||
* @class Phaser.Easing.Sinusoidal
|
* @class Phaser.Easing.Sinusoidal
|
||||||
*/
|
*/
|
||||||
Sinusoidal: {
|
Sinusoidal: {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sinusoidal ease-in.
|
* Sinusoidal ease-in.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Sinusoidal#In
|
* @method Phaser.Easing.Sinusoidal#In
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
In: function ( k ) {
|
In: function ( k ) {
|
||||||
|
|
||||||
return 1 - Math.cos( k * Math.PI / 2 );
|
return 1 - Math.cos( k * Math.PI / 2 );
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sinusoidal ease-out.
|
* Sinusoidal ease-out.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Sinusoidal#Out
|
* @method Phaser.Easing.Sinusoidal#Out
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
Out: function ( k ) {
|
Out: function ( k ) {
|
||||||
|
|
||||||
return Math.sin( k * Math.PI / 2 );
|
return Math.sin( k * Math.PI / 2 );
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sinusoidal ease-in/out.
|
* Sinusoidal ease-in/out.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Sinusoidal#InOut
|
* @method Phaser.Easing.Sinusoidal#InOut
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
InOut: function ( k ) {
|
InOut: function ( k ) {
|
||||||
|
|
||||||
return 0.5 * ( 1 - Math.cos( Math.PI * k ) );
|
return 0.5 * ( 1 - Math.cos( Math.PI * k ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exponential easing.
|
* Exponential easing.
|
||||||
*
|
*
|
||||||
* @class Phaser.Easing.Exponential
|
* @class Phaser.Easing.Exponential
|
||||||
*/
|
*/
|
||||||
Exponential: {
|
Exponential: {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exponential ease-in.
|
* Exponential ease-in.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Exponential#In
|
* @method Phaser.Easing.Exponential#In
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
In: function ( k ) {
|
In: function ( k ) {
|
||||||
|
|
||||||
return k === 0 ? 0 : Math.pow( 1024, k - 1 );
|
return k === 0 ? 0 : Math.pow( 1024, k - 1 );
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exponential ease-out.
|
* Exponential ease-out.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Exponential#Out
|
* @method Phaser.Easing.Exponential#Out
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
Out: function ( k ) {
|
Out: function ( k ) {
|
||||||
|
|
||||||
return k === 1 ? 1 : 1 - Math.pow( 2, - 10 * k );
|
return k === 1 ? 1 : 1 - Math.pow( 2, - 10 * k );
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exponential ease-in/out.
|
* Exponential ease-in/out.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Exponential#InOut
|
* @method Phaser.Easing.Exponential#InOut
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
InOut: function ( k ) {
|
InOut: function ( k ) {
|
||||||
|
|
||||||
if ( k === 0 ) return 0;
|
if ( k === 0 ) return 0;
|
||||||
if ( k === 1 ) return 1;
|
if ( k === 1 ) return 1;
|
||||||
if ( ( k *= 2 ) < 1 ) return 0.5 * Math.pow( 1024, k - 1 );
|
if ( ( k *= 2 ) < 1 ) return 0.5 * Math.pow( 1024, k - 1 );
|
||||||
return 0.5 * ( - Math.pow( 2, - 10 * ( k - 1 ) ) + 2 );
|
return 0.5 * ( - Math.pow( 2, - 10 * ( k - 1 ) ) + 2 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Circular easing.
|
* Circular easing.
|
||||||
*
|
*
|
||||||
* @class Phaser.Easing.Circular
|
* @class Phaser.Easing.Circular
|
||||||
*/
|
*/
|
||||||
Circular: {
|
Circular: {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Circular ease-in.
|
* Circular ease-in.
|
||||||
*
|
|
||||||
* @method Phaser.Easing.Circular#In
|
|
||||||
* @param {number} k - The value to be tweened.
|
|
||||||
* @returns {number} The tweened value.
|
|
||||||
*/
|
|
||||||
In: function ( k ) {
|
|
||||||
|
|
||||||
return 1 - Math.sqrt( 1 - k * k );
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Circular ease-out.
|
|
||||||
*
|
|
||||||
* @method Phaser.Easing.Circular#Out
|
|
||||||
* @param {number} k - The value to be tweened.
|
|
||||||
* @returns {number} The tweened value.
|
|
||||||
*/
|
|
||||||
Out: function ( k ) {
|
|
||||||
|
|
||||||
return Math.sqrt( 1 - ( --k * k ) );
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Circular ease-in/out.
|
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Circular#InOut
|
* @method Phaser.Easing.Circular#In
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
InOut: function ( k ) {
|
In: function ( k ) {
|
||||||
|
|
||||||
if ( ( k *= 2 ) < 1) return - 0.5 * ( Math.sqrt( 1 - k * k) - 1);
|
return 1 - Math.sqrt( 1 - k * k );
|
||||||
return 0.5 * ( Math.sqrt( 1 - ( k -= 2) * k) + 1);
|
|
||||||
|
|
||||||
}
|
},
|
||||||
|
|
||||||
},
|
/**
|
||||||
|
* Circular ease-out.
|
||||||
|
*
|
||||||
|
* @method Phaser.Easing.Circular#Out
|
||||||
|
* @param {number} k - The value to be tweened.
|
||||||
|
* @returns {number} The tweened value.
|
||||||
|
*/
|
||||||
|
Out: function ( k ) {
|
||||||
|
|
||||||
|
return Math.sqrt( 1 - ( --k * k ) );
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Circular ease-in/out.
|
||||||
|
*
|
||||||
|
* @method Phaser.Easing.Circular#InOut
|
||||||
|
* @param {number} k - The value to be tweened.
|
||||||
|
* @returns {number} The tweened value.
|
||||||
|
*/
|
||||||
|
InOut: function ( k ) {
|
||||||
|
|
||||||
|
if ( ( k *= 2 ) < 1) return - 0.5 * ( Math.sqrt( 1 - k * k) - 1);
|
||||||
|
return 0.5 * ( Math.sqrt( 1 - ( k -= 2) * k) + 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Elastic easing.
|
* Elastic easing.
|
||||||
*
|
*
|
||||||
* @class Phaser.Easing.Elastic
|
* @class Phaser.Easing.Elastic
|
||||||
*/
|
*/
|
||||||
Elastic: {
|
Elastic: {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Elastic ease-in.
|
* Elastic ease-in.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Elastic#In
|
* @method Phaser.Easing.Elastic#In
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
In: function ( k ) {
|
In: function ( k ) {
|
||||||
|
|
||||||
var s, a = 0.1, p = 0.4;
|
var s, a = 0.1, p = 0.4;
|
||||||
if ( k === 0 ) return 0;
|
if ( k === 0 ) return 0;
|
||||||
if ( k === 1 ) return 1;
|
if ( k === 1 ) return 1;
|
||||||
if ( !a || a < 1 ) { a = 1; s = p / 4; }
|
if ( !a || a < 1 ) { a = 1; s = p / 4; }
|
||||||
else s = p * Math.asin( 1 / a ) / ( 2 * Math.PI );
|
else s = p * Math.asin( 1 / a ) / ( 2 * Math.PI );
|
||||||
return - ( a * Math.pow( 2, 10 * ( k -= 1 ) ) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) );
|
return - ( a * Math.pow( 2, 10 * ( k -= 1 ) ) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) );
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Elastic ease-out.
|
* Elastic ease-out.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Elastic#Out
|
* @method Phaser.Easing.Elastic#Out
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
Out: function ( k ) {
|
Out: function ( k ) {
|
||||||
|
|
||||||
var s, a = 0.1, p = 0.4;
|
var s, a = 0.1, p = 0.4;
|
||||||
if ( k === 0 ) return 0;
|
if ( k === 0 ) return 0;
|
||||||
if ( k === 1 ) return 1;
|
if ( k === 1 ) return 1;
|
||||||
if ( !a || a < 1 ) { a = 1; s = p / 4; }
|
if ( !a || a < 1 ) { a = 1; s = p / 4; }
|
||||||
else s = p * Math.asin( 1 / a ) / ( 2 * Math.PI );
|
else s = p * Math.asin( 1 / a ) / ( 2 * Math.PI );
|
||||||
return ( a * Math.pow( 2, - 10 * k) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) + 1 );
|
return ( a * Math.pow( 2, - 10 * k) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) + 1 );
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Elastic ease-in/out.
|
* Elastic ease-in/out.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Elastic#InOut
|
* @method Phaser.Easing.Elastic#InOut
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
InOut: function ( k ) {
|
InOut: function ( k ) {
|
||||||
|
|
||||||
var s, a = 0.1, p = 0.4;
|
var s, a = 0.1, p = 0.4;
|
||||||
if ( k === 0 ) return 0;
|
if ( k === 0 ) return 0;
|
||||||
if ( k === 1 ) return 1;
|
if ( k === 1 ) return 1;
|
||||||
if ( !a || a < 1 ) { a = 1; s = p / 4; }
|
if ( !a || a < 1 ) { a = 1; s = p / 4; }
|
||||||
else s = p * Math.asin( 1 / a ) / ( 2 * Math.PI );
|
else s = p * Math.asin( 1 / a ) / ( 2 * Math.PI );
|
||||||
if ( ( k *= 2 ) < 1 ) return - 0.5 * ( a * Math.pow( 2, 10 * ( k -= 1 ) ) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) );
|
if ( ( k *= 2 ) < 1 ) return - 0.5 * ( a * Math.pow( 2, 10 * ( k -= 1 ) ) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) );
|
||||||
return a * Math.pow( 2, -10 * ( k -= 1 ) ) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) * 0.5 + 1;
|
return a * Math.pow( 2, -10 * ( k -= 1 ) ) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) * 0.5 + 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Back easing.
|
* Back easing.
|
||||||
*
|
*
|
||||||
* @class Phaser.Easing.Back
|
* @class Phaser.Easing.Back
|
||||||
*/
|
*/
|
||||||
Back: {
|
Back: {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Back ease-in.
|
* Back ease-in.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Back#In
|
* @method Phaser.Easing.Back#In
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
In: function ( k ) {
|
In: function ( k ) {
|
||||||
|
|
||||||
var s = 1.70158;
|
var s = 1.70158;
|
||||||
return k * k * ( ( s + 1 ) * k - s );
|
return k * k * ( ( s + 1 ) * k - s );
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Back ease-out.
|
* Back ease-out.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Back#Out
|
* @method Phaser.Easing.Back#Out
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
Out: function ( k ) {
|
Out: function ( k ) {
|
||||||
|
|
||||||
var s = 1.70158;
|
var s = 1.70158;
|
||||||
return --k * k * ( ( s + 1 ) * k + s ) + 1;
|
return --k * k * ( ( s + 1 ) * k + s ) + 1;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Back ease-in/out.
|
* Back ease-in/out.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Back#InOut
|
* @method Phaser.Easing.Back#InOut
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
InOut: function ( k ) {
|
InOut: function ( k ) {
|
||||||
|
|
||||||
var s = 1.70158 * 1.525;
|
var s = 1.70158 * 1.525;
|
||||||
if ( ( k *= 2 ) < 1 ) return 0.5 * ( k * k * ( ( s + 1 ) * k - s ) );
|
if ( ( k *= 2 ) < 1 ) return 0.5 * ( k * k * ( ( s + 1 ) * k - s ) );
|
||||||
return 0.5 * ( ( k -= 2 ) * k * ( ( s + 1 ) * k + s ) + 2 );
|
return 0.5 * ( ( k -= 2 ) * k * ( ( s + 1 ) * k + s ) + 2 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bounce easing.
|
* Bounce easing.
|
||||||
*
|
*
|
||||||
* @class Phaser.Easing.Bounce
|
* @class Phaser.Easing.Bounce
|
||||||
*/
|
*/
|
||||||
Bounce: {
|
Bounce: {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bounce ease-in.
|
* Bounce ease-in.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Bounce#In
|
* @method Phaser.Easing.Bounce#In
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
In: function ( k ) {
|
In: function ( k ) {
|
||||||
|
|
||||||
return 1 - Phaser.Easing.Bounce.Out( 1 - k );
|
return 1 - Phaser.Easing.Bounce.Out( 1 - k );
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bounce ease-out.
|
* Bounce ease-out.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Bounce#Out
|
* @method Phaser.Easing.Bounce#Out
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
Out: function ( k ) {
|
Out: function ( k ) {
|
||||||
|
|
||||||
if ( k < ( 1 / 2.75 ) ) {
|
if ( k < ( 1 / 2.75 ) ) {
|
||||||
|
|
||||||
return 7.5625 * k * k;
|
return 7.5625 * k * k;
|
||||||
|
|
||||||
} else if ( k < ( 2 / 2.75 ) ) {
|
} else if ( k < ( 2 / 2.75 ) ) {
|
||||||
|
|
||||||
return 7.5625 * ( k -= ( 1.5 / 2.75 ) ) * k + 0.75;
|
return 7.5625 * ( k -= ( 1.5 / 2.75 ) ) * k + 0.75;
|
||||||
|
|
||||||
} else if ( k < ( 2.5 / 2.75 ) ) {
|
} else if ( k < ( 2.5 / 2.75 ) ) {
|
||||||
|
|
||||||
return 7.5625 * ( k -= ( 2.25 / 2.75 ) ) * k + 0.9375;
|
return 7.5625 * ( k -= ( 2.25 / 2.75 ) ) * k + 0.9375;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
return 7.5625 * ( k -= ( 2.625 / 2.75 ) ) * k + 0.984375;
|
return 7.5625 * ( k -= ( 2.625 / 2.75 ) ) * k + 0.984375;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bounce ease-in/out.
|
* Bounce ease-in/out.
|
||||||
*
|
*
|
||||||
* @method Phaser.Easing.Bounce#InOut
|
* @method Phaser.Easing.Bounce#InOut
|
||||||
* @param {number} k - The value to be tweened.
|
* @param {number} k - The value to be tweened.
|
||||||
* @returns {number} The tweened value.
|
* @returns {number} The tweened value.
|
||||||
*/
|
*/
|
||||||
InOut: function ( k ) {
|
InOut: function ( k ) {
|
||||||
|
|
||||||
if ( k < 0.5 ) return Phaser.Easing.Bounce.In( k * 2 ) * 0.5;
|
if ( k < 0.5 ) return Phaser.Easing.Bounce.In( k * 2 ) * 0.5;
|
||||||
return Phaser.Easing.Bounce.Out( k * 2 - 1 ) * 0.5 + 0.5;
|
return Phaser.Easing.Bounce.Out( k * 2 - 1 ) * 0.5 + 0.5;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,7 +20,7 @@ Phaser.Tween = function (object, game) {
|
||||||
* @property {object} _object
|
* @property {object} _object
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._object = object;
|
this._object = object;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Phaser.Game} game - A reference to the currently running Game.
|
* @property {Phaser.Game} game - A reference to the currently running Game.
|
||||||
|
@ -154,7 +154,7 @@ Phaser.Tween = function (object, game) {
|
||||||
|
|
||||||
// Set all starting values present on the target object
|
// Set all starting values present on the target object
|
||||||
for ( var field in object ) {
|
for ( var field in object ) {
|
||||||
this._valuesStart[ field ] = parseFloat(object[field], 10);
|
this._valuesStart[ field ] = parseFloat(object[field], 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -177,45 +177,45 @@ Phaser.Tween = function (object, game) {
|
||||||
|
|
||||||
Phaser.Tween.prototype = {
|
Phaser.Tween.prototype = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure the Tween
|
* Configure the Tween
|
||||||
*
|
*
|
||||||
* @method Phaser.Tween#to
|
* @method Phaser.Tween#to
|
||||||
* @param {object} properties - Properties you want to tween.
|
* @param {object} properties - Properties you want to tween.
|
||||||
* @param {number} duration - Duration of this tween.
|
* @param {number} duration - Duration of this tween.
|
||||||
* @param {function} ease - Easing function.
|
* @param {function} ease - Easing function.
|
||||||
* @param {boolean} autoStart - Whether this tween will start automatically or not.
|
* @param {boolean} autoStart - Whether this tween will start automatically or not.
|
||||||
* @param {number} delay - Delay before this tween will start, defaults to 0 (no delay).
|
* @param {number} delay - Delay before this tween will start, defaults to 0 (no delay).
|
||||||
* @param {boolean} repeat - Should the tween automatically restart once complete? (ignores any chained tweens).
|
* @param {boolean} repeat - Should the tween automatically restart once complete? (ignores any chained tweens).
|
||||||
* @param {Phaser.Tween} yoyo - Description.
|
* @param {Phaser.Tween} yoyo - Description.
|
||||||
* @return {Phaser.Tween} Itself.
|
* @return {Phaser.Tween} Itself.
|
||||||
*/
|
*/
|
||||||
to: function ( properties, duration, ease, autoStart, delay, repeat, yoyo ) {
|
to: function ( properties, duration, ease, autoStart, delay, repeat, yoyo ) {
|
||||||
|
|
||||||
duration = duration || 1000;
|
duration = duration || 1000;
|
||||||
ease = ease || null;
|
ease = ease || null;
|
||||||
autoStart = autoStart || false;
|
autoStart = autoStart || false;
|
||||||
delay = delay || 0;
|
delay = delay || 0;
|
||||||
repeat = repeat || 0;
|
repeat = repeat || 0;
|
||||||
yoyo = yoyo || false;
|
yoyo = yoyo || false;
|
||||||
|
|
||||||
var self;
|
var self;
|
||||||
if (this._parent)
|
if (this._parent)
|
||||||
{
|
{
|
||||||
self = this._manager.create(this._object);
|
self = this._manager.create(this._object);
|
||||||
this._lastChild.chain(self);
|
this._lastChild.chain(self);
|
||||||
this._lastChild = self;
|
this._lastChild = self;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
self = this;
|
self = this;
|
||||||
this._parent = this;
|
this._parent = this;
|
||||||
this._lastChild = this;
|
this._lastChild = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
self._repeat = repeat;
|
self._repeat = repeat;
|
||||||
self._duration = duration;
|
self._duration = duration;
|
||||||
self._valuesEnd = properties;
|
self._valuesEnd = properties;
|
||||||
|
|
||||||
if (ease !== null)
|
if (ease !== null)
|
||||||
{
|
{
|
||||||
|
@ -235,256 +235,255 @@ Phaser.Tween.prototype = {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the tween running. Can also be called by the autoStart parameter of Tween.to.
|
* Starts the tween running. Can also be called by the autoStart parameter of Tween.to.
|
||||||
*
|
*
|
||||||
* @method Phaser.Tween#start
|
* @method Phaser.Tween#start
|
||||||
* @param {number} time - Description.
|
* @return {Phaser.Tween} Itself.
|
||||||
* @return {Phaser.Tween} Itself.
|
*/
|
||||||
*/
|
start: function () {
|
||||||
start: function ( time ) {
|
|
||||||
|
|
||||||
if (this.game === null || this._object === null) {
|
if (this.game === null || this._object === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._manager.add(this);
|
this._manager.add(this);
|
||||||
|
|
||||||
this.onStart.dispatch(this._object);
|
this.onStart.dispatch(this._object);
|
||||||
|
|
||||||
this.isRunning = true;
|
this.isRunning = true;
|
||||||
|
|
||||||
this._onStartCallbackFired = false;
|
this._onStartCallbackFired = false;
|
||||||
|
|
||||||
this._startTime = this.game.time.now + this._delayTime;
|
this._startTime = this.game.time.now + this._delayTime;
|
||||||
|
|
||||||
for ( var property in this._valuesEnd ) {
|
for ( var property in this._valuesEnd ) {
|
||||||
|
|
||||||
// check if an Array was provided as property value
|
// check if an Array was provided as property value
|
||||||
if ( this._valuesEnd[ property ] instanceof Array ) {
|
if ( this._valuesEnd[ property ] instanceof Array ) {
|
||||||
|
|
||||||
if ( this._valuesEnd[ property ].length === 0 ) {
|
if ( this._valuesEnd[ property ].length === 0 ) {
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a local copy of the Array with the start value at the front
|
// create a local copy of the Array with the start value at the front
|
||||||
this._valuesEnd[ property ] = [ this._object[ property ] ].concat( this._valuesEnd[ property ] );
|
this._valuesEnd[ property ] = [ this._object[ property ] ].concat( this._valuesEnd[ property ] );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this._valuesStart[ property ] = this._object[ property ];
|
this._valuesStart[ property ] = this._object[ property ];
|
||||||
|
|
||||||
if ( ( this._valuesStart[ property ] instanceof Array ) === false ) {
|
if ( ( this._valuesStart[ property ] instanceof Array ) === false ) {
|
||||||
this._valuesStart[ property ] *= 1.0; // Ensures we're using numbers, not strings
|
this._valuesStart[ property ] *= 1.0; // Ensures we're using numbers, not strings
|
||||||
}
|
}
|
||||||
|
|
||||||
this._valuesStartRepeat[ property ] = this._valuesStart[ property ] || 0;
|
this._valuesStartRepeat[ property ] = this._valuesStart[ property ] || 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops the tween if running and removes it from the TweenManager. If there are any onComplete callbacks or events they are not dispatched.
|
* Stops the tween if running and removes it from the TweenManager. If there are any onComplete callbacks or events they are not dispatched.
|
||||||
*
|
*
|
||||||
* @method Phaser.Tween#stop
|
* @method Phaser.Tween#stop
|
||||||
* @return {Phaser.Tween} Itself.
|
* @return {Phaser.Tween} Itself.
|
||||||
*/
|
*/
|
||||||
stop: function () {
|
stop: function () {
|
||||||
|
|
||||||
this.isRunning = false;
|
this.isRunning = false;
|
||||||
|
|
||||||
this._manager.remove(this);
|
this._manager.remove(this);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a delay time before this tween will start.
|
* Sets a delay time before this tween will start.
|
||||||
*
|
*
|
||||||
* @method Phaser.Tween#delay
|
* @method Phaser.Tween#delay
|
||||||
* @param {number} amount - The amount of the delay in ms.
|
* @param {number} amount - The amount of the delay in ms.
|
||||||
* @return {Phaser.Tween} Itself.
|
* @return {Phaser.Tween} Itself.
|
||||||
*/
|
*/
|
||||||
delay: function ( amount ) {
|
delay: function ( amount ) {
|
||||||
|
|
||||||
this._delayTime = amount;
|
this._delayTime = amount;
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the number of times this tween will repeat.
|
* Sets the number of times this tween will repeat.
|
||||||
*
|
*
|
||||||
* @method Phaser.Tween#repeat
|
* @method Phaser.Tween#repeat
|
||||||
* @param {number} times - How many times to repeat.
|
* @param {number} times - How many times to repeat.
|
||||||
* @return {Phaser.Tween} Itself.
|
* @return {Phaser.Tween} Itself.
|
||||||
*/
|
*/
|
||||||
repeat: function ( times ) {
|
repeat: function ( times ) {
|
||||||
|
|
||||||
this._repeat = times;
|
this._repeat = times;
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A tween that has yoyo set to true will run through from start to finish, then reverse from finish to start.
|
* A tween that has yoyo set to true will run through from start to finish, then reverse from finish to start.
|
||||||
* Used in combination with repeat you can create endless loops.
|
* Used in combination with repeat you can create endless loops.
|
||||||
*
|
*
|
||||||
* @method Phaser.Tween#yoyo
|
* @method Phaser.Tween#yoyo
|
||||||
* @param {boolean} yoyo - Set to true to yoyo this tween.
|
* @param {boolean} yoyo - Set to true to yoyo this tween.
|
||||||
* @return {Phaser.Tween} Itself.
|
* @return {Phaser.Tween} Itself.
|
||||||
*/
|
*/
|
||||||
yoyo: function( yoyo ) {
|
yoyo: function( yoyo ) {
|
||||||
|
|
||||||
this._yoyo = yoyo;
|
this._yoyo = yoyo;
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set easing function this tween will use, i.e. Phaser.Easing.Linear.None.
|
* Set easing function this tween will use, i.e. Phaser.Easing.Linear.None.
|
||||||
*
|
*
|
||||||
* @method Phaser.Tween#easing
|
* @method Phaser.Tween#easing
|
||||||
* @param {function} easing - The easing function this tween will use, i.e. Phaser.Easing.Linear.None.
|
* @param {function} easing - The easing function this tween will use, i.e. Phaser.Easing.Linear.None.
|
||||||
* @return {Phaser.Tween} Itself.
|
* @return {Phaser.Tween} Itself.
|
||||||
*/
|
*/
|
||||||
easing: function ( easing ) {
|
easing: function ( easing ) {
|
||||||
|
|
||||||
this._easingFunction = easing;
|
this._easingFunction = easing;
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set interpolation function the tween will use, by default it uses Phaser.Math.linearInterpolation.
|
* Set interpolation function the tween will use, by default it uses Phaser.Math.linearInterpolation.
|
||||||
*
|
*
|
||||||
* @method Phaser.Tween#interpolation
|
* @method Phaser.Tween#interpolation
|
||||||
* @param {function} interpolation - The interpolation function to use (Phaser.Math.linearInterpolation by default)
|
* @param {function} interpolation - The interpolation function to use (Phaser.Math.linearInterpolation by default)
|
||||||
* @return {Phaser.Tween} Itself.
|
* @return {Phaser.Tween} Itself.
|
||||||
*/
|
*/
|
||||||
interpolation: function ( interpolation ) {
|
interpolation: function ( interpolation ) {
|
||||||
|
|
||||||
this._interpolationFunction = interpolation;
|
this._interpolationFunction = interpolation;
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* You can chain tweens together by passing a reference to the chain function. This enables one tween to call another on completion.
|
* You can chain tweens together by passing a reference to the chain function. This enables one tween to call another on completion.
|
||||||
* You can pass as many tweens as you like to this function, they will each be chained in sequence.
|
* You can pass as many tweens as you like to this function, they will each be chained in sequence.
|
||||||
*
|
*
|
||||||
* @method Phaser.Tween#chain
|
* @method Phaser.Tween#chain
|
||||||
* @return {Phaser.Tween} Itself.
|
* @return {Phaser.Tween} Itself.
|
||||||
*/
|
*/
|
||||||
chain: function () {
|
chain: function () {
|
||||||
|
|
||||||
this._chainedTweens = arguments;
|
this._chainedTweens = arguments;
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loop a chain of tweens
|
* Loop a chain of tweens
|
||||||
*
|
*
|
||||||
* Usage:
|
* Usage:
|
||||||
* game.add.tween(p).to({ x: 700 }, 1000, Phaser.Easing.Linear.None, true)
|
* game.add.tween(p).to({ x: 700 }, 1000, Phaser.Easing.Linear.None, true)
|
||||||
* .to({ y: 300 }, 1000, Phaser.Easing.Linear.None)
|
* .to({ y: 300 }, 1000, Phaser.Easing.Linear.None)
|
||||||
* .to({ x: 0 }, 1000, Phaser.Easing.Linear.None)
|
* .to({ x: 0 }, 1000, Phaser.Easing.Linear.None)
|
||||||
* .to({ y: 0 }, 1000, Phaser.Easing.Linear.None)
|
* .to({ y: 0 }, 1000, Phaser.Easing.Linear.None)
|
||||||
* .loop();
|
* .loop();
|
||||||
* @method Phaser.Tween#loop
|
* @method Phaser.Tween#loop
|
||||||
* @return {Phaser.Tween} Itself.
|
* @return {Phaser.Tween} Itself.
|
||||||
*/
|
*/
|
||||||
loop: function() {
|
loop: function() {
|
||||||
|
|
||||||
this._lastChild.chain(this);
|
this._lastChild.chain(this);
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a callback to be fired when the tween starts. Note: callback will be called in the context of the global scope.
|
* Sets a callback to be fired when the tween starts. Note: callback will be called in the context of the global scope.
|
||||||
*
|
*
|
||||||
* @method Phaser.Tween#onStartCallback
|
* @method Phaser.Tween#onStartCallback
|
||||||
* @param {function} callback - The callback to invoke on start.
|
* @param {function} callback - The callback to invoke on start.
|
||||||
* @return {Phaser.Tween} Itself.
|
* @return {Phaser.Tween} Itself.
|
||||||
*/
|
*/
|
||||||
onStartCallback: function ( callback ) {
|
onStartCallback: function ( callback ) {
|
||||||
|
|
||||||
this._onStartCallback = callback;
|
this._onStartCallback = callback;
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a callback to be fired each time this tween updates. Note: callback will be called in the context of the global scope.
|
* Sets a callback to be fired each time this tween updates. Note: callback will be called in the context of the global scope.
|
||||||
*
|
*
|
||||||
* @method Phaser.Tween#onUpdateCallback
|
* @method Phaser.Tween#onUpdateCallback
|
||||||
* @param {function} callback - The callback to invoke each time this tween is updated.
|
* @param {function} callback - The callback to invoke each time this tween is updated.
|
||||||
* @return {Phaser.Tween} Itself.
|
* @return {Phaser.Tween} Itself.
|
||||||
*/
|
*/
|
||||||
onUpdateCallback: function ( callback ) {
|
onUpdateCallback: function ( callback ) {
|
||||||
|
|
||||||
this._onUpdateCallback = callback;
|
this._onUpdateCallback = callback;
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a callback to be fired when the tween completes. Note: callback will be called in the context of the global scope.
|
* Sets a callback to be fired when the tween completes. Note: callback will be called in the context of the global scope.
|
||||||
*
|
*
|
||||||
* @method Phaser.Tween#onCompleteCallback
|
* @method Phaser.Tween#onCompleteCallback
|
||||||
* @param {function} callback - The callback to invoke on completion.
|
* @param {function} callback - The callback to invoke on completion.
|
||||||
* @return {Phaser.Tween} Itself.
|
* @return {Phaser.Tween} Itself.
|
||||||
*/
|
*/
|
||||||
onCompleteCallback: function ( callback ) {
|
onCompleteCallback: function ( callback ) {
|
||||||
|
|
||||||
this._onCompleteCallback = callback;
|
this._onCompleteCallback = callback;
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pauses the tween.
|
* Pauses the tween.
|
||||||
*
|
*
|
||||||
* @method Phaser.Tween#pause
|
* @method Phaser.Tween#pause
|
||||||
*/
|
*/
|
||||||
pause: function () {
|
pause: function () {
|
||||||
this._paused = true;
|
this._paused = true;
|
||||||
this._pausedTime = this.game.time.now;
|
this._pausedTime = this.game.time.now;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resumes a paused tween.
|
* Resumes a paused tween.
|
||||||
*
|
*
|
||||||
* @method Phaser.Tween#resume
|
* @method Phaser.Tween#resume
|
||||||
*/
|
*/
|
||||||
resume: function () {
|
resume: function () {
|
||||||
this._paused = false;
|
this._paused = false;
|
||||||
this._startTime += (this.game.time.now - this._pausedTime);
|
this._startTime += (this.game.time.now - this._pausedTime);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Core tween update function called by the TweenManager. Does not need to be invoked directly.
|
* Core tween update function called by the TweenManager. Does not need to be invoked directly.
|
||||||
*
|
*
|
||||||
* @method Phaser.Tween#update
|
* @method Phaser.Tween#update
|
||||||
* @param {number} time - A timestamp passed in by the TweenManager.
|
* @param {number} time - A timestamp passed in by the TweenManager.
|
||||||
* @return {boolean} false if the tween has completed and should be deleted from the manager, otherwise true (still active).
|
* @return {boolean} false if the tween has completed and should be deleted from the manager, otherwise true (still active).
|
||||||
*/
|
*/
|
||||||
update: function ( time ) {
|
update: function ( time ) {
|
||||||
|
|
||||||
if (this.pendingDelete)
|
if (this.pendingDelete)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._paused || time < this._startTime) {
|
if (this._paused || time < this._startTime) {
|
||||||
|
|
||||||
|
@ -492,120 +491,120 @@ Phaser.Tween.prototype = {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var property;
|
var property;
|
||||||
|
|
||||||
if ( time < this._startTime ) {
|
if ( time < this._startTime ) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( this._onStartCallbackFired === false ) {
|
if ( this._onStartCallbackFired === false ) {
|
||||||
|
|
||||||
if ( this._onStartCallback !== null ) {
|
if ( this._onStartCallback !== null ) {
|
||||||
|
|
||||||
this._onStartCallback.call( this._object );
|
this._onStartCallback.call( this._object );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this._onStartCallbackFired = true;
|
this._onStartCallbackFired = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var elapsed = ( time - this._startTime ) / this._duration;
|
var elapsed = ( time - this._startTime ) / this._duration;
|
||||||
elapsed = elapsed > 1 ? 1 : elapsed;
|
elapsed = elapsed > 1 ? 1 : elapsed;
|
||||||
|
|
||||||
var value = this._easingFunction( elapsed );
|
var value = this._easingFunction( elapsed );
|
||||||
|
|
||||||
for ( property in this._valuesEnd ) {
|
for ( property in this._valuesEnd ) {
|
||||||
|
|
||||||
var start = this._valuesStart[ property ] || 0;
|
var start = this._valuesStart[ property ] || 0;
|
||||||
var end = this._valuesEnd[ property ];
|
var end = this._valuesEnd[ property ];
|
||||||
|
|
||||||
if ( end instanceof Array ) {
|
if ( end instanceof Array ) {
|
||||||
|
|
||||||
this._object[ property ] = this._interpolationFunction( end, value );
|
this._object[ property ] = this._interpolationFunction( end, value );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Parses relative end values with start as base (e.g.: +10, -3)
|
// Parses relative end values with start as base (e.g.: +10, -3)
|
||||||
if ( typeof(end) === "string" ) {
|
if ( typeof(end) === "string" ) {
|
||||||
end = start + parseFloat(end, 10);
|
end = start + parseFloat(end, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
// protect against non numeric properties.
|
// protect against non numeric properties.
|
||||||
if ( typeof(end) === "number" ) {
|
if ( typeof(end) === "number" ) {
|
||||||
this._object[ property ] = start + ( end - start ) * value;
|
this._object[ property ] = start + ( end - start ) * value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( this._onUpdateCallback !== null ) {
|
if ( this._onUpdateCallback !== null ) {
|
||||||
|
|
||||||
this._onUpdateCallback.call( this._object, value );
|
this._onUpdateCallback.call( this._object, value );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( elapsed == 1 ) {
|
if ( elapsed == 1 ) {
|
||||||
|
|
||||||
if ( this._repeat > 0 ) {
|
if ( this._repeat > 0 ) {
|
||||||
|
|
||||||
if ( isFinite( this._repeat ) ) {
|
if ( isFinite( this._repeat ) ) {
|
||||||
this._repeat--;
|
this._repeat--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reassign starting values, restart by making startTime = now
|
// reassign starting values, restart by making startTime = now
|
||||||
for ( property in this._valuesStartRepeat ) {
|
for ( property in this._valuesStartRepeat ) {
|
||||||
|
|
||||||
if ( typeof( this._valuesEnd[ property ] ) === "string" ) {
|
if ( typeof( this._valuesEnd[ property ] ) === "string" ) {
|
||||||
this._valuesStartRepeat[ property ] = this._valuesStartRepeat[ property ] + parseFloat(this._valuesEnd[ property ], 10);
|
this._valuesStartRepeat[ property ] = this._valuesStartRepeat[ property ] + parseFloat(this._valuesEnd[ property ], 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._yoyo) {
|
if (this._yoyo) {
|
||||||
var tmp = this._valuesStartRepeat[ property ];
|
var tmp = this._valuesStartRepeat[ property ];
|
||||||
this._valuesStartRepeat[ property ] = this._valuesEnd[ property ];
|
this._valuesStartRepeat[ property ] = this._valuesEnd[ property ];
|
||||||
this._valuesEnd[ property ] = tmp;
|
this._valuesEnd[ property ] = tmp;
|
||||||
this._reversed = !this._reversed;
|
this._reversed = !this._reversed;
|
||||||
}
|
}
|
||||||
this._valuesStart[ property ] = this._valuesStartRepeat[ property ];
|
this._valuesStart[ property ] = this._valuesStartRepeat[ property ];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this._startTime = time + this._delayTime;
|
this._startTime = time + this._delayTime;
|
||||||
|
|
||||||
this.onComplete.dispatch(this._object);
|
this.onComplete.dispatch(this._object);
|
||||||
|
|
||||||
if ( this._onCompleteCallback !== null ) {
|
if ( this._onCompleteCallback !== null ) {
|
||||||
this._onCompleteCallback.call( this._object );
|
this._onCompleteCallback.call( this._object );
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
this.isRunning = false;
|
this.isRunning = false;
|
||||||
this.onComplete.dispatch(this._object);
|
this.onComplete.dispatch(this._object);
|
||||||
|
|
||||||
if ( this._onCompleteCallback !== null ) {
|
if ( this._onCompleteCallback !== null ) {
|
||||||
this._onCompleteCallback.call( this._object );
|
this._onCompleteCallback.call( this._object );
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i ++ ) {
|
for ( var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i ++ ) {
|
||||||
|
|
||||||
this._chainedTweens[ i ].start( time );
|
this._chainedTweens[ i ].start( time );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,180 +22,183 @@
|
||||||
*/
|
*/
|
||||||
Phaser.TweenManager = function (game) {
|
Phaser.TweenManager = function (game) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Phaser.Game} game - Local reference to game.
|
* @property {Phaser.Game} game - Local reference to game.
|
||||||
*/
|
*/
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {array} _tweens - Description.
|
* @property {array} _tweens - Description.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._tweens = [];
|
this._tweens = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {array} _add - Description.
|
* @property {array} _add - Description.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._add = [];
|
this._add = [];
|
||||||
|
|
||||||
this.game.onPause.add(this.pauseAll, this);
|
this.game.onPause.add(this.pauseAll, this);
|
||||||
this.game.onResume.add(this.resumeAll, this);
|
this.game.onResume.add(this.resumeAll, this);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Phaser.TweenManager.prototype = {
|
Phaser.TweenManager.prototype = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Version number of this library.
|
* Version number of this library.
|
||||||
* @property {string} REVISION
|
* @property {string} REVISION
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
REVISION: '11dev',
|
REVISION: '11dev',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all the tween objects in an array.
|
* Get all the tween objects in an array.
|
||||||
* @method Phaser.TweenManager#getAll
|
* @method Phaser.TweenManager#getAll
|
||||||
* @returns {Phaser.Tween[]} Array with all tween objects.
|
* @returns {Phaser.Tween[]} Array with all tween objects.
|
||||||
*/
|
*/
|
||||||
getAll: function () {
|
getAll: function () {
|
||||||
|
|
||||||
return this._tweens;
|
return this._tweens;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all tween objects.
|
* Remove all tween objects.
|
||||||
* @method Phaser.TweenManager#removeAll
|
* @method Phaser.TweenManager#removeAll
|
||||||
*/
|
*/
|
||||||
removeAll: function () {
|
removeAll: function () {
|
||||||
|
|
||||||
this._tweens = [];
|
this._tweens = [];
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new tween into the TweenManager.
|
* Add a new tween into the TweenManager.
|
||||||
*
|
*
|
||||||
* @method Phaser.TweenManager#add
|
* @method Phaser.TweenManager#add
|
||||||
* @param {Phaser.Tween} tween - The tween object you want to add.
|
* @param {Phaser.Tween} tween - The tween object you want to add.
|
||||||
* @returns {Phaser.Tween} The tween object you added to the manager.
|
* @returns {Phaser.Tween} The tween object you added to the manager.
|
||||||
*/
|
*/
|
||||||
add: function ( tween ) {
|
add: function ( tween ) {
|
||||||
|
|
||||||
this._add.push( tween );
|
this._add.push( tween );
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite.
|
* Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite.
|
||||||
*
|
*
|
||||||
* @method Phaser.TweenManager#create
|
* @method Phaser.TweenManager#create
|
||||||
* @param {Object} object - Object the tween will be run on.
|
* @param {Object} object - Object the tween will be run on.
|
||||||
* @returns {Phaser.Tween} The newly created tween object.
|
* @returns {Phaser.Tween} The newly created tween object.
|
||||||
*/
|
*/
|
||||||
create: function (object) {
|
create: function (object) {
|
||||||
|
|
||||||
return new Phaser.Tween(object, this.game);
|
return new Phaser.Tween(object, this.game);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a tween from this manager.
|
* Remove a tween from this manager.
|
||||||
*
|
*
|
||||||
* @method Phaser.TweenManager#remove
|
* @method Phaser.TweenManager#remove
|
||||||
* @param {Phaser.Tween} tween - The tween object you want to remove.
|
* @param {Phaser.Tween} tween - The tween object you want to remove.
|
||||||
*/
|
*/
|
||||||
remove: function ( tween ) {
|
remove: function ( tween ) {
|
||||||
|
|
||||||
var i = this._tweens.indexOf( tween );
|
var i = this._tweens.indexOf( tween );
|
||||||
|
|
||||||
if ( i !== -1 ) {
|
if ( i !== -1 ) {
|
||||||
|
|
||||||
this._tweens[i].pendingDelete = true;
|
this._tweens[i].pendingDelete = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update all the tween objects you added to this manager.
|
|
||||||
*
|
|
||||||
* @method Phaser.TweenManager#update
|
|
||||||
* @returns {boolean} Return false if there's no tween to update, otherwise return true.
|
|
||||||
*/
|
|
||||||
update: function () {
|
|
||||||
|
|
||||||
if ( this._tweens.length === 0 && this._add.length === 0 ) return false;
|
|
||||||
|
|
||||||
var i = 0;
|
|
||||||
var numTweens = this._tweens.length;
|
|
||||||
|
|
||||||
while ( i < numTweens ) {
|
|
||||||
|
|
||||||
if ( this._tweens[ i ].update( this.game.time.now ) ) {
|
|
||||||
|
|
||||||
i++;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
this._tweens.splice( i, 1 );
|
|
||||||
|
|
||||||
numTweens--;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there are any new tweens to be added, do so now - otherwise they can be spliced out of the array before ever running
|
|
||||||
if (this._add.length > 0)
|
|
||||||
{
|
|
||||||
this._tweens = this._tweens.concat(this._add);
|
|
||||||
this._add.length = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks to see if a particular Sprite is currently being tweened.
|
|
||||||
*
|
|
||||||
* @method Phaser.TweenManager#isTweening
|
|
||||||
* @param {object} object - The object to check for tweens against.
|
|
||||||
* @returns {boolean} Returns true if the object is currently being tweened, false if not.
|
|
||||||
*/
|
|
||||||
isTweening: function(object) {
|
|
||||||
|
|
||||||
return this._tweens.some(function(tween) {
|
|
||||||
return tween._object === object;
|
|
||||||
});
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pauses all currently running tweens.
|
|
||||||
*
|
|
||||||
* @method Phaser.TweenManager#update
|
|
||||||
*/
|
|
||||||
pauseAll: function () {
|
|
||||||
|
|
||||||
for (var i = this._tweens.length - 1; i >= 0; i--) {
|
|
||||||
this._tweens[i].pause();
|
|
||||||
};
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pauses all currently paused tweens.
|
* Update all the tween objects you added to this manager.
|
||||||
*
|
*
|
||||||
* @method Phaser.TweenManager#resumeAll
|
* @method Phaser.TweenManager#update
|
||||||
*/
|
* @returns {boolean} Return false if there's no tween to update, otherwise return true.
|
||||||
resumeAll: function () {
|
*/
|
||||||
|
update: function () {
|
||||||
|
|
||||||
for (var i = this._tweens.length - 1; i >= 0; i--) {
|
if ( this._tweens.length === 0 && this._add.length === 0 )
|
||||||
this._tweens[i].resume();
|
{
|
||||||
};
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var i = 0;
|
||||||
|
var numTweens = this._tweens.length;
|
||||||
|
|
||||||
|
while ( i < numTweens ) {
|
||||||
|
|
||||||
|
if ( this._tweens[ i ].update( this.game.time.now ) ) {
|
||||||
|
|
||||||
|
i++;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
this._tweens.splice( i, 1 );
|
||||||
|
|
||||||
|
numTweens--;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there are any new tweens to be added, do so now - otherwise they can be spliced out of the array before ever running
|
||||||
|
if (this._add.length > 0)
|
||||||
|
{
|
||||||
|
this._tweens = this._tweens.concat(this._add);
|
||||||
|
this._add.length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to see if a particular Sprite is currently being tweened.
|
||||||
|
*
|
||||||
|
* @method Phaser.TweenManager#isTweening
|
||||||
|
* @param {object} object - The object to check for tweens against.
|
||||||
|
* @returns {boolean} Returns true if the object is currently being tweened, false if not.
|
||||||
|
*/
|
||||||
|
isTweening: function(object) {
|
||||||
|
|
||||||
|
return this._tweens.some(function(tween) {
|
||||||
|
return tween._object === object;
|
||||||
|
});
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pauses all currently running tweens.
|
||||||
|
*
|
||||||
|
* @method Phaser.TweenManager#update
|
||||||
|
*/
|
||||||
|
pauseAll: function () {
|
||||||
|
|
||||||
|
for (var i = this._tweens.length - 1; i >= 0; i--) {
|
||||||
|
this._tweens[i].pause();
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pauses all currently paused tweens.
|
||||||
|
*
|
||||||
|
* @method Phaser.TweenManager#resumeAll
|
||||||
|
*/
|
||||||
|
resumeAll: function () {
|
||||||
|
|
||||||
|
for (var i = this._tweens.length - 1; i >= 0; i--) {
|
||||||
|
this._tweens[i].resume();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,13 +79,13 @@ Phaser.Color = {
|
||||||
var argb = Phaser.Color.getRGB(color);
|
var argb = Phaser.Color.getRGB(color);
|
||||||
var hsl = Phaser.Color.RGBtoHSV(color);
|
var hsl = Phaser.Color.RGBtoHSV(color);
|
||||||
|
|
||||||
// Hex format
|
// Hex format
|
||||||
var result = Phaser.Color.RGBtoHexstring(color) + "\n";
|
var result = Phaser.Color.RGBtoHexstring(color) + "\n";
|
||||||
|
|
||||||
// RGB format
|
// RGB format
|
||||||
result = result.concat("Alpha: " + argb.alpha + " Red: " + argb.red + " Green: " + argb.green + " Blue: " + argb.blue) + "\n";
|
result = result.concat("Alpha: " + argb.alpha + " Red: " + argb.red + " Green: " + argb.green + " Blue: " + argb.blue) + "\n";
|
||||||
|
|
||||||
// HSL info
|
// HSL info
|
||||||
result = result.concat("Hue: " + hsl.hue + " Saturation: " + hsl.saturation + " Lightnes: " + hsl.lightness);
|
result = result.concat("Hue: " + hsl.hue + " Saturation: " + hsl.saturation + " Lightnes: " + hsl.lightness);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -232,7 +232,7 @@ Phaser.Color = {
|
||||||
if (typeof max === "undefined") { max = 255; }
|
if (typeof max === "undefined") { max = 255; }
|
||||||
if (typeof alpha === "undefined") { alpha = 255; }
|
if (typeof alpha === "undefined") { alpha = 255; }
|
||||||
|
|
||||||
// Sanity checks
|
// Sanity checks
|
||||||
if (max > 255) {
|
if (max > 255) {
|
||||||
return Phaser.Color.getColor(255, 255, 255);
|
return Phaser.Color.getColor(255, 255, 255);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,47 +15,47 @@
|
||||||
Phaser.Utils.Debug = function (game) {
|
Phaser.Utils.Debug = function (game) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Phaser.Game} game - A reference to the currently running Game.
|
* @property {Phaser.Game} game - A reference to the currently running Game.
|
||||||
*/
|
*/
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Context} context - The canvas context on which to render the debug information.
|
* @property {Context} context - The canvas context on which to render the debug information.
|
||||||
*/
|
*/
|
||||||
this.context = game.context;
|
this.context = game.context;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {string} font - The font that the debug information is rendered in.
|
* @property {string} font - The font that the debug information is rendered in.
|
||||||
* @default '14px Courier'
|
* @default '14px Courier'
|
||||||
*/
|
*/
|
||||||
this.font = '14px Courier';
|
this.font = '14px Courier';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} lineHeight - The line height between the debug text.
|
* @property {number} lineHeight - The line height between the debug text.
|
||||||
*/
|
*/
|
||||||
this.lineHeight = 16;
|
this.lineHeight = 16;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {boolean} renderShadow - Should the text be rendered with a slight shadow? Makes it easier to read on different types of background.
|
* @property {boolean} renderShadow - Should the text be rendered with a slight shadow? Makes it easier to read on different types of background.
|
||||||
*/
|
*/
|
||||||
this.renderShadow = true;
|
this.renderShadow = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Context} currentX - The current X position the debug information will be rendered at.
|
* @property {Context} currentX - The current X position the debug information will be rendered at.
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.currentX = 0;
|
this.currentX = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} currentY - The current Y position the debug information will be rendered at.
|
* @property {number} currentY - The current Y position the debug information will be rendered at.
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.currentY = 0;
|
this.currentY = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} currentAlpha - The current alpha the debug information will be rendered at.
|
* @property {number} currentAlpha - The current alpha the debug information will be rendered at.
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.currentAlpha = 1;
|
this.currentAlpha = 1;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -184,13 +184,13 @@ Phaser.Utils.Debug.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders the corners and point information of the given Sprite.
|
* Renders the corners and point information of the given Sprite.
|
||||||
* @method Phaser.Utils.Debug#renderSpriteCorners
|
* @method Phaser.Utils.Debug#renderSpriteCorners
|
||||||
* @param {Phaser.Sprite} sprite - The sprite to be rendered.
|
* @param {Phaser.Sprite} sprite - The sprite to be rendered.
|
||||||
* @param {boolean} [showText=false] - If true the x/y coordinates of each point will be rendered.
|
* @param {boolean} [showText=false] - If true the x/y coordinates of each point will be rendered.
|
||||||
* @param {boolean} [showBounds=false] - If true the bounds will be rendered over the top of the sprite.
|
* @param {boolean} [showBounds=false] - If true the bounds will be rendered over the top of the sprite.
|
||||||
* @param {string} [color='rgb(255,0,255)'] - The color the text is rendered in.
|
* @param {string} [color='rgb(255,0,255)'] - The color the text is rendered in.
|
||||||
*/
|
*/
|
||||||
renderSpriteCorners: function (sprite, showText, showBounds, color) {
|
renderSpriteCorners: function (sprite, showText, showBounds, color) {
|
||||||
|
|
||||||
if (this.context == null)
|
if (this.context == null)
|
||||||
|
@ -388,13 +388,13 @@ Phaser.Utils.Debug.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render Sprite collision.
|
* Render Sprite collision.
|
||||||
* @method Phaser.Utils.Debug#renderSpriteCollision
|
* @method Phaser.Utils.Debug#renderSpriteCollision
|
||||||
* @param {Phaser.Sprite} sprite - The sprite to be rendered.
|
* @param {Phaser.Sprite} sprite - The sprite to be rendered.
|
||||||
* @param {number} x - X position of the debug info to be rendered.
|
* @param {number} x - X position of the debug info to be rendered.
|
||||||
* @param {number} y - Y position of the debug info to be rendered.
|
* @param {number} y - Y position of the debug info to be rendered.
|
||||||
* @param {string} [color='rgb(255,255,255)'] - color of the debug info to be rendered. (format is css color string).
|
* @param {string} [color='rgb(255,255,255)'] - color of the debug info to be rendered. (format is css color string).
|
||||||
*/
|
*/
|
||||||
renderSpriteCollision: function (sprite, x, y, color) {
|
renderSpriteCollision: function (sprite, x, y, color) {
|
||||||
|
|
||||||
color = color || 'rgb(255,255,255)';
|
color = color || 'rgb(255,255,255)';
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* jshint supernew: true */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Richard Davey <rich@photonstorm.com>
|
* @author Richard Davey <rich@photonstorm.com>
|
||||||
* @copyright 2013 Photon Storm Ltd.
|
* @copyright 2013 Photon Storm Ltd.
|
||||||
|
@ -10,66 +12,68 @@
|
||||||
*/
|
*/
|
||||||
Phaser.Utils = {
|
Phaser.Utils = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A standard Fisher-Yates Array shuffle implementation.
|
* A standard Fisher-Yates Array shuffle implementation.
|
||||||
* @method Phaser.Utils.shuffle
|
* @method Phaser.Utils.shuffle
|
||||||
* @param {array} array - The array to shuffle.
|
* @param {array} array - The array to shuffle.
|
||||||
* @return {array} The shuffled array.
|
* @return {array} The shuffled array.
|
||||||
*/
|
*/
|
||||||
shuffle: function (array) {
|
shuffle: function (array) {
|
||||||
|
|
||||||
for (var i = array.length - 1; i > 0; i--)
|
for (var i = array.length - 1; i > 0; i--)
|
||||||
{
|
{
|
||||||
var j = Math.floor(Math.random() * (i + 1));
|
var j = Math.floor(Math.random() * (i + 1));
|
||||||
var temp = array[i];
|
var temp = array[i];
|
||||||
array[i] = array[j];
|
array[i] = array[j];
|
||||||
array[j] = temp;
|
array[j] = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
return array;
|
return array;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Javascript string pad http://www.webtoolkit.info/.
|
* Javascript string pad http://www.webtoolkit.info/.
|
||||||
* pad = the string to pad it out with (defaults to a space)
|
* pad = the string to pad it out with (defaults to a space)
|
||||||
* dir = 1 (left), 2 (right), 3 (both)
|
* dir = 1 (left), 2 (right), 3 (both)
|
||||||
* @method Phaser.Utils.pad
|
* @method Phaser.Utils.pad
|
||||||
* @param {string} str - The target string.
|
* @param {string} str - The target string.
|
||||||
* @param {number} len - Description.
|
* @param {number} len - Description.
|
||||||
* @param {number} pad - the string to pad it out with (defaults to a space).
|
* @param {number} pad - the string to pad it out with (defaults to a space).
|
||||||
* @param {number} [dir=3] the direction dir = 1 (left), 2 (right), 3 (both).
|
* @param {number} [dir=3] the direction dir = 1 (left), 2 (right), 3 (both).
|
||||||
* @return {string} The padded string
|
* @return {string} The padded string
|
||||||
*/
|
*/
|
||||||
pad: function (str, len, pad, dir) {
|
pad: function (str, len, pad, dir) {
|
||||||
|
|
||||||
if (typeof(len) == "undefined") { var len = 0; }
|
if (typeof(len) == "undefined") { var len = 0; }
|
||||||
if (typeof(pad) == "undefined") { var pad = ' '; }
|
if (typeof(pad) == "undefined") { var pad = ' '; }
|
||||||
if (typeof(dir) == "undefined") { var dir = 3; }
|
if (typeof(dir) == "undefined") { var dir = 3; }
|
||||||
|
|
||||||
if (len + 1 >= str.length)
|
var padlen = 0;
|
||||||
{
|
|
||||||
switch (dir)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
str = Array(len + 1 - str.length).join(pad) + str;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 3:
|
if (len + 1 >= str.length)
|
||||||
var right = Math.ceil((padlen = len - str.length) / 2);
|
{
|
||||||
var left = padlen - right;
|
switch (dir)
|
||||||
str = Array(left+1).join(pad) + str + Array(right+1).join(pad);
|
{
|
||||||
break;
|
case 1:
|
||||||
|
str = Array(len + 1 - str.length).join(pad) + str;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
case 3:
|
||||||
str = str + Array(len + 1 - str.length).join(pad);
|
var right = Math.ceil((padlen = len - str.length) / 2);
|
||||||
break;
|
var left = padlen - right;
|
||||||
}
|
str = Array(left+1).join(pad) + str + Array(right+1).join(pad);
|
||||||
}
|
break;
|
||||||
|
|
||||||
return str;
|
default:
|
||||||
|
str = str + Array(len + 1 - str.length).join(pad);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
},
|
return str;
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a slightly modified version of jQuery.isPlainObject. A plain object is an object whose internal class property is [object Object].
|
* This is a slightly modified version of jQuery.isPlainObject. A plain object is an object whose internal class property is [object Object].
|
||||||
|
@ -77,41 +81,41 @@ Phaser.Utils = {
|
||||||
* @param {object} obj - The object to inspect.
|
* @param {object} obj - The object to inspect.
|
||||||
* @return {boolean} - true if the object is plain, otherwise false.
|
* @return {boolean} - true if the object is plain, otherwise false.
|
||||||
*/
|
*/
|
||||||
isPlainObject: function (obj) {
|
isPlainObject: function (obj) {
|
||||||
|
|
||||||
// Not plain objects:
|
// Not plain objects:
|
||||||
// - Any object or value whose internal [[Class]] property is not "[object Object]"
|
// - Any object or value whose internal [[Class]] property is not "[object Object]"
|
||||||
// - DOM nodes
|
// - DOM nodes
|
||||||
// - window
|
// - window
|
||||||
if (typeof(obj) !== "object" || obj.nodeType || obj === obj.window)
|
if (typeof(obj) !== "object" || obj.nodeType || obj === obj.window)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Support: Firefox <20
|
// Support: Firefox <20
|
||||||
// The try/catch suppresses exceptions thrown when attempting to access
|
// The try/catch suppresses exceptions thrown when attempting to access
|
||||||
// the "constructor" property of certain host objects, ie. |window.location|
|
// the "constructor" property of certain host objects, ie. |window.location|
|
||||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=814622
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=814622
|
||||||
try {
|
try {
|
||||||
if (obj.constructor && !hasOwn.call(obj.constructor.prototype, "isPrototypeOf"))
|
if (obj.constructor && !hasOwn.call(obj.constructor.prototype, "isPrototypeOf"))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the function hasn't returned already, we're confident that
|
// If the function hasn't returned already, we're confident that
|
||||||
// |obj| is a plain object, created by {} or constructed with new Object
|
// |obj| is a plain object, created by {} or constructed with new Object
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// deep, target, objects to copy to the target object
|
// deep, target, objects to copy to the target object
|
||||||
// This is a slightly modified version of {@link http://api.jquery.com/jQuery.extend/|jQuery.extend}
|
// This is a slightly modified version of {@link http://api.jquery.com/jQuery.extend/|jQuery.extend}
|
||||||
// deep (boolean)
|
// deep (boolean)
|
||||||
// target (object to add to)
|
// target (object to add to)
|
||||||
// objects ... (objects to recurse and copy from)
|
// objects ... (objects to recurse and copy from)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a slightly modified version of http://api.jquery.com/jQuery.extend/
|
* This is a slightly modified version of http://api.jquery.com/jQuery.extend/
|
||||||
|
@ -120,87 +124,87 @@ Phaser.Utils = {
|
||||||
* @param {object} target - The target object to copy to.
|
* @param {object} target - The target object to copy to.
|
||||||
* @return {object} The extended object.
|
* @return {object} The extended object.
|
||||||
*/
|
*/
|
||||||
extend: function () {
|
extend: function () {
|
||||||
|
|
||||||
var options, name, src, copy, copyIsArray, clone,
|
var options, name, src, copy, copyIsArray, clone,
|
||||||
target = arguments[0] || {},
|
target = arguments[0] || {},
|
||||||
i = 1,
|
i = 1,
|
||||||
length = arguments.length,
|
length = arguments.length,
|
||||||
deep = false;
|
deep = false;
|
||||||
|
|
||||||
// Handle a deep copy situation
|
// Handle a deep copy situation
|
||||||
if (typeof target === "boolean")
|
if (typeof target === "boolean")
|
||||||
{
|
{
|
||||||
deep = target;
|
deep = target;
|
||||||
target = arguments[1] || {};
|
target = arguments[1] || {};
|
||||||
// skip the boolean and the target
|
// skip the boolean and the target
|
||||||
i = 2;
|
i = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// extend Phaser if only one argument is passed
|
// extend Phaser if only one argument is passed
|
||||||
if (length === i)
|
if (length === i)
|
||||||
{
|
{
|
||||||
target = this;
|
target = this;
|
||||||
--i;
|
--i;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( ; i < length; i++ )
|
for ( ; i < length; i++ )
|
||||||
{
|
{
|
||||||
// Only deal with non-null/undefined values
|
// Only deal with non-null/undefined values
|
||||||
if ((options = arguments[i]) != null)
|
if ((options = arguments[i]) != null)
|
||||||
{
|
{
|
||||||
// Extend the base object
|
// Extend the base object
|
||||||
for (name in options)
|
for (name in options)
|
||||||
{
|
{
|
||||||
src = target[name];
|
src = target[name];
|
||||||
copy = options[name];
|
copy = options[name];
|
||||||
|
|
||||||
// Prevent never-ending loop
|
// Prevent never-ending loop
|
||||||
if (target === copy)
|
if (target === copy)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recurse if we're merging plain objects or arrays
|
// Recurse if we're merging plain objects or arrays
|
||||||
if (deep && copy && (Phaser.Utils.isPlainObject(copy) || (copyIsArray = Array.isArray(copy))))
|
if (deep && copy && (Phaser.Utils.isPlainObject(copy) || (copyIsArray = Array.isArray(copy))))
|
||||||
{
|
{
|
||||||
if (copyIsArray)
|
if (copyIsArray)
|
||||||
{
|
{
|
||||||
copyIsArray = false;
|
copyIsArray = false;
|
||||||
clone = src && Array.isArray(src) ? src : [];
|
clone = src && Array.isArray(src) ? src : [];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
clone = src && Phaser.Utils.isPlainObject(src) ? src : {};
|
clone = src && Phaser.Utils.isPlainObject(src) ? src : {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Never move original objects, clone them
|
// Never move original objects, clone them
|
||||||
target[name] = Phaser.Utils.extend(deep, clone, copy);
|
target[name] = Phaser.Utils.extend(deep, clone, copy);
|
||||||
|
|
||||||
// Don't bring in undefined values
|
// Don't bring in undefined values
|
||||||
}
|
}
|
||||||
else if (copy !== undefined)
|
else if (copy !== undefined)
|
||||||
{
|
{
|
||||||
target[name] = copy;
|
target[name] = copy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the modified object
|
// Return the modified object
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Global functions that PIXI needs
|
// Global functions that PIXI needs
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var consoleDisabled = false;
|
var consoleDisabled = false;
|
||||||
if (consoleDisabled) {
|
if (consoleDisabled) {
|
||||||
window.console = undefined;
|
window.console = undefined;
|
||||||
}
|
}
|
||||||
if (window.console == undefined) {
|
if (window.console === undefined) {
|
||||||
window.console = {
|
window.console = {
|
||||||
debug: function() {
|
debug: function() {
|
||||||
return true;
|
return true;
|
||||||
|
@ -237,32 +241,42 @@ Phaser.Utils = {
|
||||||
* @return {array}
|
* @return {array}
|
||||||
*/
|
*/
|
||||||
function HEXtoRGB(hex) {
|
function HEXtoRGB(hex) {
|
||||||
return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255];
|
return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A polyfill for Function.prototype.bind
|
* A polyfill for Function.prototype.bind
|
||||||
*/
|
*/
|
||||||
if (typeof Function.prototype.bind != 'function') {
|
if (typeof Function.prototype.bind != 'function') {
|
||||||
Function.prototype.bind = (function () {
|
|
||||||
var slice = Array.prototype.slice;
|
|
||||||
return function (thisArg) {
|
|
||||||
var target = this, boundArgs = slice.call(arguments, 1);
|
|
||||||
|
|
||||||
if (typeof target != 'function') throw new TypeError();
|
Function.prototype.bind = (function () {
|
||||||
|
|
||||||
function bound() {
|
var slice = Array.prototype.slice;
|
||||||
var args = boundArgs.concat(slice.call(arguments));
|
|
||||||
target.apply(this instanceof bound ? this : thisArg, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
bound.prototype = (function F(proto) {
|
return function (thisArg) {
|
||||||
proto && (F.prototype = proto);
|
|
||||||
if (!(this instanceof F)) return new F;
|
|
||||||
})(target.prototype);
|
|
||||||
|
|
||||||
return bound;
|
var target = this, boundArgs = slice.call(arguments, 1);
|
||||||
};
|
|
||||||
})();
|
if (typeof target != 'function')
|
||||||
|
{
|
||||||
|
throw new TypeError();
|
||||||
|
}
|
||||||
|
|
||||||
|
function bound() {
|
||||||
|
var args = boundArgs.concat(slice.call(arguments));
|
||||||
|
target.apply(this instanceof bound ? this : thisArg, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
bound.prototype = (function F(proto) {
|
||||||
|
proto && (F.prototype = proto);
|
||||||
|
|
||||||
|
if (!(this instanceof F))
|
||||||
|
{
|
||||||
|
return new F;
|
||||||
|
}
|
||||||
|
})(target.prototype);
|
||||||
|
|
||||||
|
return bound;
|
||||||
|
};
|
||||||
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue