@@ -729,33 +849,55 @@ Object.defineProperty(Phaser.Animation.prototype, "frame", {
*
* @method Phaser.Animation.generateFrameNames
* @param {string} prefix - The start of the filename. If the filename was 'explosion_0001-large' the prefix would be 'explosion_'.
-* @param {number} min - The number to start sequentially counting from. If your frames are named 'explosion_0001' to 'explosion_0034' the min is 1.
-* @param {number} max - The number to count up to. If your frames are named 'explosion_0001' to 'explosion_0034' the max is 34.
+* @param {number} start - The number to start sequentially counting from. If your frames are named 'explosion_0001' to 'explosion_0034' the start is 1.
+* @param {number} stop - The number to count to. If your frames are named 'explosion_0001' to 'explosion_0034' the stop value is 34.
* @param {string} [suffix=''] - The end of the filename. If the filename was 'explosion_0001-large' the prefix would be '-large'.
* @param {number} [zeroPad=0] - The number of zeroes to pad the min and max values with. If your frames are named 'explosion_0001' to 'explosion_0034' then the zeroPad is 4.
*/
-Phaser.Animation.generateFrameNames = function (prefix, min, max, suffix, zeroPad) {
+Phaser.Animation.generateFrameNames = function (prefix, start, stop, suffix, zeroPad) {
if (typeof suffix == 'undefined') { suffix = ''; }
var output = [];
var frame = '';
- for (var i = min; i <= max; i++)
+ if (start < stop)
{
- if (typeof zeroPad == 'number')
+ for (var i = start; i <= stop; i++)
{
- // str, len, pad, dir
- frame = Phaser.Utils.pad(i.toString(), zeroPad, '0', 1);
+ if (typeof zeroPad == 'number')
+ {
+ // str, len, pad, dir
+ frame = Phaser.Utils.pad(i.toString(), zeroPad, '0', 1);
+ }
+ else
+ {
+ frame = i.toString();
+ }
+
+ frame = prefix + frame + suffix;
+
+ output.push(frame);
}
- else
+ }
+ else
+ {
+ for (var i = start; i >= stop; i--)
{
- frame = i.toString();
+ if (typeof zeroPad == 'number')
+ {
+ // str, len, pad, dir
+ frame = Phaser.Utils.pad(i.toString(), zeroPad, '0', 1);
+ }
+ else
+ {
+ frame = i.toString();
+ }
+
+ frame = prefix + frame + suffix;
+
+ output.push(frame);
}
-
- frame = prefix + frame + suffix;
-
- output.push(frame);
}
return output;
@@ -781,8 +923,8 @@ Phaser.Animation.generateFrameNames = function (prefix, min, max, suffix, zeroPa
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:51:58 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:43 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/AnimationManager.js.html b/docs/AnimationManager.js.html
index e6f07a55..3e94389f 100644
--- a/docs/AnimationManager.js.html
+++ b/docs/AnimationManager.js.html
@@ -54,6 +54,18 @@
AnimationParser
+
/**
+* @author Richard Davey <rich@photonstorm.com>
+* @copyright 2013 Photon Storm Ltd.
+* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
+*/
+
+/**
+* @class Phaser.Physics
+*/
+Phaser.Physics = {};
+
+/**
+* Arcade Physics constructor.
+*
+* @class Phaser.Physics.Arcade
+* @classdesc Arcade Physics Constructor
+* @constructor
+* @param {Phaser.Game} game reference to the current game instance.
+*/
+Phaser.Physics.Arcade = function (game) {
+
+ this.game = game;
+
+ this.gravity = new Phaser.Point;
+ this.bounds = new Phaser.Rectangle(0, 0, game.world.width, game.world.height);
+
+ /**
+ * Used by the QuadTree to set the maximum number of objects
+ * @type {number}
+ */
+ this.maxObjects = 10;
+
+ /**
+ * Used by the QuadTree to set the maximum number of levels
+ * @type {number}
+ */
+ this.maxLevels = 4;
+
+ this.OVERLAP_BIAS = 4;
+ this.TILE_OVERLAP = false;
+
+ this.quadTree = new Phaser.QuadTree(this, this.game.world.bounds.x, this.game.world.bounds.y, this.game.world.bounds.width, this.game.world.bounds.height, this.maxObjects, this.maxLevels);
+ this.quadTreeID = 0;
+
+ // Avoid gc spikes by caching these values for re-use
+ this._bounds1 = new Phaser.Rectangle;
+ this._bounds2 = new Phaser.Rectangle;
+ this._overlap = 0;
+ this._maxOverlap = 0;
+ this._velocity1 = 0;
+ this._velocity2 = 0;
+ this._newVelocity1 = 0;
+ this._newVelocity2 = 0;
+ this._average = 0;
+ this._mapData = [];
+ this._mapTiles = 0;
+ this._result = false;
+ this._total = 0;
+ this._angle = 0;
+ this._dx = 0;
+ this._dy = 0;
+
+};
+
+Phaser.Physics.Arcade.prototype = {
+
+ /**
+ * Called automatically by a Physics body, it updates all motion related values on the Body.
+ *
+ * @method Phaser.Physics.Arcade#updateMotion
+ * @param {Phaser.Physics.Arcade.Body} The Body object to be updated.
+ */
+ updateMotion: function (body) {
+
+ // If you're wondering why the velocity is halved and applied twice, read this: http://www.niksula.hut.fi/~hkankaan/Homepages/gravity.html
+
+ // Rotation
+ this._velocityDelta = (this.computeVelocity(0, body, body.angularVelocity, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2;
+ body.angularVelocity += this._velocityDelta;
+ body.rotation += (body.angularVelocity * this.game.time.physicsElapsed);
+ body.angularVelocity += this._velocityDelta;
+
+ // Horizontal
+ this._velocityDelta = (this.computeVelocity(1, body, body.velocity.x, body.acceleration.x, body.drag.x, body.maxVelocity.x) - body.velocity.x) / 2;
+ body.velocity.x += this._velocityDelta;
+ body.x += (body.velocity.x * this.game.time.physicsElapsed);
+ body.velocity.x += this._velocityDelta;
+
+ // Vertical
+ this._velocityDelta = (this.computeVelocity(2, body, body.velocity.y, body.acceleration.y, body.drag.y, body.maxVelocity.y) - body.velocity.y) / 2;
+ body.velocity.y += this._velocityDelta;
+ body.y += (body.velocity.y * this.game.time.physicsElapsed);
+ body.velocity.y += this._velocityDelta;
+
+ },
+
+ /**
+ * A tween-like function that takes a starting velocity and some other factors and returns an altered velocity.
+ *
+ * @method Phaser.Physics.Arcade#computeVelocity
+ * @param {number} axis - 1 for horizontal, 2 for vertical.
+ * @param {Phaser.Physics.Arcade.Body} body - The Body object to be updated.
+ * @param {number} velocity - Any component of velocity (e.g. 20).
+ * @param {number} acceleration - Rate at which the velocity is changing.
+ * @param {number} drag - Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set.
+ * @param {number} mMax - An absolute value cap for the velocity.
+ * @return {number} The altered Velocity value.
+ */
+ computeVelocity: function (axis, body, velocity, acceleration, drag, max) {
+
+ max = max || 10000;
+
+ if (axis == 1 && body.allowGravity)
+ {
+ velocity += this.gravity.x + body.gravity.x;
+ }
+ else if (axis == 2 && body.allowGravity)
+ {
+ velocity += this.gravity.y + body.gravity.y;
+ }
+
+ if (acceleration !== 0)
+ {
+ velocity += acceleration * this.game.time.physicsElapsed;
+ }
+ else if (drag !== 0)
+ {
+ this._drag = drag * this.game.time.physicsElapsed;
+
+ if (velocity - this._drag > 0)
+ {
+ velocity -= this._drag;
+ }
+ else if (velocity + this._drag < 0)
+ {
+ velocity += this._drag;
+ }
+ else
+ {
+ velocity = 0;
+ }
+ }
+
+ if (velocity > max)
+ {
+ velocity = max;
+ }
+ else if (velocity < -max)
+ {
+ velocity = -max;
+ }
+
+ return velocity;
+
+ },
+
+ /**
+ * Called automatically by the core game loop.
+ *
+ * @method Phaser.Physics.Arcade#preUpdate
+ * @protected
+ */
+ preUpdate: function () {
+
+ // Clear the tree
+ this.quadTree.clear();
+
+ // Create our tree which all of the Physics bodies will add themselves to
+ this.quadTreeID = 0;
+ this.quadTree = new Phaser.QuadTree(this, this.game.world.bounds.x, this.game.world.bounds.y, this.game.world.bounds.width, this.game.world.bounds.height, this.maxObjects, this.maxLevels);
+
+ },
+
+ /**
+ * Called automatically by the core game loop.
+ *
+ * @method Phaser.Physics.Arcade#postUpdate
+ * @protected
+ */
+ postUpdate: function () {
+
+ // Clear the tree ready for the next update
+ this.quadTree.clear();
+
+ },
+
+ /**
+ * Checks if two Sprite objects overlap.
+ *
+ * @method Phaser.Physics.Arcade#overlap
+ * @param {Phaser.Sprite} object1 - The first object to check. Can be an instance of Phaser.Sprite or anything that extends it.
+ * @param {Phaser.Sprite} object2 - The second object to check. Can be an instance of Phaser.Sprite or anything that extends it.
+ * @returns {boolean} true if the two objects overlap.
+ */
+ overlap: function (object1, object2) {
+
+ // Only test valid objects
+ if (object1 && object2 && object1.exists && object2.exists)
+ {
+ return (Phaser.Rectangle.intersects(object1.body, object2.body));
+ }
+
+ return false;
+
+ },
+
+ /**
+ * Checks for collision between two game objects. The objects can be Sprites, Groups, Emitters or Tilemaps.
+ * You can perform Sprite vs. Sprite, Sprite vs. Group, Group vs. Group, Sprite vs. Tilemap or Group vs. Tilemap collisions.
+ * The objects are also automatically separated.
+ *
+ * @method Phaser.Physics.Arcade#collide
+ * @param {Phaser.Sprite|Phaser.Group|Phaser.Particles.Emitter|Phaser.Tilemap} object1 - The first object to check. Can be an instance of Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter, or Phaser.Tilemap
+ * @param {Phaser.Sprite|Phaser.Group|Phaser.Particles.Emitter|Phaser.Tilemap} object2 - The second object to check. Can be an instance of Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter or Phaser.Tilemap
+ * @param {function} [collideCallback=null] - An optional callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap.
+ * @param {function} [processCallback=null] - A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then collideCallback will only be called if processCallback returns true.
+ * @param {object} [callbackContext] - The context in which to run the callbacks.
+ * @returns {number} The number of collisions that were processed.
+ */
+ collide: function (object1, object2, collideCallback, processCallback, callbackContext) {
+
+ collideCallback = collideCallback || null;
+ processCallback = processCallback || null;
+ callbackContext = callbackContext || collideCallback;
+
+ this._result = false;
+ this._total = 0;
+
+ // Only collide valid objects
+ if (object1 && object2 && object1.exists && object2.exists)
+ {
+ // Can expand to support Buttons, Text, etc at a later date. For now these are the essentials.
+
+ // SPRITES
+ if (object1.type == Phaser.SPRITE)
+ {
+ if (object2.type == Phaser.SPRITE)
+ {
+ this.collideSpriteVsSprite(object1, object2, collideCallback, processCallback, callbackContext);
+ }
+ else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER)
+ {
+ this.collideSpriteVsGroup(object1, object2, collideCallback, processCallback, callbackContext);
+ }
+ else if (object2.type == Phaser.TILEMAPLAYER)
+ {
+ this.collideSpriteVsTilemapLayer(object1, object2, collideCallback, processCallback, callbackContext);
+ }
+ }
+ // GROUPS
+ else if (object1.type == Phaser.GROUP)
+ {
+ if (object2.type == Phaser.SPRITE)
+ {
+ this.collideSpriteVsGroup(object2, object1, collideCallback, processCallback, callbackContext);
+ }
+ else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER)
+ {
+ this.collideGroupVsGroup(object1, object2, collideCallback, processCallback, callbackContext);
+ }
+ else if (object2.type == Phaser.TILEMAPLAYER)
+ {
+ this.collideGroupVsTilemapLayer(object1, object2, collideCallback, processCallback, callbackContext);
+ }
+ }
+ // TILEMAP LAYERS
+ else if (object1.type == Phaser.TILEMAPLAYER)
+ {
+ if (object2.type == Phaser.SPRITE)
+ {
+ this.collideSpriteVsTilemapLayer(object2, object1, collideCallback, processCallback, callbackContext);
+ }
+ else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER)
+ {
+ this.collideGroupVsTilemapLayer(object2, object1, collideCallback, processCallback, callbackContext);
+ }
+ }
+ // EMITTER
+ else if (object1.type == Phaser.EMITTER)
+ {
+ if (object2.type == Phaser.SPRITE)
+ {
+ this.collideSpriteVsGroup(object2, object1, collideCallback, processCallback, callbackContext);
+ }
+ else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER)
+ {
+ this.collideGroupVsGroup(object1, object2, collideCallback, processCallback, callbackContext);
+ }
+ else if (object2.type == Phaser.TILEMAPLAYER)
+ {
+ this.collideGroupVsTilemapLayer(object1, object2, collideCallback, processCallback, callbackContext);
+ }
+ }
+ }
+
+ return (this._total > 0);
+
+ },
+
+ /**
+ * An internal function. Use Phaser.Physics.Arcade.collide instead.
+ *
+ * @method Phaser.Physics.Arcade#collideSpriteVsTilemapLayer
+ * @private
+ */
+ collideSpriteVsTilemapLayer: function (sprite, tilemapLayer, collideCallback, processCallback, callbackContext) {
+
+ this._mapData = tilemapLayer.getTiles(sprite.body.x, sprite.body.y, sprite.body.width, sprite.body.height, true);
+
+ if (this._mapData.length > 1)
+ {
+ for (var i = 1; i < this._mapData.length; i++)
+ {
+ this.separateTile(sprite.body, this._mapData[i]);
+
+ if (this._result)
+ {
+ // They collided, is there a custom process callback?
+ if (processCallback)
+ {
+ if (processCallback.call(callbackContext, sprite, this._mapData[i]))
+ {
+ this._total++;
+
+ if (collideCallback)
+ {
+ collideCallback.call(callbackContext, sprite, this._mapData[i]);
+ }
+ }
+ }
+ else
+ {
+ this._total++;
+
+ if (collideCallback)
+ {
+ collideCallback.call(callbackContext, sprite, this._mapData[i]);
+ }
+ }
+ }
+ }
+ }
+
+ },
+
+ /**
+ * An internal function. Use Phaser.Physics.Arcade.collide instead.
+ *
+ * @method Phaser.Physics.Arcade#collideGroupVsTilemapLayer
+ * @private
+ */
+ collideGroupVsTilemapLayer: function (group, tilemapLayer, collideCallback, processCallback, callbackContext) {
+
+ if (group.length == 0)
+ {
+ return;
+ }
+
+ if (group._container.first._iNext)
+ {
+ var currentNode = group._container.first._iNext;
+
+ do
+ {
+ if (currentNode.exists)
+ {
+ this.collideSpriteVsTilemapLayer(currentNode, tilemapLayer, collideCallback, processCallback, callbackContext);
+ }
+ currentNode = currentNode._iNext;
+ }
+ while (currentNode != group._container.last._iNext);
+ }
+
+ },
+
+ /**
+ * An internal function. Use Phaser.Physics.Arcade.collide instead.
+ *
+ * @method Phaser.Physics.Arcade#collideSpriteVsSprite
+ * @private
+ */
+ collideSpriteVsSprite: function (sprite1, sprite2, collideCallback, processCallback, callbackContext) {
+
+ this.separate(sprite1.body, sprite2.body);
+
+ if (this._result)
+ {
+ // They collided, is there a custom process callback?
+ if (processCallback)
+ {
+ if (processCallback.call(callbackContext, sprite1, sprite2))
+ {
+ this._total++;
+
+ if (collideCallback)
+ {
+ collideCallback.call(callbackContext, sprite1, sprite2);
+ }
+ }
+ }
+ else
+ {
+ this._total++;
+
+ if (collideCallback)
+ {
+ collideCallback.call(callbackContext, sprite1, sprite2);
+ }
+ }
+ }
+
+ },
+
+ /**
+ * An internal function. Use Phaser.Physics.Arcade.collide instead.
+ *
+ * @method Phaser.Physics.Arcade#collideSpriteVsGroup
+ * @private
+ */
+ collideSpriteVsGroup: function (sprite, group, collideCallback, processCallback, callbackContext) {
+
+ if (group.length == 0)
+ {
+ return;
+ }
+
+ // What is the sprite colliding with in the quadtree?
+ this._potentials = this.quadTree.retrieve(sprite);
+
+ for (var i = 0, len = this._potentials.length; i < len; i++)
+ {
+ // We have our potential suspects, are they in this group?
+ if (this._potentials[i].sprite.group == group)
+ {
+ this.separate(sprite.body, this._potentials[i]);
+
+ if (this._result && processCallback)
+ {
+ this._result = processCallback.call(callbackContext, sprite, this._potentials[i].sprite);
+ }
+
+ if (this._result)
+ {
+ this._total++;
+
+ if (collideCallback)
+ {
+ collideCallback.call(callbackContext, sprite, this._potentials[i].sprite);
+ }
+ }
+ }
+ }
+
+ },
+
+ /**
+ * An internal function. Use Phaser.Physics.Arcade.collide instead.
+ *
+ * @method Phaser.Physics.Arcade#collideGroupVsGroup
+ * @private
+ */
+ collideGroupVsGroup: function (group1, group2, collideCallback, processCallback, callbackContext) {
+
+ if (group1.length == 0 || group2.length == 0)
+ {
+ return;
+ }
+
+ if (group1._container.first._iNext)
+ {
+ var currentNode = group1._container.first._iNext;
+
+ do
+ {
+ if (currentNode.exists)
+ {
+ this.collideSpriteVsGroup(currentNode, group2, collideCallback, processCallback, callbackContext);
+ }
+ currentNode = currentNode._iNext;
+ }
+ while (currentNode != group1._container.last._iNext);
+ }
+
+ },
+
+ /**
+ * The core separation function to separate two physics bodies.
+ * @method Phaser.Physics.Arcade#separate
+ * @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate.
+ * @param {Phaser.Physics.Arcade.Body} body2 - The Body object to separate.
+ * @returns {boolean} Returns true if the bodies were separated, otherwise false.
+ */
+ separate: function (body1, body2) {
+
+ this._result = (this.separateX(body1, body2) || this.separateY(body1, body2));
+
+ },
+
+ /**
+ * The core separation function to separate two physics bodies on the x axis.
+ * @method Phaser.Physics.Arcade#separateX
+ * @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate.
+ * @param {Phaser.Physics.Arcade.Body} body2 - The Body object to separate.
+ * @returns {boolean} Returns true if the bodies were separated, otherwise false.
+ */
+ separateX: function (body1, body2) {
+
+ // Can't separate two immovable bodies
+ if (body1.immovable && body2.immovable)
+ {
+ return false;
+ }
+
+ this._overlap = 0;
+
+ // Check if the hulls actually overlap
+ if (Phaser.Rectangle.intersects(body1, body2))
+ {
+ this._maxOverlap = body1.deltaAbsX() + body2.deltaAbsX() + this.OVERLAP_BIAS;
+
+ if (body1.deltaX() == 0 && body2.deltaX() == 0)
+ {
+ // They overlap but neither of them are moving
+ body1.embedded = true;
+ body2.embedded = true;
+ }
+ else if (body1.deltaX() > body2.deltaX())
+ {
+ // Body1 is moving right and/or Body2 is moving left
+ this._overlap = body1.x + body1.width - body2.x;
+
+ if ((this._overlap > this._maxOverlap) || body1.allowCollision.right == false || body2.allowCollision.left == false)
+ {
+ this._overlap = 0;
+ }
+ else
+ {
+ body1.touching.right = true;
+ body2.touching.left = true;
+ }
+ }
+ else if (body1.deltaX() < body2.deltaX())
+ {
+ // Body1 is moving left and/or Body2 is moving right
+ this._overlap = body1.x - body2.width - body2.x;
+
+ if ((-this._overlap > this._maxOverlap) || body1.allowCollision.left == false || body2.allowCollision.right == false)
+ {
+ this._overlap = 0;
+ }
+ else
+ {
+ body1.touching.left = true;
+ body2.touching.right = true;
+ }
+ }
+
+ // Then adjust their positions and velocities accordingly (if there was any overlap)
+ if (this._overlap != 0)
+ {
+ body1.overlapX = this._overlap;
+ body2.overlapX = this._overlap;
+
+ if (body1.customSeparateX || body2.customSeparateX)
+ {
+ return true;
+ }
+
+ this._velocity1 = body1.velocity.x;
+ this._velocity2 = body2.velocity.x;
+
+ if (!body1.immovable && !body2.immovable)
+ {
+ this._overlap *= 0.5;
+
+ body1.x = body1.x - this._overlap;
+ body2.x += this._overlap;
+
+ this._newVelocity1 = Math.sqrt((this._velocity2 * this._velocity2 * body2.mass) / body1.mass) * ((this._velocity2 > 0) ? 1 : -1);
+ this._newVelocity2 = Math.sqrt((this._velocity1 * this._velocity1 * body1.mass) / body2.mass) * ((this._velocity1 > 0) ? 1 : -1);
+ this._average = (this._newVelocity1 + this._newVelocity2) * 0.5;
+ this._newVelocity1 -= this._average;
+ this._newVelocity2 -= this._average;
+
+ body1.velocity.x = this._average + this._newVelocity1 * body1.bounce.x;
+ body2.velocity.x = this._average + this._newVelocity2 * body2.bounce.x;
+ }
+ else if (!body1.immovable)
+ {
+ body1.x = body1.x - this._overlap;
+ body1.velocity.x = this._velocity2 - this._velocity1 * body1.bounce.x;
+ }
+ else if (!body2.immovable)
+ {
+ body2.x += this._overlap;
+ body2.velocity.x = this._velocity1 - this._velocity2 * body2.bounce.x;
+ }
+
+ return true;
+ }
+ }
+
+ return false;
+
+ },
+
+ /**
+ * The core separation function to separate two physics bodies on the y axis.
+ * @method Phaser.Physics.Arcade#separateY
+ * @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate.
+ * @param {Phaser.Physics.Arcade.Body} body2 - The Body object to separate.
+ * @returns {boolean} Returns true if the bodies were separated, otherwise false.
+ */
+ separateY: function (body1, body2) {
+
+ // Can't separate two immovable or non-existing bodys
+ if (body1.immovable && body2.immovable)
+ {
+ return false;
+ }
+
+ this._overlap = 0;
+
+ // Check if the hulls actually overlap
+ if (Phaser.Rectangle.intersects(body1, body2))
+ {
+ this._maxOverlap = body1.deltaAbsY() + body2.deltaAbsY() + this.OVERLAP_BIAS;
+
+ if (body1.deltaY() == 0 && body2.deltaY() == 0)
+ {
+ // They overlap but neither of them are moving
+ body1.embedded = true;
+ body2.embedded = true;
+ }
+ else if (body1.deltaY() > body2.deltaY())
+ {
+ // Body1 is moving down and/or Body2 is moving up
+ this._overlap = body1.y + body1.height - body2.y;
+
+ if ((this._overlap > this._maxOverlap) || body1.allowCollision.down == false || body2.allowCollision.up == false)
+ {
+ this._overlap = 0;
+ }
+ else
+ {
+ body1.touching.down = true;
+ body2.touching.up = true;
+ }
+ }
+ else if (body1.deltaY() < body2.deltaY())
+ {
+ // Body1 is moving up and/or Body2 is moving down
+ this._overlap = body1.y - body2.height - body2.y;
+
+ if ((-this._overlap > this._maxOverlap) || body1.allowCollision.up == false || body2.allowCollision.down == false)
+ {
+ this._overlap = 0;
+ }
+ else
+ {
+ body1.touching.up = true;
+ body2.touching.down = true;
+ }
+ }
+
+ // Then adjust their positions and velocities accordingly (if there was any overlap)
+ if (this._overlap != 0)
+ {
+ body1.overlapY = this._overlap;
+ body2.overlapY = this._overlap;
+
+ if (body1.customSeparateY || body2.customSeparateY)
+ {
+ return true;
+ }
+
+ this._velocity1 = body1.velocity.y;
+ this._velocity2 = body2.velocity.y;
+
+ if (!body1.immovable && !body2.immovable)
+ {
+ this._overlap *= 0.5;
+
+ body1.y = body1.y - this._overlap;
+ body2.y += this._overlap;
+
+ this._newVelocity1 = Math.sqrt((this._velocity2 * this._velocity2 * body2.mass) / body1.mass) * ((this._velocity2 > 0) ? 1 : -1);
+ this._newVelocity2 = Math.sqrt((this._velocity1 * this._velocity1 * body1.mass) / body2.mass) * ((this._velocity1 > 0) ? 1 : -1);
+ this._average = (this._newVelocity1 + this._newVelocity2) * 0.5;
+ this._newVelocity1 -= this._average;
+ this._newVelocity2 -= this._average;
+
+ body1.velocity.y = this._average + this._newVelocity1 * body1.bounce.y;
+ body2.velocity.y = this._average + this._newVelocity2 * body2.bounce.y;
+ }
+ else if (!body1.immovable)
+ {
+ body1.y = body1.y - this._overlap;
+ body1.velocity.y = this._velocity2 - this._velocity1 * body1.bounce.y;
+
+ // This is special case code that handles things like horizontal moving platforms you can ride
+ if (body2.active && body2.moves && (body1.deltaY() > body2.deltaY()))
+ {
+ body1.x += body2.x - body2.lastX;
+ }
+ }
+ else if (!body2.immovable)
+ {
+ body2.y += this._overlap;
+ body2.velocity.y = this._velocity1 - this._velocity2 * body2.bounce.y;
+
+ // This is special case code that handles things like horizontal moving platforms you can ride
+ if (body1.sprite.active && body1.moves && (body1.deltaY() < body2.deltaY()))
+ {
+ body2.x += body1.x - body1.lastX;
+ }
+ }
+
+ return true;
+ }
+
+ }
+
+ return false;
+
+ },
+
+ /**
+ * The core separation function to separate a physics body and a tile.
+ * @method Phaser.Physics.Arcade#separateTile
+ * @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate.
+ * @param {Phaser.Tile} tile - The tile to collide against.
+ * @returns {boolean} Returns true if the bodies were separated, otherwise false.
+ */
+ separateTile: function (body, tile) {
+
+ this._result = (this.separateTileX(body, tile, true) || this.separateTileY(body, tile, true));
+
+ },
+
+ /**
+ * The core separation function to separate a physics body and a tile on the x axis.
+ * @method Phaser.Physics.Arcade#separateTileX
+ * @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate.
+ * @param {Phaser.Tile} tile - The tile to collide against.
+ * @returns {boolean} Returns true if the bodies were separated, otherwise false.
+ */
+ separateTileX: function (body, tile, separate) {
+
+ // Can't separate two immovable objects (tiles are always immovable)
+ if (body.immovable || body.deltaX() == 0 || Phaser.Rectangle.intersects(body.hullX, tile) == false)
+ {
+ return false;
+ }
+
+ this._overlap = 0;
+
+ // The hulls overlap, let's process it
+ this._maxOverlap = body.deltaAbsX() + this.OVERLAP_BIAS;
+
+ if (body.deltaX() < 0)
+ {
+ // Moving left
+ this._overlap = tile.right - body.hullX.x;
+
+ if ((this._overlap > this._maxOverlap) || body.allowCollision.left == false || tile.tile.collideRight == false)
+ {
+ this._overlap = 0;
+ }
+ else
+ {
+ body.touching.left = true;
+ }
+ }
+ else
+ {
+ // Moving right
+ this._overlap = body.hullX.right - tile.x;
+
+ if ((this._overlap > this._maxOverlap) || body.allowCollision.right == false || tile.tile.collideLeft == false)
+ {
+ this._overlap = 0;
+ }
+ else
+ {
+ body.touching.right = true;
+ }
+ }
+
+ // Then adjust their positions and velocities accordingly (if there was any overlap)
+ if (this._overlap != 0)
+ {
+ if (separate)
+ {
+ if (body.deltaX() < 0)
+ {
+ body.x = body.x + this._overlap;
+ }
+ else
+ {
+ body.x = body.x - this._overlap;
+ }
+
+ if (body.bounce.x == 0)
+ {
+ body.velocity.x = 0;
+ }
+ else
+ {
+ body.velocity.x = -body.velocity.x * body.bounce.x;
+ }
+
+ body.updateHulls();
+ }
+
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+
+ },
+
+ /**
+ * The core separation function to separate a physics body and a tile on the x axis.
+ * @method Phaser.Physics.Arcade#separateTileY
+ * @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate.
+ * @param {Phaser.Tile} tile - The tile to collide against.
+ * @returns {boolean} Returns true if the bodies were separated, otherwise false.
+ */
+ separateTileY: function (body, tile, separate) {
+
+ // Can't separate two immovable objects (tiles are always immovable)
+ if (body.immovable || body.deltaY() == 0 || Phaser.Rectangle.intersects(body.hullY, tile) == false)
+ {
+ return false;
+ }
+
+ this._overlap = 0;
+
+ // The hulls overlap, let's process it
+ this._maxOverlap = body.deltaAbsY() + this.OVERLAP_BIAS;
+
+ if (body.deltaY() < 0)
+ {
+ // Moving up
+ this._overlap = tile.bottom - body.hullY.y;
+
+ if ((this._overlap > this._maxOverlap) || body.allowCollision.up == false || tile.tile.collideDown == false)
+ {
+ this._overlap = 0;
+ }
+ else
+ {
+ body.touching.up = true;
+ }
+ }
+ else
+ {
+ // Moving down
+ this._overlap = body.hullY.bottom - tile.y;
+
+ if ((this._overlap > this._maxOverlap) || body.allowCollision.down == false || tile.tile.collideUp == false)
+ {
+ this._overlap = 0;
+ }
+ else
+ {
+ body.touching.down = true;
+ }
+ }
+
+ // Then adjust their positions and velocities accordingly (if there was any overlap)
+ if (this._overlap != 0)
+ {
+ if (separate)
+ {
+ if (body.deltaY() < 0)
+ {
+ body.y = body.y + this._overlap;
+ }
+ else
+ {
+ body.y = body.y - this._overlap;
+ }
+
+ if (body.bounce.y == 0)
+ {
+ body.velocity.y = 0;
+ }
+ else
+ {
+ body.velocity.y = -body.velocity.y * body.bounce.y;
+ }
+
+ body.updateHulls();
+ }
+
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+
+ },
+
+ /**
+ * Move the given display object towards the destination object at a steady velocity.
+ * If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds.
+ * Timings are approximate due to the way browser timers work. Allow for a variance of +- 50ms.
+ * Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course.
+ * Note: The display object doesn't stop moving once it reaches the destination coordinates.
+ * Note: Doesn't take into account acceleration, maxVelocity or drag (if you've set drag or acceleration too high this object may not move at all)
+ *
+ * @method Phaser.Physics.Arcade#moveToObject
+ * @param {any} displayObject - The display object to move.
+ * @param {any} destination - The display object to move towards. Can be any object but must have visible x/y properties.
+ * @param {number} [speed=60] - The speed it will move, in pixels per second (default is 60 pixels/sec)
+ * @param {number} [maxTime=0] - Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the object will arrive at destination in the given number of ms.
+ * @return {number} The angle (in radians) that the object should be visually set to in order to match its new velocity.
+ */
+ moveToObject: function (displayObject, destination, speed, maxTime) {
+
+ speed = speed || 60;
+ maxTime = maxTime || 0;
+
+ this._angle = Math.atan2(destination.y - displayObject.y, destination.x - displayObject.x);
+
+ if (maxTime > 0)
+ {
+ // We know how many pixels we need to move, but how fast?
+ speed = this.distanceBetween(displayObject, destination) / (maxTime / 1000);
+ }
+
+ displayObject.body.velocity.x = Math.cos(this._angle) * speed;
+ displayObject.body.velocity.y = Math.sin(this._angle) * speed;
+
+ return this._angle;
+
+ },
+
+ /**
+ * Move the given display object towards the pointer at a steady velocity. If no pointer is given it will use Phaser.Input.activePointer.
+ * If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds.
+ * Timings are approximate due to the way browser timers work. Allow for a variance of +- 50ms.
+ * Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course.
+ * Note: The display object doesn't stop moving once it reaches the destination coordinates.
+ *
+ * @method Phaser.Physics.Arcade#moveToPointer
+ * @param {any} displayObject - The display object to move.
+ * @param {number} [speed=60] - The speed it will move, in pixels per second (default is 60 pixels/sec)
+ * @param {Phaser.Pointer} [pointer] - The pointer to move towards. Defaults to Phaser.Input.activePointer.
+ * @param {number} [maxTime=0] - Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the object will arrive at destination in the given number of ms.
+ * @return {number} The angle (in radians) that the object should be visually set to in order to match its new velocity.
+ */
+ moveToPointer: function (displayObject, speed, pointer, maxTime) {
+
+ speed = speed || 60;
+ pointer = pointer || this.game.input.activePointer;
+ maxTime = maxTime || 0;
+
+ this._angle = this.angleToPointer(displayObject, pointer);
+
+ if (maxTime > 0)
+ {
+ // We know how many pixels we need to move, but how fast?
+ speed = this.distanceToPointer(displayObject, pointer) / (maxTime / 1000);
+ }
+
+ displayObject.body.velocity.x = Math.cos(this._angle) * speed;
+ displayObject.body.velocity.y = Math.sin(this._angle) * speed;
+
+ return this._angle;
+
+ },
+
+ /**
+ * Move the given display object towards the x/y coordinates at a steady velocity.
+ * If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds.
+ * Timings are approximate due to the way browser timers work. Allow for a variance of +- 50ms.
+ * Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course.
+ * Note: The display object doesn't stop moving once it reaches the destination coordinates.
+ * Note: Doesn't take into account acceleration, maxVelocity or drag (if you've set drag or acceleration too high this object may not move at all)
+ *
+ * @method Phaser.Physics.Arcade#moveToXY
+ * @param {any} displayObject - The display object to move.
+ * @param {number} x - The x coordinate to move towards.
+ * @param {number} y - The y coordinate to move towards.
+ * @param {number} [speed=60] - The speed it will move, in pixels per second (default is 60 pixels/sec)
+ * @param {number} [maxTime=0] - Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the object will arrive at destination in the given number of ms.
+ * @return {number} The angle (in radians) that the object should be visually set to in order to match its new velocity.
+ */
+ moveToXY: function (displayObject, x, y, speed, maxTime) {
+
+ speed = speed || 60;
+ maxTime = maxTime || 0;
+
+ this._angle = Math.atan2(y - displayObject.y, x - displayObject.x);
+
+ if (maxTime > 0)
+ {
+ // We know how many pixels we need to move, but how fast?
+ speed = this.distanceToXY(displayObject, x, y) / (maxTime / 1000);
+ }
+
+ displayObject.body.velocity.x = Math.cos(this._angle) * speed;
+ displayObject.body.velocity.y = Math.sin(this._angle) * speed;
+
+ return this._angle;
+
+ },
+
+ /**
+ * Given the angle (in degrees) and speed calculate the velocity and return it as a Point object, or set it to the given point object.
+ * One way to use this is: velocityFromAngle(angle, 200, sprite.velocity) which will set the values directly to the sprites velocity and not create a new Point object.
+ *
+ * @method Phaser.Physics.Arcade#velocityFromAngle
+ * @param {number} angle - The angle in degrees calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative)
+ * @param {number} [speed=60] - The speed it will move, in pixels per second sq.
+ * @param {Phaser.Point|object} [point] - The Point object in which the x and y properties will be set to the calculated velocity.
+ * @return {Phaser.Point} - A Point where point.x contains the velocity x value and point.y contains the velocity y value.
+ */
+ velocityFromAngle: function (angle, speed, point) {
+
+ speed = speed || 60;
+ point = point || new Phaser.Point;
+
+ return point.setTo((Math.cos(this.game.math.degToRad(angle)) * speed), (Math.sin(this.game.math.degToRad(angle)) * speed));
+
+ },
+
+ /**
+ * Given the rotation (in radians) and speed calculate the velocity and return it as a Point object, or set it to the given point object.
+ * One way to use this is: velocityFromRotation(rotation, 200, sprite.velocity) which will set the values directly to the sprites velocity and not create a new Point object.
+ *
+ * @method Phaser.Physics.Arcade#velocityFromRotation
+ * @param {number} rotation - The angle in radians.
+ * @param {number} [speed=60] - The speed it will move, in pixels per second sq.
+ * @param {Phaser.Point|object} [point] - The Point object in which the x and y properties will be set to the calculated velocity.
+ * @return {Phaser.Point} - A Point where point.x contains the velocity x value and point.y contains the velocity y value.
+ */
+ velocityFromRotation: function (rotation, speed, point) {
+
+ speed = speed || 60;
+ point = point || new Phaser.Point;
+
+ return point.setTo((Math.cos(rotation) * speed), (Math.sin(rotation) * speed));
+
+ },
+
+ /**
+ * Given the rotation (in radians) and speed calculate the acceleration and return it as a Point object, or set it to the given point object.
+ * One way to use this is: velocityFromRotation(rotation, 200, sprite.velocity) which will set the values directly to the sprites velocity and not create a new Point object.
+ *
+ * @method Phaser.Physics.Arcade#accelerationFromRotation
+ * @param {number} rotation - The angle in radians.
+ * @param {number} [speed=60] - The speed it will move, in pixels per second sq.
+ * @param {Phaser.Point|object} [point] - The Point object in which the x and y properties will be set to the calculated acceleration.
+ * @return {Phaser.Point} - A Point where point.x contains the acceleration x value and point.y contains the acceleration y value.
+ */
+ accelerationFromRotation: function (rotation, speed, point) {
+
+ speed = speed || 60;
+ point = point || new Phaser.Point;
+
+ return point.setTo((Math.cos(rotation) * speed), (Math.sin(rotation) * speed));
+
+ },
+
+ /**
+ * Sets the acceleration.x/y property on the display object so it will move towards the target at the given speed (in pixels per second sq.)
+ * You must give a maximum speed value, beyond which the display object won't go any faster.
+ * Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course.
+ * Note: The display object doesn't stop moving once it reaches the destination coordinates.
+ *
+ * @method Phaser.Physics.Arcade#accelerateToObject
+ * @param {any} displayObject - The display object to move.
+ * @param {any} destination - The display object to move towards. Can be any object but must have visible x/y properties.
+ * @param {number} [speed=60] - The speed it will accelerate in pixels per second.
+ * @param {number} [xSpeedMax=500] - The maximum x velocity the display object can reach.
+ * @param {number} [ySpeedMax=500] - The maximum y velocity the display object can reach.
+ * @return {number} The angle (in radians) that the object should be visually set to in order to match its new trajectory.
+ */
+ accelerateToObject: function (displayObject, destination, speed, xSpeedMax, ySpeedMax) {
+
+ if (typeof speed === 'undefined') { speed = 60; }
+ if (typeof xSpeedMax === 'undefined') { xSpeedMax = 1000; }
+ if (typeof ySpeedMax === 'undefined') { ySpeedMax = 1000; }
+
+ this._angle = this.angleBetween(displayObject, destination);
+
+ displayObject.body.acceleration.setTo(Math.cos(this._angle) * speed, Math.sin(this._angle) * speed);
+ displayObject.body.maxVelocity.setTo(xSpeedMax, ySpeedMax);
+
+ return this._angle;
+
+ },
+
+ /**
+ * Sets the acceleration.x/y property on the display object so it will move towards the target at the given speed (in pixels per second sq.)
+ * You must give a maximum speed value, beyond which the display object won't go any faster.
+ * Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course.
+ * Note: The display object doesn't stop moving once it reaches the destination coordinates.
+ *
+ * @method Phaser.Physics.Arcade#accelerateToPointer
+ * @param {any} displayObject - The display object to move.
+ * @param {Phaser.Pointer} [pointer] - The pointer to move towards. Defaults to Phaser.Input.activePointer.
+ * @param {number} [speed=60] - The speed it will accelerate in pixels per second.
+ * @param {number} [xSpeedMax=500] - The maximum x velocity the display object can reach.
+ * @param {number} [ySpeedMax=500] - The maximum y velocity the display object can reach.
+ * @return {number} The angle (in radians) that the object should be visually set to in order to match its new trajectory.
+ */
+ accelerateToPointer: function (displayObject, pointer, speed, xSpeedMax, ySpeedMax) {
+
+ if (typeof speed === 'undefined') { speed = 60; }
+ if (typeof pointer === 'undefined') { pointer = this.game.input.activePointer; }
+ if (typeof xSpeedMax === 'undefined') { xSpeedMax = 1000; }
+ if (typeof ySpeedMax === 'undefined') { ySpeedMax = 1000; }
+
+ this._angle = this.angleToPointer(displayObject, pointer);
+
+ displayObject.body.acceleration.setTo(Math.cos(this._angle) * speed, Math.sin(this._angle) * speed);
+ displayObject.body.maxVelocity.setTo(xSpeedMax, ySpeedMax);
+
+ return this._angle;
+
+ },
+
+ /**
+ * Sets the acceleration.x/y property on the display object so it will move towards the x/y coordinates at the given speed (in pixels per second sq.)
+ * You must give a maximum speed value, beyond which the display object won't go any faster.
+ * Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course.
+ * Note: The display object doesn't stop moving once it reaches the destination coordinates.
+ *
+ * @method Phaser.Physics.Arcade#accelerateToXY
+ * @param {any} displayObject - The display object to move.
+ * @param {number} x - The x coordinate to accelerate towards.
+ * @param {number} y - The y coordinate to accelerate towards.
+ * @param {number} [speed=60] - The speed it will accelerate in pixels per second.
+ * @param {number} [xSpeedMax=500] - The maximum x velocity the display object can reach.
+ * @param {number} [ySpeedMax=500] - The maximum y velocity the display object can reach.
+ * @return {number} The angle (in radians) that the object should be visually set to in order to match its new trajectory.
+ */
+ accelerateToXY: function (displayObject, x, y, speed, xSpeedMax, ySpeedMax) {
+
+ if (typeof speed === 'undefined') { speed = 60; }
+ if (typeof xSpeedMax === 'undefined') { xSpeedMax = 1000; }
+ if (typeof ySpeedMax === 'undefined') { ySpeedMax = 1000; }
+
+ this._angle = this.angleToXY(displayObject, x, y);
+
+ displayObject.body.acceleration.setTo(Math.cos(this._angle) * speed, Math.sin(this._angle) * speed);
+ displayObject.body.maxVelocity.setTo(xSpeedMax, ySpeedMax);
+
+ return this._angle;
+
+ },
+
+ /**
+ * Find the distance between two display objects (like Sprites).
+ *
+ * @method Phaser.Physics.Arcade#distanceBetween
+ * @param {any} source - The Display Object to test from.
+ * @param {any} target - The Display Object to test to.
+ * @return {number} The distance between the source and target objects.
+ */
+ distanceBetween: function (source, target) {
+
+ this._dx = source.x - target.x;
+ this._dy = source.y - target.y;
+
+ return Math.sqrt(this._dx * this._dx + this._dy * this._dy);
+
+ },
+
+ /**
+ * Find the distance between a display object (like a Sprite) and the given x/y coordinates.
+ * The calculation is made from the display objects x/y coordinate. This may be the top-left if its anchor hasn't been changed.
+ * If you need to calculate from the center of a display object instead use the method distanceBetweenCenters()
+ *
+ * @method Phaser.Physics.Arcade#distanceToXY
+ * @param {any} displayObject - The Display Object to test from.
+ * @param {number} x - The x coordinate to move towards.
+ * @param {number} y - The y coordinate to move towards.
+ * @return {number} The distance between the object and the x/y coordinates.
+ */
+ distanceToXY: function (displayObject, x, y) {
+
+ this._dx = displayObject.x - x;
+ this._dy = displayObject.y - y;
+
+ return Math.sqrt(this._dx * this._dx + this._dy * this._dy);
+
+ },
+
+ /**
+ * Find the distance between a display object (like a Sprite) and a Pointer. If no Pointer is given the Input.activePointer is used.
+ * The calculation is made from the display objects x/y coordinate. This may be the top-left if its anchor hasn't been changed.
+ * If you need to calculate from the center of a display object instead use the method distanceBetweenCenters()
+ *
+ * @method Phaser.Physics.Arcade#distanceToPointer
+ * @param {any} displayObject - The Display Object to test from.
+ * @param {Phaser.Pointer} [pointer] - The Phaser.Pointer to test to. If none is given then Input.activePointer is used.
+ * @return {number} The distance between the object and the Pointer.
+ */
+ distanceToPointer: function (displayObject, pointer) {
+
+ pointer = pointer || this.game.input.activePointer;
+
+ this._dx = displayObject.worldX - pointer.x;
+ this._dy = displayObject.worldY - pointer.y;
+
+ return Math.sqrt(this._dx * this._dx + this._dy * this._dy);
+
+ },
+
+ /**
+ * Find the angle in radians between two display objects (like Sprites).
+ *
+ * @method Phaser.Physics.Arcade#angleBetween
+ * @param {any} source - The Display Object to test from.
+ * @param {any} target - The Display Object to test to.
+ * @return {number} The angle in radians between the source and target display objects.
+ */
+ angleBetween: function (source, target) {
+
+ this._dx = target.x - source.x;
+ this._dy = target.y - source.y;
+
+ return Math.atan2(this._dy, this._dx);
+
+ },
+
+ /**
+ * Find the angle in radians between a display object (like a Sprite) and the given x/y coordinate.
+ *
+ * @method Phaser.Physics.Arcade#angleToXY
+ * @param {any} displayObject - The Display Object to test from.
+ * @param {number} x - The x coordinate to get the angle to.
+ * @param {number} y - The y coordinate to get the angle to.
+ * @return {number} The angle in radians between displayObject.x/y to Pointer.x/y
+ */
+ angleToXY: function (displayObject, x, y) {
+
+ this._dx = x - displayObject.x;
+ this._dy = y - displayObject.y;
+
+ return Math.atan2(this._dy, this._dx);
+
+ },
+
+ /**
+ * Find the angle in radians between a display object (like a Sprite) and a Pointer, taking their x/y and center into account.
+ *
+ * @method Phaser.Physics.Arcade#angleToPointer
+ * @param {any} displayObject - The Display Object to test from.
+ * @param {Phaser.Pointer} [pointer] - The Phaser.Pointer to test to. If none is given then Input.activePointer is used.
+ * @return {number} The angle in radians between displayObject.x/y to Pointer.x/y
+ */
+ angleToPointer: function (displayObject, pointer) {
+
+ pointer = pointer || this.game.input.activePointer;
+
+ this._dx = pointer.worldX - displayObject.x;
+ this._dy = pointer.worldY - displayObject.y;
+
+ return Math.atan2(this._dy, this._dx);
+
+ }
+
+};
+
/**
+* @author Richard Davey <rich@photonstorm.com>
+* @copyright 2013 Photon Storm Ltd.
+* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
+*/
+
+
+/**
+* Create a new <code>Button</code> object.
+* @class Phaser.Button
+* @constructor
+*
+* @param {Phaser.Game} game Current game instance.
+* @param {number} [x] X position of the button.
+* @param {number} [y] Y position of the button.
+* @param {string} [key] The image key as defined in the Game.Cache to use as the texture for this button.
+* @param {function} [callback] The function to call when this button is pressed
+* @param {object} [callbackContext] The context in which the callback will be called (usually 'this')
+* @param {string|number} [overFrame] This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name.
+* @param {string|number} [outFrame] This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name.
+* @param {string|number} [downFrame] This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name.
+*/
+Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) {
+
+ x = x || 0;
+ y = y || 0;
+ key = key || null;
+ callback = callback || null;
+ callbackContext = callbackContext || this;
+
+ Phaser.Sprite.call(this, game, x, y, key, outFrame);
+
+ /**
+ * @property {Description} type - Description.
+ */
+ this.type = Phaser.BUTTON;
+
+ /**
+ * @property {Description} _onOverFrameName - Description.
+ * @private
+ * @default
+ */
+ this._onOverFrameName = null;
+
+ /**
+ * @property {Description} _onOutFrameName - Description.
+ * @private
+ * @default
+ */
+ this._onOutFrameName = null;
+
+ /**
+ * @property {Description} _onDownFrameName - Description.
+ * @private
+ * @default
+ */
+ this._onDownFrameName = null;
+
+ /**
+ * @property {Description} _onUpFrameName - Description.
+ * @private
+ * @default
+ */
+ this._onUpFrameName = null;
+
+ /**
+ * @property {Description} _onOverFrameID - Description.
+ * @private
+ * @default
+ */
+ this._onOverFrameID = null;
+
+ /**
+ * @property {Description} _onOutFrameID - Description.
+ * @private
+ * @default
+ */
+ this._onOutFrameID = null;
+
+ /**
+ * @property {Description} _onDownFrameID - Description.
+ * @private
+ * @default
+ */
+ this._onDownFrameID = null;
+
+ /**
+ * @property {Description} _onUpFrameID - Description.
+ * @private
+ * @default
+ */
+ this._onUpFrameID = null;
+
+ // These are the signals the game will subscribe to
+ /**
+ * @property {Phaser.Signal} onInputOver - Description.
+ */
+ this.onInputOver = new Phaser.Signal;
+
+ /**
+ * @property {Phaser.Signal} onInputOut - Description.
+ */
+ this.onInputOut = new Phaser.Signal;
+
+ /**
+ * @property {Phaser.Signal} onInputDown - Description.
+ */
+ this.onInputDown = new Phaser.Signal;
+
+ /**
+ * @property {Phaser.Signal} onInputUp - Description.
+ */
+ this.onInputUp = new Phaser.Signal;
+
+ this.setFrames(overFrame, outFrame, downFrame);
+
+ if (callback !== null)
+ {
+ this.onInputUp.add(callback, callbackContext);
+ }
+
+ this.freezeFrames = false;
+
+ this.input.start(0, true);
+
+ // Redirect the input events to here so we can handle animation updates, etc
+ this.events.onInputOver.add(this.onInputOverHandler, this);
+ this.events.onInputOut.add(this.onInputOutHandler, this);
+ this.events.onInputDown.add(this.onInputDownHandler, this);
+ this.events.onInputUp.add(this.onInputUpHandler, this);
+
+};
+
+Phaser.Button.prototype = Phaser.Utils.extend(true, Phaser.Sprite.prototype, PIXI.Sprite.prototype);
+Phaser.Button.prototype.constructor = Phaser.Button;
+
+/**
+* Used to manually set the frames that will be used for the different states of the button
+* exactly like setting them in the constructor.
+*
+* @method Phaser.Button.prototype.setFrames
+* @param {string|number} [overFrame] - This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name.
+* @param {string|number} [outFrame] - This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name.
+* @param {string|number} [downFrame] - This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name.
+*/
+Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) {
+
+ if (overFrame !== null)
+ {
+ if (typeof overFrame === 'string')
+ {
+ this._onOverFrameName = overFrame;
+
+ if (this.input.pointerOver())
+ {
+ this.frameName = overFrame;
+ }
+ }
+ else
+ {
+ this._onOverFrameID = overFrame;
+
+ if (this.input.pointerOver())
+ {
+ this.frame = overFrame;
+ }
+ }
+ }
+
+ if (outFrame !== null)
+ {
+ if (typeof outFrame === 'string')
+ {
+ this._onOutFrameName = outFrame;
+ this._onUpFrameName = outFrame;
+
+ if (this.input.pointerOver() == false)
+ {
+ this.frameName = outFrame;
+ }
+ }
+ else
+ {
+ this._onOutFrameID = outFrame;
+ this._onUpFrameID = outFrame;
+
+ if (this.input.pointerOver() == false)
+ {
+ this.frame = outFrame;
+ }
+ }
+ }
+
+ if (downFrame !== null)
+ {
+ if (typeof downFrame === 'string')
+ {
+ this._onDownFrameName = downFrame;
+
+ if (this.input.pointerOver())
+ {
+ this.frameName = downFrame;
+ }
+ }
+ else
+ {
+ this._onDownFrameID = downFrame;
+
+ if (this.input.pointerOver())
+ {
+ this.frame = downFrame;
+ }
+ }
+ }
+
+};
+
+/**
+* Description.
+*
+* @method Phaser.Button.prototype.onInputOverHandler
+* @param {Description} pointer - Description.
+*/
+Phaser.Button.prototype.onInputOverHandler = function (pointer) {
+
+ if (this.freezeFrames == false)
+ {
+ if (this._onOverFrameName != null)
+ {
+ this.frameName = this._onOverFrameName;
+ }
+ else if (this._onOverFrameID != null)
+ {
+ this.frame = this._onOverFrameID;
+ }
+ }
+
+ if (this.onInputOver)
+ {
+ this.onInputOver.dispatch(this, pointer);
+ }
+};
+
+/**
+* Description.
+*
+* @method Phaser.Button.prototype.onInputOutHandler
+* @param {Description} pointer - Description.
+*/
+Phaser.Button.prototype.onInputOutHandler = function (pointer) {
+
+ if (this.freezeFrames == false)
+ {
+ if (this._onOutFrameName != null)
+ {
+ this.frameName = this._onOutFrameName;
+ }
+ else if (this._onOutFrameID != null)
+ {
+ this.frame = this._onOutFrameID;
+ }
+ }
+
+ if (this.onInputOut)
+ {
+ this.onInputOut.dispatch(this, pointer);
+ }
+};
+
+/**
+* Description.
+*
+* @method Phaser.Button.prototype.onInputDownHandler
+* @param {Description} pointer - Description.
+*/
+Phaser.Button.prototype.onInputDownHandler = function (pointer) {
+
+ if (this.freezeFrames == false)
+ {
+ if (this._onDownFrameName != null)
+ {
+ this.frameName = this._onDownFrameName;
+ }
+ else if (this._onDownFrameID != null)
+ {
+ this.frame = this._onDownFrameID;
+ }
+ }
+
+ if (this.onInputDown)
+ {
+ this.onInputDown.dispatch(this, pointer);
+ }
+};
+
+/**
+* Description.
+*
+* @method Phaser.Button.prototype.onInputUpHandler
+* @param {Description} pointer - Description.
+*/
+Phaser.Button.prototype.onInputUpHandler = function (pointer) {
+
+ if (this.freezeFrames == false)
+ {
+ if (this._onUpFrameName != null)
+ {
+ this.frameName = this._onUpFrameName;
+ }
+ else if (this._onUpFrameID != null)
+ {
+ this.frame = this._onUpFrameID;
+ }
+ }
+
+ if (this.onInputUp)
+ {
+ this.onInputUp.dispatch(this, pointer);
+ }
+};
+
/**
+* @author Richard Davey <rich@photonstorm.com>
+* @copyright 2013 Photon Storm Ltd.
+* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
+*/
+
+/**
+* Description.
+*
+* @class Phaser.GameObjectFactory
+* @constructor
+* @param {Phaser.Game} game - A reference to the currently running game.
+*/
+Phaser.GameObjectFactory = function (game) {
+
+ /**
+ * @property {Phaser.Game} game - A reference to the currently running Game.
+ */
+ this.game = game;
+
+ /**
+ * @property {Phaser.World} world - A reference to the game world.
+ */
+ this.world = this.game.world;
+
+};
+
+Phaser.GameObjectFactory.prototype = {
+
+ /**
+ * @property {Phaser.Game} game - A reference to the currently running Game.
+ * @default
+ */
+ game: null,
+
+ /**
+ * @property {Phaser.World} world - A reference to the game world.
+ * @default
+ */
+ world: null,
+
+ /**
+ * Description.
+ * @method existing.
+ * @param {*} object - An instance of Phaser.Sprite, Phaser.Button or any other display object..
+ * @return {*} The child that was added to the Group.
+ */
+ existing: function (object) {
+
+ return this.world.add(object);
+
+ },
+
+ /**
+ * Create a new Sprite with specific position and sprite sheet key.
+ *
+ * @method sprite
+ * @param {number} x - X position of the new sprite.
+ * @param {number} y - Y position of the new sprite.
+ * @param {string|Phaser.RenderTexture|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture.
+ * @param {string|number} [frame] - If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
+ * @returns {Phaser.Sprite} the newly created sprite object.
+ */
+ sprite: function (x, y, key, frame) {
+
+ return this.world.create(x, y, key, frame);
+
+ },
+
+ /**
+ * Create a new Sprite with specific position and sprite sheet key that will automatically be added as a child of the given parent.
+ *
+ * @method child
+ * @param {Phaser.Group} group - The Group to add this child to.
+ * @param {number} x - X position of the new sprite.
+ * @param {number} y - Y position of the new sprite.
+ * @param {string|RenderTexture} [key] - The image key as defined in the Game.Cache to use as the texture for this sprite OR a RenderTexture.
+ * @param {string|number} [frame] - If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
+ * @returns {Phaser.Sprite} the newly created sprite object.
+ */
+ child: function (group, x, y, key, frame) {
+
+ return group.create(x, y, key, frame);
+
+ },
+
+ /**
+ * Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite.
+ *
+ * @method tween
+ * @param {object} obj - Object the tween will be run on.
+ * @return {Phaser.Tween} Description.
+ */
+ tween: function (obj) {
+
+ return this.game.tweens.create(obj);
+
+ },
+
+ /**
+ * A Group is a container for display objects that allows for fast pooling, recycling and collision checks.
+ *
+ * @method group
+ * @param {*} parent - The parent Group or DisplayObjectContainer that will hold this group, if any.
+ * @param {string} [name=group] - A name for this Group. Not used internally but useful for debugging.
+ * @return {Phaser.Group} The newly created group.
+ */
+ group: function (parent, name) {
+
+ return new Phaser.Group(this.game, parent, name);
+
+ },
+
+ /**
+ * Creates a new instance of the Sound class.
+ *
+ * @method audio
+ * @param {string} key - The Game.cache key of the sound that this object will use.
+ * @param {number} volume - The volume at which the sound will be played.
+ * @param {boolean} loop - Whether or not the sound will loop.
+ * @return {Phaser.Sound} The newly created text object.
+ */
+ audio: function (key, volume, loop) {
+
+ return this.game.sound.add(key, volume, loop);
+
+ },
+
+ /**
+ * Creates a new <code>TileSprite</code>.
+ *
+ * @method tileSprite
+ * @param {number} x - X position of the new tileSprite.
+ * @param {number} y - Y position of the new tileSprite.
+ * @param {number} width - the width of the tilesprite.
+ * @param {number} height - the height of the tilesprite.
+ * @param {string|Phaser.RenderTexture|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture.
+ * @param {string|number} frame - If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
+ * @return {Phaser.TileSprite} The newly created tileSprite object.
+ */
+ tileSprite: function (x, y, width, height, key, frame) {
+
+ return this.world.add(new Phaser.TileSprite(this.game, x, y, width, height, key, frame));
+
+ },
+
+ /**
+ * Creates a new <code>Text</code>.
+ *
+ * @method text
+ * @param {number} x - X position of the new text object.
+ * @param {number} y - Y position of the new text object.
+ * @param {string} text - The actual text that will be written.
+ * @param {object} style - The style object containing style attributes like font, font size , etc.
+ * @return {Phaser.Text} The newly created text object.
+ */
+ text: function (x, y, text, style) {
+
+ return this.world.add(new Phaser.Text(this.game, x, y, text, style));
+
+ },
+
+ /**
+ * Creates a new <code>Button</code> object.
+ *
+ * @method button
+ * @param {number} [x] X position of the new button object.
+ * @param {number} [y] Y position of the new button object.
+ * @param {string} [key] The image key as defined in the Game.Cache to use as the texture for this button.
+ * @param {function} [callback] The function to call when this button is pressed
+ * @param {object} [callbackContext] The context in which the callback will be called (usually 'this')
+ * @param {string|number} [overFrame] This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name.
+ * @param {string|number} [outFrame] This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name.
+ * @param {string|number} [downFrame] This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name.
+ * @return {Phaser.Button} The newly created button object.
+ */
+ button: function (x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) {
+
+ return this.world.add(new Phaser.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame));
+
+ },
+
+ /**
+ * Creates a new <code>Graphics</code> object.
+ *
+ * @method graphics
+ * @param {number} x - X position of the new graphics object.
+ * @param {number} y - Y position of the new graphics object.
+ * @return {Phaser.Graphics} The newly created graphics object.
+ */
+ graphics: function (x, y) {
+
+ return this.world.add(new Phaser.Graphics(this.game, x, y));
+
+ },
+
+ /**
+ * Emitter is a lightweight particle emitter. It can be used for one-time explosions or for
+ * continuous effects like rain and fire. All it really does is launch Particle objects out
+ * at set intervals, and fixes their positions and velocities accorindgly.
+ *
+ * @method emitter
+ * @param {number} [x=0] - The x coordinate within the Emitter that the particles are emitted from.
+ * @param {number} [y=0] - The y coordinate within the Emitter that the particles are emitted from.
+ * @param {number} [maxParticles=50] - The total number of particles in this emitter.
+ * @return {Phaser.Emitter} The newly created emitter object.
+ */
+ emitter: function (x, y, maxParticles) {
+
+ return this.game.particles.add(new Phaser.Particles.Arcade.Emitter(this.game, x, y, maxParticles));
+
+ },
+
+ /**
+ * * Create a new <code>BitmapText</code>.
+ *
+ * @method bitmapText
+ * @param {number} x - X position of the new bitmapText object.
+ * @param {number} y - Y position of the new bitmapText object.
+ * @param {string} text - The actual text that will be written.
+ * @param {object} style - The style object containing style attributes like font, font size , etc.
+ * @return {Phaser.BitmapText} The newly created bitmapText object.
+ */
+ bitmapText: function (x, y, text, style) {
+
+ return this.world.add(new Phaser.BitmapText(this.game, x, y, text, style));
+
+ },
+
+ /**
+ * Description.
+ *
+ * @method tilemap
+ * @param {string} key - Asset key for the JSON file.
+ * @return {Phaser.Tilemap} The newly created tilemap object.
+ */
+ tilemap: function (key) {
+
+ return new Phaser.Tilemap(this.game, key);
+
+ },
+
+ /**
+ * Description.
+ *
+ * @method tileset
+ * @param {string} key - The image key as defined in the Game.Cache to use as the tileset.
+ * @return {Phaser.Tileset} The newly created tileset object.
+ */
+ tileset: function (key) {
+
+ return this.game.cache.getTileset(key);
+
+ },
+
+ /**
+ * Description.
+ *
+ * @method tilemaplayer
+ * @param {number} x - X position of the new tilemapLayer.
+ * @param {number} y - Y position of the new tilemapLayer.
+ * @param {number} width - the width of the tilemapLayer.
+ * @param {number} height - the height of the tilemapLayer.
+ * @return {Phaser.TilemapLayer} The newly created tilemaplayer object.
+ */
+ tilemapLayer: function (x, y, width, height, tileset, tilemap, layer) {
+
+ return this.world.add(new Phaser.TilemapLayer(this.game, x, y, width, height, tileset, tilemap, layer));
+
+ },
+
+ /**
+ * A dynamic initially blank canvas to which images can be drawn
+ *
+ * @method renderTexture
+ * @param {string} key - Asset key for the render texture.
+ * @param {number} width - the width of the render texture.
+ * @param {number} height - the height of the render texture.
+ * @return {Phaser.RenderTexture} The newly created renderTexture object.
+ */
+ renderTexture: function (key, width, height) {
+
+ var texture = new Phaser.RenderTexture(this.game, key, width, height);
+
+ this.game.cache.addRenderTexture(key, texture);
+
+ return texture;
+
+ },
+
+};
@@ -1936,7 +2056,7 @@ You could use this function to generate those by doing: Phaser.Animation.generat
-
min
+
start
@@ -1964,14 +2084,14 @@ You could use this function to generate those by doing: Phaser.Animation.generat
-
The number to start sequentially counting from. If your frames are named 'explosion_0001' to 'explosion_0034' the min is 1.
+
The number to start sequentially counting from. If your frames are named 'explosion_0001' to 'explosion_0034' the start is 1.
-
max
+
stop
@@ -1999,7 +2119,7 @@ You could use this function to generate those by doing: Phaser.Animation.generat
-
The number to count up to. If your frames are named 'explosion_0001' to 'explosion_0034' the max is 34.
+
The number to count to. If your frames are named 'explosion_0001' to 'explosion_0034' the stop value is 34.
@@ -2814,8 +2934,8 @@ You could use this function to generate those by doing: Phaser.Animation.generat
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:51:58 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:43 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.AnimationManager.html b/docs/Phaser.AnimationManager.html
index cc33f1bc..4c73a71f 100644
--- a/docs/Phaser.AnimationManager.html
+++ b/docs/Phaser.AnimationManager.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -387,7 +507,7 @@ Any Game Object such as Phaser.Sprite that supports animation contains a single
-Phaser.Sprite
+Phaser.Sprite
@@ -1340,7 +1460,7 @@ Any Game Object such as Phaser.Sprite that supports animation contains a single
-Phaser.Sprite
+Phaser.Sprite
@@ -2723,8 +2843,8 @@ The currentAnim property of the AnimationManager is automatically set to the ani
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:51:58 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:43 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.AnimationParser.html b/docs/Phaser.AnimationParser.html
index 4e3a2f84..878830e1 100644
--- a/docs/Phaser.AnimationParser.html
+++ b/docs/Phaser.AnimationParser.html
@@ -54,6 +54,18 @@
AnimationParser
+
Warning: Bullet is an experimental object that we don't advise using for now.
+
A Bullet is like a stripped-down Sprite, useful for when you just need to get something moving around the screen quickly with little of the extra
+features that a Sprite supports.
+Bullet is MISSING the following:
+
animation, all input events, crop support, health/damage, loadTexture
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.
+
+
+
+
+
+
+
frame
+
+
+
+
+
+string
+|
+
+number
+
+
+
+
+
+
+
+
+
+
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.
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
Indicates the rotation of the Bullet, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation.
+Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement player.angle = 450 is the same as player.angle = 90.
+If you wish to work in radians instead of degrees use the property Bullet.rotation instead.
+
+
+
+
+
+
+
+
+
+
Properties:
+
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
+
+
+
Description
+
+
+
+
+
+
+
+
+
angle
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
Gets or sets the Bullets angle of rotation in degrees.
Should this Sprite be automatically culled if out of range of the camera?
+A culled sprite has its visible property set to 'false'.
+Note that this check doesn't look at this Sprites children, which may still be in camera range.
+So you should set autoCull to false if the Sprite will have children likely to still be in camera range.
A Sprite that is fixed to the camera ignores the position of any ancestors in the display list and uses its x/y coordinates as offsets from the top left of the camera.
If you would like the Sprite to have a lifespan once 'born' you can set this to a positive value. Handy for particles, bullets, etc.
+The lifespan is decremented by game.time.elapsed each update, once it reaches zero the kill() function is called.
The image key as defined in the Game.Cache to use as the texture for this button.
+
+
+
+
+
+
+
callback
+
+
+
+
+
+function
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
The function to call when this button is pressed
+
+
+
+
+
+
+
callbackContext
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
The context in which the callback will be called (usually 'this')
+
+
+
+
+
+
+
overFrame
+
+
+
+
+
+string
+|
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name.
+
+
+
+
+
+
+
outFrame
+
+
+
+
+
+string
+|
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name.
+
+
+
+
+
+
+
downFrame
+
+
+
+
+
+string
+|
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name.
Used to manually set the frames that will be used for the different states of the button
+exactly like setting them in the constructor.
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
Argument
+
+
+
+
+
Description
+
+
+
+
+
+
+
+
+
overFrame
+
+
+
+
+
+string
+|
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name.
+
+
+
+
+
+
+
outFrame
+
+
+
+
+
+string
+|
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name.
+
+
+
+
+
+
+
downFrame
+
+
+
+
+
+string
+|
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name.
@@ -6813,8 +6933,8 @@ Normally you don't call this directly but instead use getImageKeys, getSoundKeys
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:51:59 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:44 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.Camera.html b/docs/Phaser.Camera.html
index af7ae150..95529a37 100644
--- a/docs/Phaser.Camera.html
+++ b/docs/Phaser.Camera.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -1600,7 +1720,7 @@ at all then set this to null. The values can be anything and are in World coordi
-Phaser.Sprite
+Phaser.Sprite
@@ -2678,7 +2798,7 @@ Objects outside of this view are not rendered (unless set to ignore the Camera,
-Phaser.Sprite
+Phaser.Sprite
@@ -3163,8 +3283,8 @@ without having to use game.camera.x and game.camera.y.
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:51:59 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:44 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.Canvas.html b/docs/Phaser.Canvas.html
index 14daba08..5647d0c4 100644
--- a/docs/Phaser.Canvas.html
+++ b/docs/Phaser.Canvas.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -2407,8 +2527,8 @@ patchy on earlier browsers, especially on mobile.
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:51:59 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:44 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.Circle.html b/docs/Phaser.Circle.html
index 46e4a9eb..148f1751 100644
--- a/docs/Phaser.Circle.html
+++ b/docs/Phaser.Circle.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -4187,8 +4307,8 @@ This method checks the radius distances between the two Circle objects to see if
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:51:59 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:44 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.Color.html b/docs/Phaser.Color.html
index 484476f6..203cf9cb 100644
--- a/docs/Phaser.Color.html
+++ b/docs/Phaser.Color.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -3516,8 +3636,8 @@ RGB format information and HSL information. Each section starts on a newline, 3
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:51:59 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:44 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.Device.html b/docs/Phaser.Device.html
index f3bf6fd1..a4b79bfc 100644
--- a/docs/Phaser.Device.html
+++ b/docs/Phaser.Device.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -1800,8 +1920,8 @@ The frames are returned in the output array, or if none is provided in a new Arr
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:00 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:45 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.Game.html b/docs/Phaser.Game.html
index 704bea9a..b752b0b1 100644
--- a/docs/Phaser.Game.html
+++ b/docs/Phaser.Game.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -659,7 +779,7 @@ providing quick access to common functions and handling the boot process.
-Phaser.GameObjectFactory
+Phaser.GameObjectFactory
@@ -2581,7 +2701,7 @@ When a game is paused the onPause event is dispatched. When it is resumed the on
@@ -4374,8 +4494,8 @@ When a game is paused the onPause event is dispatched. When it is resumed the on
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:00 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:46 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.GameObjectFactory.html b/docs/Phaser.GameObjectFactory.html
new file mode 100644
index 00000000..b1fe49a3
--- /dev/null
+++ b/docs/Phaser.GameObjectFactory.html
@@ -0,0 +1,1078 @@
+
+
+
+
+
+ Phaser Class: GameObjectFactory
+
+
+
+
+
+
+
+
+
+
+
@@ -6880,8 +7000,8 @@ Group.subAll('x', 10) will minus 10 from the child.x value.
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:00 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:46 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.Input.html b/docs/Phaser.Input.html
index 8b99dbb3..94af83fb 100644
--- a/docs/Phaser.Input.html
+++ b/docs/Phaser.Input.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -7472,8 +7333,8 @@ If you need more then use this to create a new one, up to a maximum of 10.
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:01 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:46 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.InputHandler.html b/docs/Phaser.InputHandler.html
index d69deb50..d5b0ccdd 100644
--- a/docs/Phaser.InputHandler.html
+++ b/docs/Phaser.InputHandler.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -7388,8 +7508,8 @@ This value is only set when the pointer is over this Sprite.
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:01 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:46 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.Key.html b/docs/Phaser.Key.html
index 564ecb42..9535d426 100644
--- a/docs/Phaser.Key.html
+++ b/docs/Phaser.Key.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -2435,8 +2555,8 @@ If the key is up it holds the duration of the previous down session.
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:01 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:46 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.Keyboard.html b/docs/Phaser.Keyboard.html
index ab37d5cd..52fba980 100644
--- a/docs/Phaser.Keyboard.html
+++ b/docs/Phaser.Keyboard.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -2862,8 +2982,8 @@ This is called automatically by Phaser.Input and should not normally be invoked
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:01 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:46 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.LinkedList.html b/docs/Phaser.LinkedList.html
index c67232b5..81eb6ad1 100644
--- a/docs/Phaser.LinkedList.html
+++ b/docs/Phaser.LinkedList.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -1354,8 +1474,8 @@ The function must exist on the member.
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:01 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:46 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.Loader.html b/docs/Phaser.Loader.html
index 000cf34b..eec2d3f3 100644
--- a/docs/Phaser.Loader.html
+++ b/docs/Phaser.Loader.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -5824,8 +5944,8 @@ This allows you to easily make loading bars for games.
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:01 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:47 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.LoaderParser.html b/docs/Phaser.LoaderParser.html
index ec747435..5ca3d17b 100644
--- a/docs/Phaser.LoaderParser.html
+++ b/docs/Phaser.LoaderParser.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -1619,8 +1739,8 @@ It will work only in Internet Explorer 10 and Windows Store or Windows Phone 8 a
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:02 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:47 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.Math.html b/docs/Phaser.Math.html
index 499a808e..afd434de 100644
--- a/docs/Phaser.Math.html
+++ b/docs/Phaser.Math.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -10085,8 +10205,8 @@ Should be called whenever the angle is updated on the Sprite to stop it from goi
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:01 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:47 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.Mouse.html b/docs/Phaser.Mouse.html
index 1527a2b5..bb7eac36 100644
--- a/docs/Phaser.Mouse.html
+++ b/docs/Phaser.Mouse.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -1244,8 +1364,8 @@ Optionally you can redirect to the new url, or just return it as a string.
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:02 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:47 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.Particles.Arcade.Emitter.html b/docs/Phaser.Particles.Arcade.Emitter.html
index 4851dc76..f024f524 100644
--- a/docs/Phaser.Particles.Arcade.Emitter.html
+++ b/docs/Phaser.Particles.Arcade.Emitter.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -11111,8 +11231,8 @@ Group.subAll('x', 10) will minus 10 from the child.x value.
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:02 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:47 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.Particles.html b/docs/Phaser.Particles.html
index bbe241c6..b84e1ee9 100644
--- a/docs/Phaser.Particles.html
+++ b/docs/Phaser.Particles.html
@@ -54,6 +54,18 @@
AnimationParser
+
Sets the acceleration.x/y property on the display object so it will move towards the target at the given speed (in pixels per second sq.)
+You must give a maximum speed value, beyond which the display object won't go any faster.
+Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course.
+Note: The display object doesn't stop moving once it reaches the destination coordinates.
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
Argument
+
+
+
+
Default
+
+
+
Description
+
+
+
+
+
+
+
+
+
displayObject
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
The display object to move.
+
+
+
+
+
+
+
destination
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
The display object to move towards. Can be any object but must have visible x/y properties.
+
+
+
+
+
+
+
speed
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
+ 60
+
+
+
+
+
The speed it will accelerate in pixels per second.
+
+
+
+
+
+
+
xSpeedMax
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
+ 500
+
+
+
+
+
The maximum x velocity the display object can reach.
+
+
+
+
+
+
+
ySpeedMax
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
+ 500
+
+
+
+
+
The maximum y velocity the display object can reach.
Sets the acceleration.x/y property on the display object so it will move towards the target at the given speed (in pixels per second sq.)
+You must give a maximum speed value, beyond which the display object won't go any faster.
+Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course.
+Note: The display object doesn't stop moving once it reaches the destination coordinates.
The angle (in radians) that the object should be visually set to in order to match its new trajectory.
+
+
+
+
+
+
+ Type
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
accelerateToXY(displayObject, x, y, speed, xSpeedMax, ySpeedMax) → {number}
+
+
+
+
+
+
+
+
Sets the acceleration.x/y property on the display object so it will move towards the x/y coordinates at the given speed (in pixels per second sq.)
+You must give a maximum speed value, beyond which the display object won't go any faster.
+Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course.
+Note: The display object doesn't stop moving once it reaches the destination coordinates.
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
Argument
+
+
+
+
Default
+
+
+
Description
+
+
+
+
+
+
+
+
+
displayObject
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
The display object to move.
+
+
+
+
+
+
+
x
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
The x coordinate to accelerate towards.
+
+
+
+
+
+
+
y
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
The y coordinate to accelerate towards.
+
+
+
+
+
+
+
speed
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
+ 60
+
+
+
+
+
The speed it will accelerate in pixels per second.
+
+
+
+
+
+
+
xSpeedMax
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
+ 500
+
+
+
+
+
The maximum x velocity the display object can reach.
+
+
+
+
+
+
+
ySpeedMax
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
+ 500
+
+
+
+
+
The maximum y velocity the display object can reach.
Given the rotation (in radians) and speed calculate the acceleration and return it as a Point object, or set it to the given point object.
+One way to use this is: velocityFromRotation(rotation, 200, sprite.velocity) which will set the values directly to the sprites velocity and not create a new Point object.
Checks for collision between two game objects. The objects can be Sprites, Groups, Emitters or Tilemaps.
+You can perform Sprite vs. Sprite, Sprite vs. Group, Group vs. Group, Sprite vs. Tilemap or Group vs. Tilemap collisions.
+The objects are also automatically separated.
The second object to check. Can be an instance of Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter or Phaser.Tilemap
+
+
+
+
+
+
+
collideCallback
+
+
+
+
+
+function
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
+ null
+
+
+
+
+
An optional callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap.
+
+
+
+
+
+
+
processCallback
+
+
+
+
+
+function
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
+ null
+
+
+
+
+
A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then collideCallback will only be called if processCallback returns true.
Find the distance between a display object (like a Sprite) and a Pointer. If no Pointer is given the Input.activePointer is used.
+The calculation is made from the display objects x/y coordinate. This may be the top-left if its anchor hasn't been changed.
+If you need to calculate from the center of a display object instead use the method distanceBetweenCenters()
Find the distance between a display object (like a Sprite) and the given x/y coordinates.
+The calculation is made from the display objects x/y coordinate. This may be the top-left if its anchor hasn't been changed.
+If you need to calculate from the center of a display object instead use the method distanceBetweenCenters()
Move the given display object towards the destination object at a steady velocity.
+If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds.
+Timings are approximate due to the way browser timers work. Allow for a variance of +- 50ms.
+Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course.
+Note: The display object doesn't stop moving once it reaches the destination coordinates.
+Note: Doesn't take into account acceleration, maxVelocity or drag (if you've set drag or acceleration too high this object may not move at all)
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
Argument
+
+
+
+
Default
+
+
+
Description
+
+
+
+
+
+
+
+
+
displayObject
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
The display object to move.
+
+
+
+
+
+
+
destination
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
The display object to move towards. Can be any object but must have visible x/y properties.
+
+
+
+
+
+
+
speed
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
+ 60
+
+
+
+
+
The speed it will move, in pixels per second (default is 60 pixels/sec)
+
+
+
+
+
+
+
maxTime
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the object will arrive at destination in the given number of ms.
Move the given display object towards the pointer at a steady velocity. If no pointer is given it will use Phaser.Input.activePointer.
+If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds.
+Timings are approximate due to the way browser timers work. Allow for a variance of +- 50ms.
+Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course.
+Note: The display object doesn't stop moving once it reaches the destination coordinates.
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
Argument
+
+
+
+
Default
+
+
+
Description
+
+
+
+
+
+
+
+
+
displayObject
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
The display object to move.
+
+
+
+
+
+
+
speed
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
+ 60
+
+
+
+
+
The speed it will move, in pixels per second (default is 60 pixels/sec)
The angle (in radians) that the object should be visually set to in order to match its new velocity.
+
+
+
+
+
+
+ Type
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
moveToXY(displayObject, x, y, speed, maxTime) → {number}
+
+
+
+
+
+
+
+
Move the given display object towards the x/y coordinates at a steady velocity.
+If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds.
+Timings are approximate due to the way browser timers work. Allow for a variance of +- 50ms.
+Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course.
+Note: The display object doesn't stop moving once it reaches the destination coordinates.
+Note: Doesn't take into account acceleration, maxVelocity or drag (if you've set drag or acceleration too high this object may not move at all)
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
Argument
+
+
+
+
Default
+
+
+
Description
+
+
+
+
+
+
+
+
+
displayObject
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
The display object to move.
+
+
+
+
+
+
+
x
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
The x coordinate to move towards.
+
+
+
+
+
+
+
y
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
The y coordinate to move towards.
+
+
+
+
+
+
+
speed
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
+ 60
+
+
+
+
+
The speed it will move, in pixels per second (default is 60 pixels/sec)
+
+
+
+
+
+
+
maxTime
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the object will arrive at destination in the given number of ms.
Given the angle (in degrees) and speed calculate the velocity and return it as a Point object, or set it to the given point object.
+One way to use this is: velocityFromAngle(angle, 200, sprite.velocity) which will set the values directly to the sprites velocity and not create a new Point object.
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
Argument
+
+
+
+
Default
+
+
+
Description
+
+
+
+
+
+
+
+
+
angle
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
The angle in degrees calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative)
Given the rotation (in radians) and speed calculate the velocity and return it as a Point object, or set it to the given point object.
+One way to use this is: velocityFromRotation(rotation, 200, sprite.velocity) which will set the values directly to the sprites velocity and not create a new Point object.
@@ -1706,8 +1826,8 @@ It is only called if active is set to true.
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:02 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:48 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.PluginManager.html b/docs/Phaser.PluginManager.html
index f6c39dea..a4886e8d 100644
--- a/docs/Phaser.PluginManager.html
+++ b/docs/Phaser.PluginManager.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -1336,8 +1456,8 @@ It only calls plugins who have active=true.
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:02 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:48 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.Point.html b/docs/Phaser.Point.html
index 12cb2824..4ef47585 100644
--- a/docs/Phaser.Point.html
+++ b/docs/Phaser.Point.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -1205,8 +1325,8 @@ Split the node into 4 subnodes
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:02 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:48 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.RandomDataGenerator.html b/docs/Phaser.RandomDataGenerator.html
index ff2e4bdc..c893b200 100644
--- a/docs/Phaser.RandomDataGenerator.html
+++ b/docs/Phaser.RandomDataGenerator.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -1898,8 +2018,8 @@ Random number generator from
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:03 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:48 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.Rectangle.html b/docs/Phaser.Rectangle.html
index 7f14f162..f7c069a4 100644
--- a/docs/Phaser.Rectangle.html
+++ b/docs/Phaser.Rectangle.html
@@ -54,6 +54,18 @@
AnimationParser
+
I know this has a typo in it, but it's because the PIXI.RenderTexture does and we need to pair-up with it
+once they update pixi to fix the typo, we'll fix it here too :)
@@ -5417,8 +5746,8 @@ This allows you to bundle multiple sounds together into a single audio file and
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:03 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:48 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.SoundManager.html b/docs/Phaser.SoundManager.html
index 475e87b7..dedced84 100644
--- a/docs/Phaser.SoundManager.html
+++ b/docs/Phaser.SoundManager.html
@@ -54,6 +54,18 @@
AnimationParser
+
Create a new Sprite object. Sprites are the lifeblood of your game, used for nearly everything visual.
+At its most basic a Sprite consists of a set of coordinates and a texture that is rendered to the canvas.
+They also contain additional properties allowing for physics motion (via Sprite.body), input handling (via Sprite.input),
+events (via Sprite.events), animation (via Sprite.animations), camera culling and more. Please see the Examples for use cases.
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.
+
+
+
+
+
+
+
frame
+
+
+
+
+
+string
+|
+
+number
+
+
+
+
+
+
+
+
+
+
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.
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
Indicates the rotation of the Sprite, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation.
+Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement player.angle = 450 is the same as player.angle = 90.
+If you wish to work in radians instead of degrees use the property Sprite.rotation instead.
+
+
+
+
+
+
+
+
+
+
Properties:
+
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
+
+
+
Description
+
+
+
+
+
+
+
+
+
angle
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
Gets or sets the Sprites angle of rotation in degrees.
By default Sprites have a Phaser.Physics Body attached to them. You can operate physics actions via this property, or null it to skip all physics updates.
This Rectangle object fully encompasses the Sprite and is updated in real-time.
+The bounds is the full bounding area after rotation and scale have been taken into account. It should not be modified directly.
+It's used for Camera culling and physics body alignment.
You can crop the Sprites texture by modifying the crop properties. For example crop.width = 50 would set the Sprite to only render 50px wide.
+The crop is only applied if you have set Sprite.cropEnabled to true.
A Sprite that is fixed to the camera ignores the position of any ancestors in the display list and uses its x/y coordinates as offsets from the top left of the camera.
The height of the sprite in pixels, setting this will actually modify the scale to acheive the value desired.
+If you wish to crop the Sprite instead see the Sprite.crop value.
By default a Sprite won't process any input events at all. By setting inputEnabled to true the Phaser.InputHandler is
+activated for this Sprite instance and it will then start to process click/touch events and more.
+
+
+
+
+
+
+
+
+
+
Properties:
+
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
+
+
+
Description
+
+
+
+
+
+
+
+
+
inputEnabled
+
+
+
+
+
+boolean
+
+
+
+
+
+
+
+
+
+
Set to true to allow this Sprite to receive input events, otherwise false.
A threshold value applied to the inWorld check. If you don't want a Sprite to be considered "out of the world" until at least 100px away for example then set it to 100.
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.
If you would like the Sprite to have a lifespan once 'born' you can set this to a positive value. Handy for particles, bullets, etc.
+The lifespan is decremented by game.time.elapsed each update, once it reaches zero the kill() function is called.
+
+
+
+
+
+
+
+
+
+
Properties:
+
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
+
+
+
Description
+
+
+
+
+
+
+
+
+
lifespan
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
The lifespan of the Sprite (in ms) before it will be killed.
The scale of the Sprite 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.
The width of the sprite in pixels, setting this will actually modify the scale to acheive the value desired.
+If you wish to crop the Sprite instead see the Sprite.crop value.
Brings the Sprite to the top of the display list it is a child of. Sprites that are members of a Phaser.Group are only
+bought to the top of that Group, not the entire display list.
Destroys the Sprite. This removes it from its parent group, destroys the input, event and animation handlers if present
+and nulls its reference to game, freeing it up for garbage collection.
Gets the local unmodified position of a coordinate relative to the Sprite, factoring in rotation and scale.
+Mostly only used internally by the Input Manager, but also useful for custom hit detection.
Kills a Sprite. A killed Sprite has its alive, exists and visible properties all set to false.
+It will dispatch the onKilled event, you can listen to Sprite.events.onKilled for the signal.
+Note that killing a Sprite is a way for you to quickly recycle it in a Sprite pool, it doesn't free it up from memory.
+If you don't need this Sprite any more you should call Sprite.destroy instead.
Changes the Texture the Sprite is using entirely. The old texture is removed and the new one is referenced or fetched from the Cache.
+This causes a WebGL texture update, so use sparingly or in low-intensity portions of your game.
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.
+
+
+
+
+
+
+
frame
+
+
+
+
+
+string
+|
+
+number
+
+
+
+
+
+
+
+
+
+
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.
Play an animation based on the given key. The animation should previously have been added via sprite.animations.add()
+If the requested animation is already playing this request will be ignored. If you need to reset an already running animation do so directly on the Animation object itself.
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
Argument
+
+
+
+
Default
+
+
+
Description
+
+
+
+
+
+
+
+
+
name
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
The name of the animation to be played, e.g. "fire", "walk", "jump".
+
+
+
+
+
+
+
frameRate
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
+ null
+
+
+
+
+
The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used.
+
+
+
+
+
+
+
loop
+
+
+
+
+
+boolean
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
+ false
+
+
+
+
+
Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
+
+
+
+
+
+
+
killOnComplete
+
+
+
+
+
+boolean
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
+ false
+
+
+
+
+
If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed.
Resets the Sprite. This places the Sprite at the given x/y world coordinates and then
+sets alive, exists, visible and renderable all to true. Also resets the outOfBounds state and health values.
+If the Sprite has a physics body that too is reset.
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
Argument
+
+
+
+
Default
+
+
+
Description
+
+
+
+
+
+
+
+
+
x
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
The x coordinate (in world space) to position the Sprite at.
+
+
+
+
+
+
+
y
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
The y coordinate (in world space) to position the Sprite at.
Brings a 'dead' Sprite back to life, optionally giving it the health value specified.
+A resurrected Sprite has its alive, exists and visible properties all set to true.
+It will dispatch the onRevived event, you can listen to Sprite.events.onRevived for the signal.
@@ -1382,8 +1679,8 @@ focus handling, game resizing, scaling and the pause, boot and orientation scree
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:03 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:49 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.StageScaleMode.html b/docs/Phaser.StageScaleMode.html
index afb56453..12f9e211 100644
--- a/docs/Phaser.StageScaleMode.html
+++ b/docs/Phaser.StageScaleMode.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -3719,8 +3839,8 @@ Please note that this needs to be supported by the web browser and isn't the sam
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:03 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:49 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.State.html b/docs/Phaser.State.html
index 44b1f3a4..40cf1e4c 100644
--- a/docs/Phaser.State.html
+++ b/docs/Phaser.State.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -469,7 +589,7 @@ It provides quick access to common functions such as the camera, cache, input, m
-Phaser.GameObjectFactory
+Phaser.GameObjectFactory
@@ -2473,8 +2593,8 @@ If you need to use the loader, you may need to use them here.
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:03 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:49 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.StateManager.html b/docs/Phaser.StateManager.html
index 95db2d55..c85cda32 100644
--- a/docs/Phaser.StateManager.html
+++ b/docs/Phaser.StateManager.html
@@ -54,6 +54,18 @@
AnimationParser
+
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.
+
+
+
+
+
+
+
frame
+
+
+
+
+
+string
+|
+
+number
+
+
+
+
+
+
+
+
+
+
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.
@@ -2445,8 +2565,8 @@ Doesn't appear to be supported by most browsers on a canvas element yet.
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:04 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:49 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.Tween.html b/docs/Phaser.Tween.html
index 43e8bc3b..2bb08d08 100644
--- a/docs/Phaser.Tween.html
+++ b/docs/Phaser.Tween.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -3151,8 +3271,8 @@ Used in combination with repeat you can create endless loops.
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:04 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:49 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.TweenManager.html b/docs/Phaser.TweenManager.html
index 19e57da6..ee5fce9b 100644
--- a/docs/Phaser.TweenManager.html
+++ b/docs/Phaser.TweenManager.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -5860,8 +5980,8 @@ your game set to use Phaser.AUTO then swap it for Phaser.CANVAS to ensure WebGL
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:04 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:50 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.Utils.html b/docs/Phaser.Utils.html
index 29af7947..218c7314 100644
--- a/docs/Phaser.Utils.html
+++ b/docs/Phaser.Utils.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -1994,8 +2114,8 @@ If you need to adjust the bounds of the world
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:52:04 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:50 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Phaser.html b/docs/Phaser.html
index 61ee9adf..e0e7fa60 100644
--- a/docs/Phaser.html
+++ b/docs/Phaser.html
@@ -54,6 +54,18 @@
AnimationParser
+
@@ -330,10 +450,10 @@
/**
* @namespace Phaser
*/
-var Phaser = Phaser || {
+var Phaser = Phaser || {
- VERSION: '1.1.0',
- GAMES: [],
+ VERSION: '<%= version %>',
+ GAMES: [],
AUTO: 0,
CANVAS: 1,
WEBGL: 2,
@@ -362,7 +482,8 @@ var Phaser = Phaser || {
PIXI.InteractionManager = function (dummy) {
// We don't need this in Pixi, so we've removed it to save space
// however the Stage object expects a reference to it, so here is a dummy entry.
-};
+};
+
@@ -382,8 +503,8 @@ PIXI.InteractionManager = function (dummy) {
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:51:58 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:43 GMT+0100 (BST) using the DocStrap template.
diff --git a/docs/Plugin.js.html b/docs/Plugin.js.html
index d781cc54..5fae9c1c 100644
--- a/docs/Plugin.js.html
+++ b/docs/Plugin.js.html
@@ -54,6 +54,18 @@
AnimationParser
+
/**
+* @author Richard Davey <rich@photonstorm.com>
+* @copyright 2013 Photon Storm Ltd.
+* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
+*/
+
+/**
+* Create a new `Sprite` object. Sprites are the lifeblood of your game, used for nearly everything visual.
+* At its most basic a Sprite consists of a set of coordinates and a texture that is rendered to the canvas.
+* They also contain additional properties allowing for physics motion (via Sprite.body), input handling (via Sprite.input),
+* events (via Sprite.events), animation (via Sprite.animations), camera culling and more. Please see the Examples for use cases.
+*
+* @class Phaser.Sprite
+* @constructor
+* @param {Phaser.Game} game - A reference to the currently running game.
+* @param {number} x - The x coordinate (in world space) to position the Sprite at.
+* @param {number} y - The y coordinate (in world space) to position the Sprite at.
+* @param {string|Phaser.RenderTexture|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture.
+* @param {string|number} frame - If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
+*/
+Phaser.Sprite = function (game, x, y, key, frame) {
+
+ x = x || 0;
+ y = y || 0;
+ key = key || null;
+ frame = frame || null;
+
+ /**
+ * @property {Phaser.Game} game - A reference to the currently running Game.
+ */
+ this.game = game;
+
+ /**
+ * @property {boolean} exists - If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all.
+ * @default
+ */
+ 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.
+ * @default
+ */
+ this.alive = true;
+
+ /**
+ * @property {Phaser.Group} group - The parent Group of this Sprite. This is usually set after Sprite instantiation by the parent.
+ */
+ this.group = null;
+
+ /**
+ * @property {string} name - The user defined name given to this Sprite.
+ * @default
+ */
+ this.name = '';
+
+ /**
+ * @property {number} type - The const type of this object.
+ * @default
+ */
+ this.type = Phaser.SPRITE;
+
+ /**
+ * @property {number} renderOrderID - Used by the Renderer and Input Manager to control picking order.
+ * @default
+ */
+ this.renderOrderID = -1;
+
+ /**
+ * If you would like the Sprite to have a lifespan once 'born' you can set this to a positive value. Handy for particles, bullets, etc.
+ * The lifespan is decremented by game.time.elapsed each update, once it reaches zero the kill() function is called.
+ * @property {number} lifespan - The lifespan of the Sprite (in ms) before it will be killed.
+ * @default
+ */
+ this.lifespan = 0;
+
+ /**
+ * @property {Events} events - The Events you can subscribe to that are dispatched when certain things happen on this Sprite or its components.
+ */
+ this.events = new Phaser.Events(this);
+
+ /**
+ * @property {Phaser.AnimationManager} animations - This manages animations of the sprite. You can modify animations through it (see Phaser.AnimationManager)
+ */
+ this.animations = new Phaser.AnimationManager(this);
+
+ /**
+ * @property {InputHandler} input - The Input Handler Component.
+ */
+ this.input = new Phaser.InputHandler(this);
+
+ /**
+ * @property {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.
+ */
+ this.key = key;
+
+ /**
+ * @property {Phaser.Frame} currentFrame - A reference to the currently displayed frame.
+ */
+ this.currentFrame = null;
+
+ if (key instanceof Phaser.RenderTexture)
+ {
+ PIXI.Sprite.call(this, key);
+
+ this.currentFrame = this.game.cache.getTextureFrame(key.name);
+ }
+ else if (key instanceof PIXI.Texture)
+ {
+ PIXI.Sprite.call(this, key);
+
+ this.currentFrame = frame;
+ }
+ else
+ {
+ if (key == null || this.game.cache.checkImageKey(key) == false)
+ {
+ key = '__default';
+ this.key = key;
+ }
+
+ PIXI.Sprite.call(this, PIXI.TextureCache[key]);
+
+ if (this.game.cache.isSpriteSheet(key))
+ {
+ this.animations.loadFrameData(this.game.cache.getFrameData(key));
+
+ if (frame !== null)
+ {
+ if (typeof frame === 'string')
+ {
+ this.frameName = frame;
+ }
+ else
+ {
+ this.frame = frame;
+ }
+ }
+ }
+ else
+ {
+ this.currentFrame = this.game.cache.getFrame(key);
+ }
+ }
+
+ /**
+ * 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 with Sprite rotation and scaling takes place.
+ */
+ this.anchor = new Phaser.Point();
+
+ /**
+ * @property {number} x - The x coordinate (in world space) of this Sprite.
+ */
+ this.x = x;
+
+ /**
+ * @property {number} y - The y coordinate (in world space) of this Sprite.
+ */
+ this.y = y;
+
+ this.position.x = x;
+ this.position.y = y;
+
+ /**
+ * Should this Sprite be automatically culled if out of range of the camera?
+ * A culled sprite has its renderable property set to 'false'.
+ *
+ * @property {boolean} autoCull - A flag indicating if the Sprite should be automatically camera culled or not.
+ * @default
+ */
+ this.autoCull = false;
+
+ /**
+ * @property {Phaser.Point} scale - The scale of the Sprite 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);
+
+ /**
+ * @property {Phaser.Point} _cache - A mini cache for storing all of the calculated values.
+ * @private
+ */
+ this._cache = {
+
+ dirty: false,
+
+ // Transform cache
+ a00: -1, a01: -1, a02: -1, a10: -1, a11: -1, a12: -1, id: -1,
+
+ // Input specific transform cache
+ i01: -1, i10: -1, idi: -1,
+
+ // Bounds check
+ left: null, right: null, top: null, bottom: null,
+
+ // The previous calculated position
+ x: -1, y: -1,
+
+ // The actual scale values based on the worldTransform
+ scaleX: 1, scaleY: 1,
+
+ // cache scale check
+ realScaleX: 1, realScaleY: 1,
+
+ // The width/height of the image, based on the un-modified frame size multiplied by the final calculated scale size
+ width: this.currentFrame.sourceSizeW, height: this.currentFrame.sourceSizeH,
+
+ // The actual width/height of the image if from a trimmed atlas, multiplied by the final calculated scale size
+ halfWidth: Math.floor(this.currentFrame.sourceSizeW / 2), halfHeight: Math.floor(this.currentFrame.sourceSizeH / 2),
+
+ // The width/height of the image, based on the un-modified frame size multiplied by the final calculated scale size
+ calcWidth: -1, calcHeight: -1,
+
+ // The current frame details
+ // frameID: this.currentFrame.uuid, frameWidth: this.currentFrame.width, frameHeight: this.currentFrame.height,
+ frameID: -1, frameWidth: this.currentFrame.width, frameHeight: this.currentFrame.height,
+
+ boundsX: 0, boundsY: 0,
+
+ // If this sprite visible to the camera (regardless of being set to visible or not)
+ cameraVisible: true,
+
+ // Crop cache
+ cropX: 0, cropY: 0, cropWidth: this.currentFrame.sourceSizeW, cropHeight: this.currentFrame.sourceSizeH
+
+ };
+
+ /**
+ * @property {Phaser.Point} offset - Corner point defaults. Should not typically be modified.
+ */
+ this.offset = new Phaser.Point;
+
+ /**
+ * @property {Phaser.Point} center - A Point containing the center coordinate of the Sprite. Takes rotation and scale into account.
+ */
+ this.center = new Phaser.Point(x + Math.floor(this._cache.width / 2), y + Math.floor(this._cache.height / 2));
+
+ /**
+ * @property {Phaser.Point} topLeft - A Point containing the top left coordinate of the Sprite. Takes rotation and scale into account.
+ */
+ this.topLeft = new Phaser.Point(x, y);
+
+ /**
+ * @property {Phaser.Point} topRight - A Point containing the top right coordinate of the Sprite. Takes rotation and scale into account.
+ */
+ this.topRight = new Phaser.Point(x + this._cache.width, y);
+
+ /**
+ * @property {Phaser.Point} bottomRight - A Point containing the bottom right coordinate of the Sprite. Takes rotation and scale into account.
+ */
+ this.bottomRight = new Phaser.Point(x + this._cache.width, y + this._cache.height);
+
+ /**
+ * @property {Phaser.Point} bottomLeft - A Point containing the bottom left coordinate of the Sprite. Takes rotation and scale into account.
+ */
+ this.bottomLeft = new Phaser.Point(x, y + this._cache.height);
+
+ /**
+ * This Rectangle object fully encompasses the Sprite and is updated in real-time.
+ * The bounds is the full bounding area after rotation and scale have been taken into account. It should not be modified directly.
+ * It's used for Camera culling and physics body alignment.
+ * @property {Phaser.Rectangle} bounds
+ */
+ this.bounds = new Phaser.Rectangle(x, y, this._cache.width, this._cache.height);
+
+ /**
+ * @property {Phaser.Physics.Arcade.Body} body - By default Sprites have a Phaser.Physics Body attached to them. You can operate physics actions via this property, or null it to skip all physics updates.
+ */
+ this.body = new Phaser.Physics.Arcade.Body(this);
+
+ /**
+ * @property {number} health - Health value. Used in combination with damage() to allow for quick killing of Sprites.
+ */
+ this.health = 1;
+
+ /**
+ * @property {boolean} inWorld - This value is set to true if the Sprite is positioned within the World, otherwise false.
+ */
+ this.inWorld = Phaser.Rectangle.intersects(this.bounds, this.game.world.bounds);
+
+ /**
+ * @property {number} inWorldThreshold - A threshold value applied to the inWorld check. If you don't want a Sprite to be considered "out of the world" until at least 100px away for example then set it to 100.
+ * @default
+ */
+ this.inWorldThreshold = 0;
+
+ /**
+ * @property {boolean} outOfBoundsKill - If true the Sprite is killed as soon as Sprite.inWorld is false.
+ * @default
+ */
+ this.outOfBoundsKill = false;
+
+ /**
+ * @property {boolean} _outOfBoundsFired - Internal flag.
+ * @private
+ * @default
+ */
+ this._outOfBoundsFired = false;
+
+ /**
+ * A Sprite that is fixed to the camera ignores the position of any ancestors in the display list and uses its x/y coordinates as offsets from the top left of the camera.
+ * @property {boolean} fixedToCamera - Fixes this Sprite to the Camera.
+ * @default
+ */
+ this.fixedToCamera = false;
+
+ /**
+ * You can crop the Sprites texture by modifying the crop properties. For example crop.width = 50 would set the Sprite to only render 50px wide.
+ * The crop is only applied if you have set Sprite.cropEnabled to true.
+ * @property {Phaser.Rectangle} crop - The crop Rectangle applied to the Sprite texture before rendering.
+ * @default
+ */
+ this.crop = new Phaser.Rectangle(0, 0, this._cache.width, this._cache.height);
+
+ /**
+ * @property {boolean} cropEnabled - If true the Sprite.crop property is used to crop the texture before render. Set to false to disable.
+ * @default
+ */
+ this.cropEnabled = false;
+
+};
+
+// Needed to keep the PIXI.Sprite constructor in the prototype chain (as the core pixi renderer uses an instanceof check sadly)
+Phaser.Sprite.prototype = Object.create(PIXI.Sprite.prototype);
+Phaser.Sprite.prototype.constructor = Phaser.Sprite;
+
+/**
+* Automatically called by World.preUpdate. Handles cache updates, lifespan checks, animation updates and physics updates.
+*
+* @method Phaser.Sprite#preUpdate
+* @memberof Phaser.Sprite
+*/
+Phaser.Sprite.prototype.preUpdate = function() {
+
+ if (!this.exists)
+ {
+ this.renderOrderID = -1;
+ return;
+ }
+
+ if (this.lifespan > 0)
+ {
+ this.lifespan -= this.game.time.elapsed;
+
+ if (this.lifespan <= 0)
+ {
+ this.kill();
+ return;
+ }
+ }
+
+ this._cache.dirty = false;
+
+ if (this.animations.update())
+ {
+ this._cache.dirty = true;
+ }
+
+ if (this.visible)
+ {
+ this.renderOrderID = this.game.world.currentRenderOrderID++;
+ }
+
+ this.prevX = this.x;
+ this.prevY = this.y;
+
+ this.updateCache();
+ this.updateAnimation();
+
+ if (this.cropEnabled)
+ {
+ this.updateCrop();
+ }
+
+ // Re-run the camera visibility check
+ if (this._cache.dirty)
+ {
+ this.updateBounds();
+
+ this._cache.cameraVisible = Phaser.Rectangle.intersects(this.game.world.camera.screenView, this.bounds, 0);
+
+ if (this.autoCull == true)
+ {
+ // Won't get rendered but will still get its transform updated
+ this.renderable = this._cache.cameraVisible;
+ }
+
+ // Update our physics bounds
+ if (this.body)
+ {
+ this.body.updateBounds(this.center.x, this.center.y, this._cache.scaleX, this._cache.scaleY);
+ }
+ }
+
+ if (this.body)
+ {
+ this.body.preUpdate();
+ }
+
+}
+
+/**
+* Internal function called by preUpdate.
+*
+* @method Phaser.Sprite#updateCache
+* @memberof Phaser.Sprite
+*/
+Phaser.Sprite.prototype.updateCache = function() {
+
+ // |a c tx|
+ // |b d ty|
+ // |0 0 1|
+
+ if (this.worldTransform[1] != this._cache.i01 || this.worldTransform[3] != this._cache.i10)
+ {
+ this._cache.a00 = this.worldTransform[0]; // scaleX a
+ this._cache.a01 = this.worldTransform[1]; // skewY c
+ this._cache.a10 = this.worldTransform[3]; // skewX b
+ this._cache.a11 = this.worldTransform[4]; // scaleY d
+
+ this._cache.i01 = this.worldTransform[1]; // skewY c (remains non-modified for input checks)
+ this._cache.i10 = this.worldTransform[3]; // skewX b (remains non-modified for input checks)
+
+ this._cache.scaleX = Math.sqrt((this._cache.a00 * this._cache.a00) + (this._cache.a01 * this._cache.a01)); // round this off a bit?
+ this._cache.scaleY = Math.sqrt((this._cache.a10 * this._cache.a10) + (this._cache.a11 * this._cache.a11)); // round this off a bit?
+
+ this._cache.a01 *= -1;
+ this._cache.a10 *= -1;
+
+ this._cache.dirty = true;
+ }
+
+ if (this.worldTransform[2] != this._cache.a02 || this.worldTransform[5] != this._cache.a12)
+ {
+ this._cache.a02 = this.worldTransform[2]; // translateX tx
+ this._cache.a12 = this.worldTransform[5]; // translateY ty
+ this._cache.dirty = true;
+ }
+
+}
+
+/**
+* Internal function called by preUpdate.
+*
+* @method Phaser.Sprite#updateAnimation
+* @memberof Phaser.Sprite
+*/
+Phaser.Sprite.prototype.updateAnimation = function() {
+
+ if (this.currentFrame && this.currentFrame.uuid != this._cache.frameID)
+ {
+ this._cache.frameWidth = this.texture.frame.width;
+ this._cache.frameHeight = this.texture.frame.height;
+ this._cache.frameID = this.currentFrame.uuid;
+ this._cache.dirty = true;
+ }
+
+ if (this._cache.dirty && this.currentFrame)
+ {
+ this._cache.width = this.currentFrame.width;
+ this._cache.height = this.currentFrame.height;
+ this._cache.halfWidth = Math.floor(this._cache.width / 2);
+ this._cache.halfHeight = Math.floor(this._cache.height / 2);
+
+ this._cache.id = 1 / (this._cache.a00 * this._cache.a11 + this._cache.a01 * -this._cache.a10);
+ this._cache.idi = 1 / (this._cache.a00 * this._cache.a11 + this._cache.i01 * -this._cache.i10);
+ }
+
+}
+
+/**
+* Internal function called by preUpdate.
+*
+* @method Phaser.Sprite#updateBounds
+* @memberof Phaser.Sprite
+*/
+Phaser.Sprite.prototype.updateBounds = function() {
+
+ var sx = 1;
+ var sy = 1;
+
+ if (this.worldTransform[3] !== 0 || this.worldTransform[1] !== 0)
+ {
+ sx = this.scale.x;
+ sy = this.scale.y;
+ }
+
+ this.offset.setTo(this._cache.a02 - (this.anchor.x * this.width), this._cache.a12 - (this.anchor.y * this.height));
+
+ this.getLocalPosition(this.center, this.offset.x + (this.width / 2), this.offset.y + (this.height / 2), sx, sy);
+ this.getLocalPosition(this.topLeft, this.offset.x, this.offset.y, sx, sy);
+ this.getLocalPosition(this.topRight, this.offset.x + this.width, this.offset.y, sx, sy);
+ this.getLocalPosition(this.bottomLeft, this.offset.x, this.offset.y + this.height, sx, sy);
+ this.getLocalPosition(this.bottomRight, this.offset.x + this.width, this.offset.y + this.height, sx, sy);
+
+ this._cache.left = Phaser.Math.min(this.topLeft.x, this.topRight.x, this.bottomLeft.x, this.bottomRight.x);
+ this._cache.right = Phaser.Math.max(this.topLeft.x, this.topRight.x, this.bottomLeft.x, this.bottomRight.x);
+ this._cache.top = Phaser.Math.min(this.topLeft.y, this.topRight.y, this.bottomLeft.y, this.bottomRight.y);
+ this._cache.bottom = Phaser.Math.max(this.topLeft.y, this.topRight.y, this.bottomLeft.y, this.bottomRight.y);
+
+ this.bounds.setTo(this._cache.left, this._cache.top, this._cache.right - this._cache.left, this._cache.bottom - this._cache.top);
+
+ // This is the coordinate the Sprite was at when the last bounds was created
+ this._cache.boundsX = this._cache.x;
+ this._cache.boundsY = this._cache.y;
+
+ this.updateFrame = true;
+
+ if (this.inWorld == false)
+ {
+ // Sprite WAS out of the screen, is it still?
+ this.inWorld = Phaser.Rectangle.intersects(this.bounds, this.game.world.bounds, this.inWorldThreshold);
+
+ if (this.inWorld)
+ {
+ // It's back again, reset the OOB check
+ this._outOfBoundsFired = false;
+ }
+ }
+ else
+ {
+ // Sprite WAS in the screen, has it now left?
+ this.inWorld = Phaser.Rectangle.intersects(this.bounds, this.game.world.bounds, this.inWorldThreshold);
+
+ if (this.inWorld == false)
+ {
+ this.events.onOutOfBounds.dispatch(this);
+ this._outOfBoundsFired = true;
+
+ if (this.outOfBoundsKill)
+ {
+ this.kill();
+ }
+ }
+ }
+
+}
+
+/**
+* Gets the local position of a coordinate relative to the Sprite, factoring in rotation and scale.
+* Mostly only used internally.
+*
+* @method Phaser.Sprite#getLocalPosition
+* @memberof Phaser.Sprite
+* @param {Phaser.Point} p - The Point object to store the results in.
+* @param {number} x - x coordinate within the Sprite to translate.
+* @param {number} y - x coordinate within the Sprite to translate.
+* @param {number} sx - Scale factor to be applied.
+* @param {number} sy - Scale factor to be applied.
+* @return {Phaser.Point} The translated point.
+*/
+Phaser.Sprite.prototype.getLocalPosition = function(p, x, y, sx, sy) {
+
+ p.x = ((this._cache.a11 * this._cache.id * x + -this._cache.a01 * this._cache.id * y + (this._cache.a12 * this._cache.a01 - this._cache.a02 * this._cache.a11) * this._cache.id) * sx) + this._cache.a02;
+ p.y = ((this._cache.a00 * this._cache.id * y + -this._cache.a10 * this._cache.id * x + (-this._cache.a12 * this._cache.a00 + this._cache.a02 * this._cache.a10) * this._cache.id) * sy) + this._cache.a12;
+
+ return p;
+
+}
+
+/**
+* Gets the local unmodified position of a coordinate relative to the Sprite, factoring in rotation and scale.
+* Mostly only used internally by the Input Manager, but also useful for custom hit detection.
+*
+* @method Phaser.Sprite#getLocalUnmodifiedPosition
+* @memberof Phaser.Sprite
+* @param {Phaser.Point} p - The Point object to store the results in.
+* @param {number} x - x coordinate within the Sprite to translate.
+* @param {number} y - x coordinate within the Sprite to translate.
+* @return {Phaser.Point} The translated point.
+*/
+Phaser.Sprite.prototype.getLocalUnmodifiedPosition = function(p, gx, gy) {
+
+ var a00 = this.worldTransform[0], a01 = this.worldTransform[1], a02 = this.worldTransform[2],
+ a10 = this.worldTransform[3], a11 = this.worldTransform[4], a12 = this.worldTransform[5],
+ id = 1 / (a00 * a11 + a01 * -a10),
+ x = a11 * id * gx + -a01 * id * gy + (a12 * a01 - a02 * a11) * id,
+ y = a00 * id * gy + -a10 * id * gx + (-a12 * a00 + a02 * a10) * id;
+
+ p.x = x + (this.anchor.x * this._cache.width);
+ p.y = y + (this.anchor.y * this._cache.height);
+
+ return p;
+
+}
+
+/**
+* Internal function called by preUpdate.
+*
+* @method Phaser.Sprite#updateCrop
+* @memberof Phaser.Sprite
+*/
+Phaser.Sprite.prototype.updateCrop = function() {
+
+ // This only runs if crop is enabled
+ if (this.crop.width != this._cache.cropWidth || this.crop.height != this._cache.cropHeight || this.crop.x != this._cache.cropX || this.crop.y != this._cache.cropY)
+ {
+ this.crop.floorAll();
+
+ this._cache.cropX = this.crop.x;
+ this._cache.cropY = this.crop.y;
+ this._cache.cropWidth = this.crop.width;
+ this._cache.cropHeight = this.crop.height;
+
+ this.texture.frame = this.crop;
+ this.texture.width = this.crop.width;
+ this.texture.height = this.crop.height;
+
+ this.texture.updateFrame = true;
+
+ PIXI.Texture.frameUpdates.push(this.texture);
+ }
+
+}
+
+/**
+* Resets the Sprite.crop value back to the frame dimensions.
+*
+* @method Phaser.Sprite#resetCrop
+* @memberof Phaser.Sprite
+*/
+Phaser.Sprite.prototype.resetCrop = function() {
+
+ this.crop = new Phaser.Rectangle(0, 0, this._cache.width, this._cache.height);
+ this.texture.setFrame(this.crop);
+ this.cropEnabled = false;
+
+}
+
+/**
+* Internal function called by the World postUpdate cycle.
+*
+* @method Phaser.Sprite#postUpdate
+* @memberof Phaser.Sprite
+*/
+Phaser.Sprite.prototype.postUpdate = function() {
+
+ if (this.exists)
+ {
+ // The sprite is positioned in this call, after taking into consideration motion updates and collision
+ if (this.body)
+ {
+ this.body.postUpdate();
+ }
+
+ if (this.fixedToCamera)
+ {
+ this._cache.x = this.game.camera.view.x + this.x;
+ this._cache.y = this.game.camera.view.y + this.y;
+ }
+ else
+ {
+ this._cache.x = this.x;
+ this._cache.y = this.y;
+ }
+
+ if (this.position.x != this._cache.x || this.position.y != this._cache.y)
+ {
+ this.position.x = this._cache.x;
+ this.position.y = this._cache.y;
+ }
+ }
+
+}
+
+/**
+* Changes the Texture the Sprite is using entirely. The old texture is removed and the new one is referenced or fetched from the Cache.
+* This causes a WebGL texture update, so use sparingly or in low-intensity portions of your game.
+*
+* @method Phaser.Sprite#loadTexture
+* @memberof Phaser.Sprite
+* @param {string|Phaser.RenderTexture|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture.
+* @param {string|number} frame - If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
+*/
+Phaser.Sprite.prototype.loadTexture = function (key, frame) {
+
+ this.key = key;
+
+ if (key instanceof Phaser.RenderTexture)
+ {
+ this.currentFrame = this.game.cache.getTextureFrame(key.name);
+ }
+ else if (key instanceof PIXI.Texture)
+ {
+ this.currentFrame = frame;
+ }
+ else
+ {
+ if (typeof key === 'undefined' || this.game.cache.checkImageKey(key) === false)
+ {
+ key = '__default';
+ this.key = key;
+ }
+
+ if (this.game.cache.isSpriteSheet(key))
+ {
+ this.animations.loadFrameData(this.game.cache.getFrameData(key));
+
+ if (typeof frame !== 'undefined')
+ {
+ if (typeof frame === 'string')
+ {
+ this.frameName = frame;
+ }
+ else
+ {
+ this.frame = frame;
+ }
+ }
+ }
+ else
+ {
+ this.currentFrame = this.game.cache.getFrame(key);
+ this.setTexture(PIXI.TextureCache[key]);
+ }
+ }
+
+}
+
+/**
+* Returns the absolute delta x value.
+*
+* @method Phaser.Sprite#deltaAbsX
+* @memberof Phaser.Sprite
+* @return {number} The absolute delta value.
+*/
+Phaser.Sprite.prototype.deltaAbsX = function () {
+ return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX());
+}
+
+/**
+* Returns the absolute delta y value.
+*
+* @method Phaser.Sprite#deltaAbsY
+* @memberof Phaser.Sprite
+* @return {number} The absolute delta value.
+*/
+Phaser.Sprite.prototype.deltaAbsY = function () {
+ return (this.deltaY() > 0 ? this.deltaY() : -this.deltaY());
+}
+
+/**
+* Returns the delta x value.
+*
+* @method Phaser.Sprite#deltaX
+* @memberof Phaser.Sprite
+* @return {number} The delta value.
+*/
+Phaser.Sprite.prototype.deltaX = function () {
+ return this.x - this.prevX;
+}
+
+/**
+* Returns the delta y value.
+*
+* @method Phaser.Sprite#deltaY
+* @memberof Phaser.Sprite
+* @return {number} The delta value.
+*/
+Phaser.Sprite.prototype.deltaY = function () {
+ return this.y - this.prevY;
+}
+
+/**
+* Moves the sprite so its center is located on the given x and y coordinates.
+* Doesn't change the anchor point of the sprite.
+*
+* @method Phaser.Sprite#centerOn
+* @memberof Phaser.Sprite
+* @param {number} x - The x coordinate (in world space) to position the Sprite at.
+* @param {number} y - The y coordinate (in world space) to position the Sprite at.
+* @return (Phaser.Sprite) This instance.
+*/
+Phaser.Sprite.prototype.centerOn = function(x, y) {
+
+ this.x = x + (this.x - this.center.x);
+ this.y = y + (this.y - this.center.y);
+ return this;
+
+}
+
+/**
+* Brings a 'dead' Sprite back to life, optionally giving it the health value specified.
+* A resurrected Sprite has its alive, exists and visible properties all set to true.
+* It will dispatch the onRevived event, you can listen to Sprite.events.onRevived for the signal.
+*
+* @method Phaser.Sprite#revive
+* @memberof Phaser.Sprite
+* @param {number} [health=1] - The health to give the Sprite.
+* @return (Phaser.Sprite) This instance.
+*/
+Phaser.Sprite.prototype.revive = function(health) {
+
+ if (typeof health === 'undefined') { health = 1; }
+
+ this.alive = true;
+ this.exists = true;
+ this.visible = true;
+ this.health = health;
+
+ if (this.events)
+ {
+ this.events.onRevived.dispatch(this);
+ }
+
+ return this;
+
+}
+
+/**
+* Kills a Sprite. A killed Sprite has its alive, exists and visible properties all set to false.
+* It will dispatch the onKilled event, you can listen to Sprite.events.onKilled for the signal.
+* Note that killing a Sprite is a way for you to quickly recycle it in a Sprite pool, it doesn't free it up from memory.
+* If you don't need this Sprite any more you should call Sprite.destroy instead.
+*
+* @method Phaser.Sprite#kill
+* @memberof Phaser.Sprite
+* @return (Phaser.Sprite) This instance.
+*/
+Phaser.Sprite.prototype.kill = function() {
+
+ this.alive = false;
+ this.exists = false;
+ this.visible = false;
+
+ if (this.events)
+ {
+ this.events.onKilled.dispatch(this);
+ }
+
+ return this;
+
+}
+
+/**
+* Destroys the Sprite. This removes it from its parent group, destroys the input, event and animation handlers if present
+* and nulls its reference to game, freeing it up for garbage collection.
+*
+* @method Phaser.Sprite#destroy
+* @memberof Phaser.Sprite
+*/
+Phaser.Sprite.prototype.destroy = function() {
+
+ if (this.group)
+ {
+ this.group.remove(this);
+ }
+
+ if (this.input)
+ {
+ this.input.destroy();
+ }
+
+ if (this.events)
+ {
+ this.events.destroy();
+ }
+
+ if (this.animations)
+ {
+ this.animations.destroy();
+ }
+
+ this.alive = false;
+ this.exists = false;
+ this.visible = false;
+
+ this.game = null;
+
+}
+
+/**
+* Damages the Sprite, this removes the given amount from the Sprites health property.
+* If health is then taken below zero Sprite.kill is called.
+*
+* @method Phaser.Sprite#damage
+* @memberof Phaser.Sprite
+* @param {number} amount - The amount to subtract from the Sprite.health value.
+* @return (Phaser.Sprite) This instance.
+*/
+Phaser.Sprite.prototype.damage = function(amount) {
+
+ if (this.alive)
+ {
+ this.health -= amount;
+
+ if (this.health < 0)
+ {
+ this.kill();
+ }
+ }
+
+ return this;
+
+}
+
+/**
+* Resets the Sprite. This places the Sprite at the given x/y world coordinates and then
+* sets alive, exists, visible and renderable all to true. Also resets the outOfBounds state and health values.
+* If the Sprite has a physics body that too is reset.
+*
+* @method Phaser.Sprite#reset
+* @memberof Phaser.Sprite
+* @param {number} x - The x coordinate (in world space) to position the Sprite at.
+* @param {number} y - The y coordinate (in world space) to position the Sprite at.
+* @param {number} [health=1] - The health to give the Sprite.
+* @return (Phaser.Sprite) This instance.
+*/
+Phaser.Sprite.prototype.reset = function(x, y, health) {
+
+ if (typeof health === 'undefined') { health = 1; }
+
+ this.x = x;
+ this.y = y;
+ this.position.x = this.x;
+ this.position.y = this.y;
+ this.alive = true;
+ this.exists = true;
+ this.visible = true;
+ this.renderable = true;
+ this._outOfBoundsFired = false;
+
+ this.health = health;
+
+ if (this.body)
+ {
+ this.body.reset();
+ }
+
+ return this;
+
+}
+
+/**
+* Brings the Sprite to the top of the display list it is a child of. Sprites that are members of a Phaser.Group are only
+* bought to the top of that Group, not the entire display list.
+*
+* @method Phaser.Sprite#bringToTop
+* @memberof Phaser.Sprite
+* @return (Phaser.Sprite) This instance.
+*/
+Phaser.Sprite.prototype.bringToTop = function() {
+
+ if (this.group)
+ {
+ this.group.bringToTop(this);
+ }
+ else
+ {
+ this.game.world.bringToTop(this);
+ }
+
+ return this;
+
+}
+
+/**
+* Play an animation based on the given key. The animation should previously have been added via sprite.animations.add()
+* If the requested animation is already playing this request will be ignored. If you need to reset an already running animation do so directly on the Animation object itself.
+*
+* @method Phaser.Sprite#play
+* @memberof Phaser.Sprite
+* @param {string} name - The name of the animation to be played, e.g. "fire", "walk", "jump".
+* @param {number} [frameRate=null] - The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used.
+* @param {boolean} [loop=false] - Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
+* @param {boolean} [killOnComplete=false] - If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed.
+* @return {Phaser.Animation} A reference to playing Animation instance.
+*/
+Phaser.Sprite.prototype.play = function (name, frameRate, loop, killOnComplete) {
+
+ if (this.animations)
+ {
+ return this.animations.play(name, frameRate, loop, killOnComplete);
+ }
+
+}
+
+/**
+* Indicates the rotation of the Sprite, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation.
+* Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement player.angle = 450 is the same as player.angle = 90.
+* If you wish to work in radians instead of degrees use the property Sprite.rotation instead.
+* @name Phaser.Sprite#angle
+* @property {number} angle - Gets or sets the Sprites angle of rotation in degrees.
+*/
+Object.defineProperty(Phaser.Sprite.prototype, 'angle', {
+
+ get: function() {
+ return Phaser.Math.wrapAngle(Phaser.Math.radToDeg(this.rotation));
+ },
+
+ set: function(value) {
+ this.rotation = Phaser.Math.degToRad(Phaser.Math.wrapAngle(value));
+ }
+
+});
+
+/**
+* @name Phaser.Sprite#frame
+* @property {number} frame - Gets or sets the current frame index and updates the Texture Cache for display.
+*/
+Object.defineProperty(Phaser.Sprite.prototype, "frame", {
+
+ get: function () {
+ return this.animations.frame;
+ },
+
+ set: function (value) {
+ this.animations.frame = value;
+ }
+
+});
+
+/**
+* @name Phaser.Sprite#frameName
+* @property {string} frameName - Gets or sets the current frame name and updates the Texture Cache for display.
+*/
+Object.defineProperty(Phaser.Sprite.prototype, "frameName", {
+
+ get: function () {
+ return this.animations.frameName;
+ },
+
+ set: function (value) {
+ this.animations.frameName = value;
+ }
+
+});
+
+/**
+* @name Phaser.Sprite#inCamera
+* @property {boolean} inCamera - Is this sprite visible to the camera or not?
+* @readonly
+*/
+Object.defineProperty(Phaser.Sprite.prototype, "inCamera", {
+
+ get: function () {
+ return this._cache.cameraVisible;
+ }
+
+});
+
+/**
+* The width of the sprite in pixels, setting this will actually modify the scale to acheive the value desired.
+* If you wish to crop the Sprite instead see the Sprite.crop value.
+*
+* @name Phaser.Sprite#width
+* @property {number} width - The width of the Sprite in pixels.
+*/
+Object.defineProperty(Phaser.Sprite.prototype, 'width', {
+
+ get: function() {
+ return this.scale.x * this.currentFrame.width;
+ },
+
+ set: function(value) {
+
+ this.scale.x = value / this.currentFrame.width;
+ this._cache.scaleX = value / this.currentFrame.width;
+ this._width = value;
+
+ }
+
+});
+
+/**
+* The height of the sprite in pixels, setting this will actually modify the scale to acheive the value desired.
+* If you wish to crop the Sprite instead see the Sprite.crop value.
+*
+* @name Phaser.Sprite#height
+* @property {number} height - The height of the Sprite in pixels.
+*/
+Object.defineProperty(Phaser.Sprite.prototype, 'height', {
+
+ get: function() {
+ return this.scale.y * this.currentFrame.height;
+ },
+
+ set: function(value) {
+
+ this.scale.y = value / this.currentFrame.height;
+ this._cache.scaleY = value / this.currentFrame.height;
+ this._height = value;
+
+ }
+
+});
+
+/**
+* By default a Sprite won't process any input events at all. By setting inputEnabled to true the Phaser.InputHandler is
+* activated for this Sprite instance and it will then start to process click/touch events and more.
+*
+* @name Phaser.Sprite#inputEnabled
+* @property {boolean} inputEnabled - Set to true to allow this Sprite to receive input events, otherwise false.
+*/
+Object.defineProperty(Phaser.Sprite.prototype, "inputEnabled", {
+
+ get: function () {
+
+ return (this.input.enabled);
+
+ },
+
+ set: function (value) {
+
+ if (value)
+ {
+ if (this.input.enabled == false)
+ {
+ this.input.start();
+ }
+ }
+ else
+ {
+ if (this.input.enabled)
+ {
+ this.input.stop();
+ }
+ }
+
+ }
+
+});
+
/**
+* @author Richard Davey <rich@photonstorm.com>
+* @copyright 2013 Photon Storm Ltd.
+* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
+*/
+
+/**
+* Create a new <code>TileSprite</code>.
+* @class Phaser.Tilemap
+* @constructor
+* @param {Phaser.Game} game - Current game instance.
+* @param {number} x - X position of the new tileSprite.
+* @param {number} y - Y position of the new tileSprite.
+* @param {number} width - the width of the tilesprite.
+* @param {number} height - the height of the tilesprite.
+* @param {string|Phaser.RenderTexture|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture.
+* @param {string|number} frame - If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
+*/
+Phaser.TileSprite = function (game, x, y, width, height, key, frame) {
+
+ x = x || 0;
+ y = y || 0;
+ width = width || 256;
+ height = height || 256;
+ key = key || null;
+ frame = frame || null;
+
+ Phaser.Sprite.call(this, game, x, y, key, frame);
+
+ /**
+ * @property {Description} texture - Description.
+ */
+ this.texture = PIXI.TextureCache[key];
+
+ PIXI.TilingSprite.call(this, this.texture, width, height);
+
+ /**
+ * @property {Description} type - Description.
+ */
+ this.type = Phaser.TILESPRITE;
+
+ /**
+ * @property {Point} tileScale - The scaling of the image that is being tiled.
+ */
+ this.tileScale = new Phaser.Point(1, 1);
+
+ /**
+ * @property {Point} tilePosition - The offset position of the image that is being tiled.
+ */
+ this.tilePosition = new Phaser.Point(0, 0);
+
+};
+
+Phaser.TileSprite.prototype = Phaser.Utils.extend(true, PIXI.TilingSprite.prototype, Phaser.Sprite.prototype);
+Phaser.TileSprite.prototype.constructor = Phaser.TileSprite;
+
+// Add our own custom methods
+
The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
button(x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) → {Phaser.Button}
+
+
+
+
+
+
+
+
Creates a new <code>Button</code> object.
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
Argument
+
+
+
+
+
Description
+
+
+
+
+
+
+
+
+
x
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
X position of the new button object.
+
+
+
+
+
+
+
y
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
Y position of the new button object.
+
+
+
+
+
+
+
key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
The image key as defined in the Game.Cache to use as the texture for this button.
+
+
+
+
+
+
+
callback
+
+
+
+
+
+function
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
The function to call when this button is pressed
+
+
+
+
+
+
+
callbackContext
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
The context in which the callback will be called (usually 'this')
+
+
+
+
+
+
+
overFrame
+
+
+
+
+
+string
+|
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name.
+
+
+
+
+
+
+
outFrame
+
+
+
+
+
+string
+|
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name.
+
+
+
+
+
+
+
downFrame
+
+
+
+
+
+string
+|
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name.
The image key as defined in the Game.Cache to use as the texture for this sprite OR a RenderTexture.
+
+
+
+
+
+
+
frame
+
+
+
+
+
+string
+|
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
Emitter is a lightweight particle emitter. It can be used for one-time explosions or for
+continuous effects like rain and fire. All it really does is launch Particle objects out
+at set intervals, and fixes their positions and velocities accorindgly.
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
Argument
+
+
+
+
Default
+
+
+
Description
+
+
+
+
+
+
+
+
+
x
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
The x coordinate within the Emitter that the particles are emitted from.
+
+
+
+
+
+
+
y
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
The y coordinate within the Emitter that the particles are emitted from.
The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
+However it does affect the width property.
The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
+However it does affect the width property.
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.
+
+
+
+
+
+
+
frame
+
+
+
+
+
+string
+|
+
+number
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
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.
+
+
+
+
+
+
+
frame
+
+
+
+
+
+string
+|
+
+number
+
+
+
+
+
+
+
+
+
+
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.
A feature-packed 2D HTML5 game framework born from the smouldering pits of Flixel and
constructed via plenty of blood, sweat, tears and coffee by Richard Davey (@photonstorm).
@@ -452,8 +572,8 @@ and my love of game development originate.
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:51:58 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:43 GMT+0100 (BST) using the DocStrap template.
@@ -598,8 +754,8 @@
- Documentation generated by JSDoc 3.2.0-dev
- on Wed Oct 23 2013 13:51:58 GMT+0100 (BST) using the DocStrap template.
+ Documentation generated by JSDoc 3.3.0-dev
+ on Fri Oct 25 2013 16:16:43 GMT+0100 (BST) using the DocStrap template.
diff --git a/src/gameobjects/Bullet.js b/src/gameobjects/Bullet.js
index d5a491d7..4da6912e 100644
--- a/src/gameobjects/Bullet.js
+++ b/src/gameobjects/Bullet.js
@@ -5,7 +5,7 @@
*/
/**
-* Create a new Bullet.
+* Warning: Bullet is an experimental object that we don't advise using for now.
*
* A Bullet is like a stripped-down Sprite, useful for when you just need to get something moving around the screen quickly with little of the extra
* features that a Sprite supports.
diff --git a/src/gameobjects/Sprite.js b/src/gameobjects/Sprite.js
index b83ddffe..3384cb73 100644
--- a/src/gameobjects/Sprite.js
+++ b/src/gameobjects/Sprite.js
@@ -5,7 +5,7 @@
*/
/**
-* Create a new Sprite object. Sprites are the lifeblood of your game, used for nearly everything visual.
+* Create a new `Sprite` object. Sprites are the lifeblood of your game, used for nearly everything visual.
* At its most basic a Sprite consists of a set of coordinates and a texture that is rendered to the canvas.
* They also contain additional properties allowing for physics motion (via Sprite.body), input handling (via Sprite.input),
* events (via Sprite.events), animation (via Sprite.animations), camera culling and more. Please see the Examples for use cases.
@@ -68,7 +68,7 @@ Phaser.Sprite = function (game, x, y, key, frame) {
/**
* If you would like the Sprite to have a lifespan once 'born' you can set this to a positive value. Handy for particles, bullets, etc.
* The lifespan is decremented by game.time.elapsed each update, once it reaches zero the kill() function is called.
- * @property {number} lifespan
+ * @property {number} lifespan - The lifespan of the Sprite (in ms) before it will be killed.
* @default
*/
this.lifespan = 0;
@@ -148,7 +148,7 @@ Phaser.Sprite = function (game, x, y, key, frame) {
* Setting than anchor to 0.5,0.5 means the textures origin is centered
* Setting the anchor to 1,1 would mean the textures origin points will be the bottom right
*
- * @property {Phaser.Point} anchor
+ * @property {Phaser.Point} anchor - The anchor around with Sprite rotation and scaling takes place.
*/
this.anchor = new Phaser.Point();
@@ -169,7 +169,7 @@ Phaser.Sprite = function (game, x, y, key, frame) {
* Should this Sprite be automatically culled if out of range of the camera?
* A culled sprite has its renderable property set to 'false'.
*
- * @property {boolean} autoCull
+ * @property {boolean} autoCull - A flag indicating if the Sprite should be automatically camera culled or not.
* @default
*/
this.autoCull = false;
@@ -310,7 +310,7 @@ Phaser.Sprite = function (game, x, y, key, frame) {
/**
* You can crop the Sprites texture by modifying the crop properties. For example crop.width = 50 would set the Sprite to only render 50px wide.
* The crop is only applied if you have set Sprite.cropEnabled to true.
- * @property {Phaser.Rectangle} crop
+ * @property {Phaser.Rectangle} crop - The crop Rectangle applied to the Sprite texture before rendering.
* @default
*/
this.crop = new Phaser.Rectangle(0, 0, this._cache.width, this._cache.height);
diff --git a/src/physics/arcade/ArcadePhysics.js b/src/physics/arcade/ArcadePhysics.js
index 31ae5718..3aff9dcc 100644
--- a/src/physics/arcade/ArcadePhysics.js
+++ b/src/physics/arcade/ArcadePhysics.js
@@ -1,52 +1,174 @@
+/**
+* @author Richard Davey
+* @copyright 2013 Photon Storm Ltd.
+* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
+*/
+
+/**
+* @class Phaser.Physics
+*/
Phaser.Physics = {};
+/**
+* Arcade Physics constructor.
+*
+* @class Phaser.Physics.Arcade
+* @classdesc Arcade Physics Constructor
+* @constructor
+* @param {Phaser.Game} game reference to the current game instance.
+*/
Phaser.Physics.Arcade = function (game) {
+ /**
+ * @property {Phaser.Game} game - Local reference to game.
+ */
this.game = game;
+ /**
+ * @property {Phaser.Point} gravity - The World gravity setting. Defaults to x: 0, y: 0, or no gravity.
+ */
this.gravity = new Phaser.Point;
+
+ /**
+ * @property {Phaser.Rectangle} bounds - The bounds inside of which the physics world exists. Defaults to match the world bounds.
+ */
this.bounds = new Phaser.Rectangle(0, 0, game.world.width, game.world.height);
/**
- * Used by the QuadTree to set the maximum number of objects
- * @type {number}
+ * @property {number} maxObjects - Used by the QuadTree to set the maximum number of objects per quad.
*/
this.maxObjects = 10;
/**
- * Used by the QuadTree to set the maximum number of levels
- * @type {number}
+ * @property {number} maxLevels - Used by the QuadTree to set the maximum number of iteration levels.
*/
this.maxLevels = 4;
+ /**
+ * @property {number} OVERLAP_BIAS - A value added to the delta values during collision checks.
+ */
this.OVERLAP_BIAS = 4;
- this.TILE_OVERLAP = false;
+ // this.TILE_OVERLAP = false;
+
+ /**
+ * @property {Phaser.QuadTree} quadTree - The world QuadTree.
+ */
this.quadTree = new Phaser.QuadTree(this, this.game.world.bounds.x, this.game.world.bounds.y, this.game.world.bounds.width, this.game.world.bounds.height, this.maxObjects, this.maxLevels);
+
+ /**
+ * @property {number} quadTreeID - The QuadTree ID.
+ */
this.quadTreeID = 0;
// Avoid gc spikes by caching these values for re-use
+
+ /**
+ * @property {Phaser.Rectangle} _bounds1 - Internal cache var.
+ * @private
+ */
this._bounds1 = new Phaser.Rectangle;
+
+ /**
+ * @property {Phaser.Rectangle} _bounds2 - Internal cache var.
+ * @private
+ */
this._bounds2 = new Phaser.Rectangle;
+
+ /**
+ * @property {number} _overlap - Internal cache var.
+ * @private
+ */
this._overlap = 0;
+
+ /**
+ * @property {number} _maxOverlap - Internal cache var.
+ * @private
+ */
this._maxOverlap = 0;
+
+ /**
+ * @property {number} _velocity1 - Internal cache var.
+ * @private
+ */
this._velocity1 = 0;
+
+ /**
+ * @property {number} _velocity2 - Internal cache var.
+ * @private
+ */
this._velocity2 = 0;
+
+ /**
+ * @property {number} _newVelocity1 - Internal cache var.
+ * @private
+ */
this._newVelocity1 = 0;
+
+ /**
+ * @property {number} _newVelocity2 - Internal cache var.
+ * @private
+ */
this._newVelocity2 = 0;
+
+ /**
+ * @property {number} _average - Internal cache var.
+ * @private
+ */
this._average = 0;
+
+ /**
+ * @property {Array} _mapData - Internal cache var.
+ * @private
+ */
this._mapData = [];
+
+ /**
+ * @property {number} _mapTiles - Internal cache var.
+ * @private
+ */
this._mapTiles = 0;
+
+ /**
+ * @property {boolean} _result - Internal cache var.
+ * @private
+ */
this._result = false;
+
+ /**
+ * @property {number} _total - Internal cache var.
+ * @private
+ */
this._total = 0;
+
+ /**
+ * @property {number} _angle - Internal cache var.
+ * @private
+ */
this._angle = 0;
+
+ /**
+ * @property {number} _dx - Internal cache var.
+ * @private
+ */
this._dx = 0;
+
+ /**
+ * @property {number} _dy - Internal cache var.
+ * @private
+ */
this._dy = 0;
};
Phaser.Physics.Arcade.prototype = {
+ /**
+ * Called automatically by a Physics body, it updates all motion related values on the Body.
+ *
+ * @method Phaser.Physics.Arcade#updateMotion
+ * @param {Phaser.Physics.Arcade.Body} The Body object to be updated.
+ */
updateMotion: function (body) {
// If you're wondering why the velocity is halved and applied twice, read this: http://www.niksula.hut.fi/~hkankaan/Homepages/gravity.html
@@ -74,11 +196,13 @@ Phaser.Physics.Arcade.prototype = {
/**
* A tween-like function that takes a starting velocity and some other factors and returns an altered velocity.
*
- * @param {number} Velocity Any component of velocity (e.g. 20).
- * @param {number} Acceleration Rate at which the velocity is changing.
- * @param {number} Drag Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set.
- * @param {number} Max An absolute value cap for the velocity.
- *
+ * @method Phaser.Physics.Arcade#computeVelocity
+ * @param {number} axis - 1 for horizontal, 2 for vertical.
+ * @param {Phaser.Physics.Arcade.Body} body - The Body object to be updated.
+ * @param {number} velocity - Any component of velocity (e.g. 20).
+ * @param {number} acceleration - Rate at which the velocity is changing.
+ * @param {number} drag - Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set.
+ * @param {number} mMax - An absolute value cap for the velocity.
* @return {number} The altered Velocity value.
*/
computeVelocity: function (axis, body, velocity, acceleration, drag, max) {
@@ -129,6 +253,12 @@ Phaser.Physics.Arcade.prototype = {
},
+ /**
+ * Called automatically by the core game loop.
+ *
+ * @method Phaser.Physics.Arcade#preUpdate
+ * @protected
+ */
preUpdate: function () {
// Clear the tree
@@ -140,6 +270,12 @@ Phaser.Physics.Arcade.prototype = {
},
+ /**
+ * Called automatically by the core game loop.
+ *
+ * @method Phaser.Physics.Arcade#postUpdate
+ * @protected
+ */
postUpdate: function () {
// Clear the tree ready for the next update
@@ -148,12 +284,13 @@ Phaser.Physics.Arcade.prototype = {
},
/**
- * Checks if two Sprite objects intersect.
+ * Checks if two Sprite objects overlap.
*
- * @param object1 The first object to check. Can be an instance of Phaser.Sprite or anything that extends it.
- * @param object2 The second object to check. Can be an instance of Phaser.Sprite or anything that extends it.
+ * @method Phaser.Physics.Arcade#overlap
+ * @param {Phaser.Sprite} object1 - The first object to check. Can be an instance of Phaser.Sprite or anything that extends it.
+ * @param {Phaser.Sprite} object2 - The second object to check. Can be an instance of Phaser.Sprite or anything that extends it.
* @returns {boolean} true if the two objects overlap.
- **/
+ */
overlap: function (object1, object2) {
// Only test valid objects
@@ -169,14 +306,16 @@ Phaser.Physics.Arcade.prototype = {
/**
* Checks for collision between two game objects. The objects can be Sprites, Groups, Emitters or Tilemaps.
* You can perform Sprite vs. Sprite, Sprite vs. Group, Group vs. Group, Sprite vs. Tilemap or Group vs. Tilemap collisions.
+ * The objects are also automatically separated.
*
- * @param object1 The first object to check. Can be an instance of Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter, or Phaser.Tilemap
- * @param object2 The second object to check. Can be an instance of Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter or Phaser.Tilemap
- * @param collideCallback An optional callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap.
- * @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then collideCallback will only be called if processCallback returns true.
- * @param callbackContext The context in which to run the callbacks.
- * @returns {boolean} true if any collisions were detected, otherwise false.
- **/
+ * @method Phaser.Physics.Arcade#collide
+ * @param {Phaser.Sprite|Phaser.Group|Phaser.Particles.Emitter|Phaser.Tilemap} object1 - The first object to check. Can be an instance of Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter, or Phaser.Tilemap
+ * @param {Phaser.Sprite|Phaser.Group|Phaser.Particles.Emitter|Phaser.Tilemap} object2 - The second object to check. Can be an instance of Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter or Phaser.Tilemap
+ * @param {function} [collideCallback=null] - An optional callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap.
+ * @param {function} [processCallback=null] - A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then collideCallback will only be called if processCallback returns true.
+ * @param {object} [callbackContext] - The context in which to run the callbacks.
+ * @returns {number} The number of collisions that were processed.
+ */
collide: function (object1, object2, collideCallback, processCallback, callbackContext) {
collideCallback = collideCallback || null;
@@ -257,6 +396,12 @@ Phaser.Physics.Arcade.prototype = {
},
+ /**
+ * An internal function. Use Phaser.Physics.Arcade.collide instead.
+ *
+ * @method Phaser.Physics.Arcade#collideSpriteVsTilemapLayer
+ * @private
+ */
collideSpriteVsTilemapLayer: function (sprite, tilemapLayer, collideCallback, processCallback, callbackContext) {
this._mapData = tilemapLayer.getTiles(sprite.body.x, sprite.body.y, sprite.body.width, sprite.body.height, true);
@@ -297,6 +442,12 @@ Phaser.Physics.Arcade.prototype = {
},
+ /**
+ * An internal function. Use Phaser.Physics.Arcade.collide instead.
+ *
+ * @method Phaser.Physics.Arcade#collideGroupVsTilemapLayer
+ * @private
+ */
collideGroupVsTilemapLayer: function (group, tilemapLayer, collideCallback, processCallback, callbackContext) {
if (group.length == 0)
@@ -321,6 +472,12 @@ Phaser.Physics.Arcade.prototype = {
},
+ /**
+ * An internal function. Use Phaser.Physics.Arcade.collide instead.
+ *
+ * @method Phaser.Physics.Arcade#collideSpriteVsSprite
+ * @private
+ */
collideSpriteVsSprite: function (sprite1, sprite2, collideCallback, processCallback, callbackContext) {
this.separate(sprite1.body, sprite2.body);
@@ -353,6 +510,12 @@ Phaser.Physics.Arcade.prototype = {
},
+ /**
+ * An internal function. Use Phaser.Physics.Arcade.collide instead.
+ *
+ * @method Phaser.Physics.Arcade#collideSpriteVsGroup
+ * @private
+ */
collideSpriteVsGroup: function (sprite, group, collideCallback, processCallback, callbackContext) {
if (group.length == 0)
@@ -389,6 +552,12 @@ Phaser.Physics.Arcade.prototype = {
},
+ /**
+ * An internal function. Use Phaser.Physics.Arcade.collide instead.
+ *
+ * @method Phaser.Physics.Arcade#collideGroupVsGroup
+ * @private
+ */
collideGroupVsGroup: function (group1, group2, collideCallback, processCallback, callbackContext) {
if (group1.length == 0 || group2.length == 0)
@@ -413,12 +582,13 @@ Phaser.Physics.Arcade.prototype = {
},
- /**
- * The core separation function to separate two physics bodies.
- * @param body1 The first Sprite.Body to separate
- * @param body2 The second Sprite.Body to separate
- * @returns {boolean} Returns true if the bodies were separated, otherwise false.
- */
+ /**
+ * The core separation function to separate two physics bodies.
+ * @method Phaser.Physics.Arcade#separate
+ * @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate.
+ * @param {Phaser.Physics.Arcade.Body} body2 - The Body object to separate.
+ * @returns {boolean} Returns true if the bodies were separated, otherwise false.
+ */
separate: function (body1, body2) {
this._result = (this.separateX(body1, body2) || this.separateY(body1, body2));
@@ -426,11 +596,12 @@ Phaser.Physics.Arcade.prototype = {
},
/**
- * Separates the two physics bodies on their X axis
- * @param body1 The first Sprite.Body to separate
- * @param body2 The second Sprite.Body to separate
- * @returns {boolean} Whether the objects in fact touched and were separated along the X axis.
- */
+ * The core separation function to separate two physics bodies on the x axis.
+ * @method Phaser.Physics.Arcade#separateX
+ * @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate.
+ * @param {Phaser.Physics.Arcade.Body} body2 - The Body object to separate.
+ * @returns {boolean} Returns true if the bodies were separated, otherwise false.
+ */
separateX: function (body1, body2) {
// Can't separate two immovable bodies
@@ -533,11 +704,12 @@ Phaser.Physics.Arcade.prototype = {
},
/**
- * Separates the two physics bodies on their Y axis
- * @param body1 The first Sprite.Body to separate
- * @param body2 The second Sprite.Body to separate
- * @returns {boolean} Whether the bodys in fact touched and were separated along the Y axis.
- */
+ * The core separation function to separate two physics bodies on the y axis.
+ * @method Phaser.Physics.Arcade#separateY
+ * @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate.
+ * @param {Phaser.Physics.Arcade.Body} body2 - The Body object to separate.
+ * @returns {boolean} Returns true if the bodies were separated, otherwise false.
+ */
separateY: function (body1, body2) {
// Can't separate two immovable or non-existing bodys
@@ -652,12 +824,13 @@ Phaser.Physics.Arcade.prototype = {
},
- /**
- * The core Collision separation function used by Collision.overlap.
- * @param object1 The first GameObject to separate
- * @param object2 The second GameObject to separate
- * @returns {boolean} Returns true if the objects were separated, otherwise false.
- */
+ /**
+ * The core separation function to separate a physics body and a tile.
+ * @method Phaser.Physics.Arcade#separateTile
+ * @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate.
+ * @param {Phaser.Tile} tile - The tile to collide against.
+ * @returns {boolean} Returns true if the bodies were separated, otherwise false.
+ */
separateTile: function (body, tile) {
this._result = (this.separateTileX(body, tile, true) || this.separateTileY(body, tile, true));
@@ -665,11 +838,12 @@ Phaser.Physics.Arcade.prototype = {
},
/**
- * Separates the two objects on their x axis
- * @param object The GameObject to separate
- * @param tile The Tile to separate
- * @returns {boolean} Whether the objects in fact touched and were separated along the X axis.
- */
+ * The core separation function to separate a physics body and a tile on the x axis.
+ * @method Phaser.Physics.Arcade#separateTileX
+ * @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate.
+ * @param {Phaser.Tile} tile - The tile to collide against.
+ * @returns {boolean} Returns true if the bodies were separated, otherwise false.
+ */
separateTileX: function (body, tile, separate) {
// Can't separate two immovable objects (tiles are always immovable)
@@ -748,11 +922,12 @@ Phaser.Physics.Arcade.prototype = {
},
/**
- * Separates the two objects on their x axis
- * @param object The GameObject to separate
- * @param tile The Tile to separate
- * @returns {boolean} Whether the objects in fact touched and were separated along the X axis.
- */
+ * The core separation function to separate a physics body and a tile on the x axis.
+ * @method Phaser.Physics.Arcade#separateTileY
+ * @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate.
+ * @param {Phaser.Tile} tile - The tile to collide against.
+ * @returns {boolean} Returns true if the bodies were separated, otherwise false.
+ */
separateTileY: function (body, tile, separate) {
// Can't separate two immovable objects (tiles are always immovable)
diff --git a/src/physics/arcade/Body.js b/src/physics/arcade/Body.js
index a2b1f3a5..7827de7c 100644
--- a/src/physics/arcade/Body.js
+++ b/src/physics/arcade/Body.js
@@ -1,84 +1,318 @@
+/**
+* @author Richard Davey
+* @copyright 2013 Photon Storm Ltd.
+* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
+*/
+
+/**
+* The Physics Body is linked to a single Sprite. All physics operations should be performed against the body rather than
+* the Sprite itself. For example you can set the velocity, acceleration, bounce values etc all on the Body.
+*
+* @class Phaser.Physics.Arcade.Body
+* @classdesc Arcade Physics Body Constructor
+* @constructor
+* @param {Phaser.Sprite} sprite - The Sprite object this physics body belongs to.
+*/
Phaser.Physics.Arcade.Body = function (sprite) {
+ /**
+ * @property {Phaser.Sprite} sprite - Reference to the parent Sprite.
+ */
this.sprite = sprite;
+
+ /**
+ * @property {Phaser.Game} game - Local reference to game.
+ */
this.game = sprite.game;
+ /**
+ * @property {Phaser.Point} offset - The offset of the Physics Body from the Sprite x/y position.
+ */
this.offset = new Phaser.Point;
+ /**
+ * @property {number} x - The x position of the physics body.
+ * @readonly
+ */
this.x = sprite.x;
+
+ /**
+ * @property {number} y - The y position of the physics body.
+ * @readonly
+ */
this.y = sprite.y;
+
+ /**
+ * @property {number} preX - The previous x position of the physics body.
+ * @readonly
+ */
this.preX = sprite.x;
+
+ /**
+ * @property {number} preY - The previous y position of the physics body.
+ * @readonly
+ */
this.preY = sprite.y;
+
+ /**
+ * @property {number} preRotation - The previous rotation of the physics body.
+ * @readonly
+ */
this.preRotation = sprite.angle;
+
+ /**
+ * @property {number} screenX - The x position of the physics body translated to screen space.
+ * @readonly
+ */
this.screenX = sprite.x;
+
+ /**
+ * @property {number} screenY - The y position of the physics body translated to screen space.
+ * @readonly
+ */
this.screenY = sprite.y;
- // un-scaled original size
+ /**
+ * @property {number} sourceWidth - The un-scaled original size.
+ * @readonly
+ */
this.sourceWidth = sprite.currentFrame.sourceSizeW;
+
+ /**
+ * @property {number} sourceHeight - The un-scaled original size.
+ * @readonly
+ */
this.sourceHeight = sprite.currentFrame.sourceSizeH;
- // calculated (scaled) size
+ /**
+ * @property {number} width - The calculated width of the physics body.
+ */
this.width = sprite.currentFrame.sourceSizeW;
+
+ /**
+ * @property .numInternal ID cache
+ */
this.height = sprite.currentFrame.sourceSizeH;
+
+ /**
+ * @property {number} halfWidth - The calculated width / 2 of the physics body.
+ */
this.halfWidth = Math.floor(sprite.currentFrame.sourceSizeW / 2);
+
+ /**
+ * @property {number} halfHeight - The calculated height / 2 of the physics body.
+ */
this.halfHeight = Math.floor(sprite.currentFrame.sourceSizeH / 2);
- // Scale value cache
+ /**
+ * @property {number} _sx - Internal cache var.
+ * @private
+ */
this._sx = sprite.scale.x;
+
+ /**
+ * @property {number} _sy - Internal cache var.
+ * @private
+ */
this._sy = sprite.scale.y;
+ /**
+ * @property {Phaser.Point} velocity - The velocity in pixels per second sq. of the Body.
+ */
this.velocity = new Phaser.Point;
+
+ /**
+ * @property {Phaser.Point} acceleration - The velocity in pixels per second sq. of the Body.
+ */
this.acceleration = new Phaser.Point;
+
+ /**
+ * @property {Phaser.Point} drag - The drag applied to the motion of the Body.
+ */
this.drag = new Phaser.Point;
+
+ /**
+ * @property {Phaser.Point} gravity - A private Gravity setting for the Body.
+ */
this.gravity = new Phaser.Point;
+
+ /**
+ * @property {Phaser.Point} bounce - The elasticitiy of the Body when colliding. bounce.x/y = 1 means full rebound, bounce.x/y = 0.5 means 50% rebound velocity.
+ */
this.bounce = new Phaser.Point;
+
+ /**
+ * @property {Phaser.Point} maxVelocity - The maximum velocity in pixels per second sq. that the Body can reach.
+ * @default
+ */
this.maxVelocity = new Phaser.Point(10000, 10000);
+ /**
+ * @property {number} angularVelocity - The angular velocity in pixels per second sq. of the Body.
+ * @default
+ */
this.angularVelocity = 0;
+
+ /**
+ * @property {number} angularAcceleration - The angular acceleration in pixels per second sq. of the Body.
+ * @default
+ */
this.angularAcceleration = 0;
+
+ /**
+ * @property {number} angularDrag - The angular drag applied to the rotation of the Body.
+ * @default
+ */
this.angularDrag = 0;
+
+ /**
+ * @property {number} maxAngular - The maximum angular velocity in pixels per second sq. that the Body can reach.
+ * @default
+ */
this.maxAngular = 1000;
+
+ /**
+ * @property {number} mass - The mass of the Body.
+ * @default
+ */
this.mass = 1;
+ /**
+ * @property {boolean} skipQuadTree - If the Body is an irregular shape you can set this to true to avoid it being added to the World quad tree.
+ * @default
+ */
this.skipQuadTree = false;
+
+ /**
+ * @property {Array} quadTreeIDs - Internal ID cache.
+ * @protected
+ */
this.quadTreeIDs = [];
+
+ /**
+ * @property {number} quadTreeIndex - Internal ID cache.
+ * @protected
+ */
this.quadTreeIndex = -1;
// Allow collision
+
+ /**
+ * Set the allowCollision properties to control which directions collision is processed for this Body.
+ * For example allowCollision.up = false means it won't collide when the collision happened while moving up.
+ * @property {object} allowCollision - An object containing allowed collision.
+ */
this.allowCollision = { none: false, any: true, up: true, down: true, left: true, right: true };
+
+ /**
+ * This object is populated with boolean values when the Body collides with another.
+ * touching.up = true means the collision happened to the top of this Body for example.
+ * @property {object} touching - An object containing touching results.
+ */
this.touching = { none: true, up: false, down: false, left: false, right: false };
+
+ /**
+ * This object is populated with previous touching values from the bodies previous collision.
+ * @property {object} wasTouching - An object containing previous touching results.
+ */
this.wasTouching = { none: true, up: false, down: false, left: false, right: false };
+
+ /**
+ * @property {number} facing - A const reference to the direction the Body is traveling or facing.
+ * @default
+ */
this.facing = Phaser.NONE;
+ /**
+ * @property {boolean} immovable - An immovable Body will not receive any impacts from other bodies.
+ * @default
+ */
this.immovable = false;
+
+ /**
+ * @property {boolean} moves - Set to true to allow the Physics system to move this Body, other false to move it manually.
+ * @default
+ */
this.moves = true;
+
+ /**
+ * @property {number} rotation - The amount the Body is rotated.
+ * @default
+ */
this.rotation = 0;
+
+ /**
+ * @property {boolean} allowRotation - Allow this Body to be rotated? (via angularVelocity, etc)
+ * @default
+ */
this.allowRotation = true;
+
+ /**
+ * @property {boolean} allowGravity - Allow this Body to be influenced by the global Gravity?
+ * @default
+ */
this.allowGravity = true;
- // These two flags allow you to disable the custom separation that takes place
- // Used in combination with your own collision processHandler you can create whatever
- // type of collision response you need.
+ /**
+ * This flag allows you to disable the custom x separation that takes place by Physics.Arcade.separate.
+ * Used in combination with your own collision processHandler you can create whatever type of collision response you need.
+ * @property {boolean} customSeparateX - Use a custom separation system or the built-in one?
+ * @default
+ */
this.customSeparateX = false;
+
+ /**
+ * This flag allows you to disable the custom y separation that takes place by Physics.Arcade.separate.
+ * Used in combination with your own collision processHandler you can create whatever type of collision response you need.
+ * @property {boolean} customSeparateY - Use a custom separation system or the built-in one?
+ * @default
+ */
this.customSeparateY = false;
- // When this body collides with another the amount of overlap is stored in here
- // These values are useful if you want to provide your own custom separation logic.
+ /**
+ * When this body collides with another, the amount of overlap is stored here.
+ * @property {number} overlapX - The amount of horizontal overlap during the collision.
+ */
this.overlapX = 0;
+
+ /**
+ * When this body collides with another, the amount of overlap is stored here.
+ * @property {number} overlapY - The amount of vertical overlap during the collision.
+ */
this.overlapY = 0;
+ /**
+ * @property {Phaser.Rectangle} hullX - The dynamically calculated hull used during collision.
+ */
this.hullX = new Phaser.Rectangle();
+
+ /**
+ * @property {Phaser.Rectangle} hullY - The dynamically calculated hull used during collision.
+ */
this.hullY = new Phaser.Rectangle();
- // If a body is overlapping with another body, but neither of them are moving (maybe they spawned on-top of each other?) this is set to true
+ /**
+ * If a body is overlapping with another body, but neither of them are moving (maybe they spawned on-top of each other?) this is set to true.
+ * @property {boolean} embedded - Body embed value.
+ */
this.embedded = false;
+ /**
+ * A Body can be set to collide against the World bounds automatically and rebound back into the World if this is set to true. Otherwise it will leave the World.
+ * @property {boolean} collideWorldBounds - Should the Body collide with the World bounds?
+ */
this.collideWorldBounds = false;
};
Phaser.Physics.Arcade.Body.prototype = {
+ /**
+ * Internal method.
+ *
+ * @method Phaser.Physics.Arcade#updateBounds
+ * @protected
+ */
updateBounds: function (centerX, centerY, scaleX, scaleY) {
if (scaleX != this._sx || scaleY != this._sy)
@@ -93,6 +327,12 @@ Phaser.Physics.Arcade.Body.prototype = {
},
+ /**
+ * Internal method.
+ *
+ * @method Phaser.Physics.Arcade#preUpdate
+ * @protected
+ */
preUpdate: function () {
// Store and reset collision flags
@@ -131,8 +371,7 @@ Phaser.Physics.Arcade.Body.prototype = {
this.checkWorldBounds();
}
- this.updateHulls();
- }
+ this.updateHulls();Array }
if (this.skipQuadTree == false && this.allowCollision.none == false && this.sprite.visible && this.sprite.alive)
{
@@ -143,6 +382,12 @@ Phaser.Physics.Arcade.Body.prototype = {
},
+ /**
+ * Internal method.
+ *
+ * @method Phaser.Physics.Arcade#postUpdate
+ * @protected
+ */
postUpdate: function () {
// Calculate forward-facing edge
@@ -183,6 +428,12 @@ Phaser.Physics.Arcade.Body.prototype = {
},
+ /**
+ * Internal method.
+ *
+ * @method Phaser.Physics.Arcade#updateHulls
+ * @protected
+ */
updateHulls: function () {
this.hullX.setTo(this.x, this.preY, this.width, this.height);
@@ -190,6 +441,12 @@ Phaser.Physics.Arcade.Body.prototype = {
},
+ /**
+ * Internal method.
+ *
+ * @method Phaser.Physics.Arcade#checkWorldBounds
+ * @protected
+ */
checkWorldBounds: function () {
if (this.x < this.game.world.bounds.x)
@@ -216,6 +473,17 @@ Phaser.Physics.Arcade.Body.prototype = {
},
+ /**
+ * You can modify the size of the physics Body to be any dimension you need.
+ * So it could be smaller or larger than the parent Sprite. You can also control the x and y offset, which
+ * is the position of the Body relative to the top-left of the Sprite.
+ *
+ * @method Phaser.Physics.Arcade#setSize
+ * @param {number} width - The width of the Body.
+ * @param {number} height - The height of the Body.
+ * @param {number} offsetX - The X offset of the Body from the Sprite position.
+ * @param {number} offsetY - The Y offset of the Body from the Sprite position.
+ */
setSize: function (width, height, offsetX, offsetY) {
offsetX = offsetX || this.offset.x;
@@ -231,6 +499,11 @@ Phaser.Physics.Arcade.Body.prototype = {
},
+ /**
+ * Resets all Body values (velocity, acceleration, rotation, etc)
+ *
+ * @method Phaser.Physics.Arcade#reset
+ */
reset: function () {
this.velocity.setTo(0, 0);
@@ -248,18 +521,42 @@ Phaser.Physics.Arcade.Body.prototype = {
},
+ /**
+ * Returns the absolute delta x value.
+ *
+ * @method Phaser.Physics.Arcade.Body#deltaAbsX
+ * @return {number} The absolute delta value.
+ */
deltaAbsX: function () {
return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX());
},
+ /**
+ * Returns the absolute delta y value.
+ *
+ * @method Phaser.Physics.Arcade.Body#deltaAbsY
+ * @return {number} The absolute delta value.
+ */
deltaAbsY: function () {
return (this.deltaY() > 0 ? this.deltaY() : -this.deltaY());
},
+ /**
+ * Returns the delta x value.
+ *
+ * @method Phaser.Physics.Arcade.Body#deltaX
+ * @return {number} The delta value.
+ */
deltaX: function () {
return this.x - this.preX;
},
+ /**
+ * Returns the delta y value.
+ *
+ * @method Phaser.Physics.Arcade.Body#deltaY
+ * @return {number} The delta value.
+ */
deltaY: function () {
return this.y - this.preY;
},
@@ -270,6 +567,10 @@ Phaser.Physics.Arcade.Body.prototype = {
};
+/**
+* @name Phaser.Physics.Arcade.Body#bottom
+* @property {number} bottom - The bottom value of this Body (same as Body.y + Body.height)
+*/
Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "bottom", {
/**
@@ -301,6 +602,10 @@ Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "bottom", {
});
+/**
+* @name Phaser.Physics.Arcade.Body#right
+* @property {number} right - The right value of this Body (same as Body.x + Body.width)
+*/
Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "right", {
/**