2014-03-05 02:36:08 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2016-04-04 21:15:01 +00:00
|
|
|
* @copyright 2016 Photon Storm Ltd.
|
2014-03-05 02:36:08 +00:00
|
|
|
* @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
|
|
|
|
* @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;
|
|
|
|
|
|
|
|
/**
|
2014-03-06 06:27:16 +00:00
|
|
|
* @property {number} type - The type of physics system this body belongs to.
|
2014-03-05 02:36:08 +00:00
|
|
|
*/
|
2014-03-06 06:27:16 +00:00
|
|
|
this.type = Phaser.Physics.ARCADE;
|
2014-03-05 02:36:08 +00:00
|
|
|
|
2014-05-27 10:22:20 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} enable - A disabled body won't be checked for any form of collision or overlap or have its pre/post updates run.
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.enable = true;
|
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
/**
|
2014-03-06 06:27:16 +00:00
|
|
|
* @property {Phaser.Point} offset - The offset of the Physics Body from the Sprite x/y position.
|
2014-03-05 02:36:08 +00:00
|
|
|
*/
|
2014-03-13 15:41:56 +00:00
|
|
|
this.offset = new Phaser.Point();
|
2014-03-05 02:36:08 +00:00
|
|
|
|
2014-03-14 03:26:06 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} position - The position of the physics body.
|
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
this.position = new Phaser.Point(sprite.x, sprite.y);
|
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
/**
|
2014-03-06 06:27:16 +00:00
|
|
|
* @property {Phaser.Point} prev - The previous position of the physics body.
|
2014-03-05 02:36:08 +00:00
|
|
|
* @readonly
|
|
|
|
*/
|
2014-03-06 06:27:16 +00:00
|
|
|
this.prev = new Phaser.Point(this.position.x, this.position.y);
|
2014-03-05 02:36:08 +00:00
|
|
|
|
2014-03-13 15:41:56 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} allowRotation - Allow this Body to be rotated? (via angularVelocity, etc)
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.allowRotation = true;
|
|
|
|
|
|
|
|
/**
|
2015-03-23 10:11:30 +00:00
|
|
|
* An Arcade Physics Body can have angularVelocity and angularAcceleration. Please understand that the collision Body
|
|
|
|
* itself never rotates, it is always axis-aligned. However these values are passed up to the parent Sprite and updates its rotation.
|
|
|
|
* @property {number} rotation
|
2014-03-13 15:41:56 +00:00
|
|
|
*/
|
|
|
|
this.rotation = sprite.rotation;
|
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
/**
|
|
|
|
* @property {number} preRotation - The previous rotation of the physics body.
|
|
|
|
* @readonly
|
|
|
|
*/
|
2014-03-13 15:41:56 +00:00
|
|
|
this.preRotation = sprite.rotation;
|
2014-03-05 02:36:08 +00:00
|
|
|
|
|
|
|
/**
|
2015-03-23 15:05:39 +00:00
|
|
|
* @property {number} width - The calculated width of the physics body.
|
2014-03-05 02:36:08 +00:00
|
|
|
* @readonly
|
|
|
|
*/
|
2015-03-23 15:05:39 +00:00
|
|
|
this.width = sprite.width;
|
2014-03-05 02:36:08 +00:00
|
|
|
|
|
|
|
/**
|
2015-03-23 15:05:39 +00:00
|
|
|
* @property {number} height - The calculated height of the physics body.
|
2014-03-05 02:36:08 +00:00
|
|
|
* @readonly
|
|
|
|
*/
|
2015-03-23 15:05:39 +00:00
|
|
|
this.height = sprite.height;
|
2014-03-05 02:36:08 +00:00
|
|
|
|
|
|
|
/**
|
2015-03-23 15:05:39 +00:00
|
|
|
* @property {number} sourceWidth - The un-scaled original size.
|
2015-02-26 23:32:14 +00:00
|
|
|
* @readonly
|
2014-03-05 02:36:08 +00:00
|
|
|
*/
|
2015-03-23 15:05:39 +00:00
|
|
|
this.sourceWidth = sprite.width;
|
2014-03-05 02:36:08 +00:00
|
|
|
|
|
|
|
/**
|
2015-03-23 15:05:39 +00:00
|
|
|
* @property {number} sourceHeight - The un-scaled original size.
|
2015-02-26 23:32:14 +00:00
|
|
|
* @readonly
|
2014-03-05 02:36:08 +00:00
|
|
|
*/
|
2015-03-23 15:05:39 +00:00
|
|
|
this.sourceHeight = sprite.height;
|
|
|
|
|
|
|
|
if (sprite.texture)
|
|
|
|
{
|
|
|
|
this.sourceWidth = sprite.texture.frame.width;
|
|
|
|
this.sourceHeight = sprite.texture.frame.height;
|
|
|
|
}
|
2014-03-05 02:36:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} halfWidth - The calculated width / 2 of the physics body.
|
2015-02-26 23:32:14 +00:00
|
|
|
* @readonly
|
2014-03-05 02:36:08 +00:00
|
|
|
*/
|
2014-03-06 06:27:16 +00:00
|
|
|
this.halfWidth = Math.abs(sprite.width / 2);
|
2014-03-05 02:36:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} halfHeight - The calculated height / 2 of the physics body.
|
2015-02-26 23:32:14 +00:00
|
|
|
* @readonly
|
2014-03-05 02:36:08 +00:00
|
|
|
*/
|
2014-03-06 06:27:16 +00:00
|
|
|
this.halfHeight = Math.abs(sprite.height / 2);
|
2014-03-05 02:36:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} center - The center coordinate of the Physics Body.
|
2015-02-26 23:32:14 +00:00
|
|
|
* @readonly
|
2014-03-05 02:36:08 +00:00
|
|
|
*/
|
2014-03-06 06:27:16 +00:00
|
|
|
this.center = new Phaser.Point(sprite.x + this.halfWidth, sprite.y + this.halfHeight);
|
2014-03-05 02:36:08 +00:00
|
|
|
|
|
|
|
/**
|
2015-03-23 10:11:30 +00:00
|
|
|
* @property {Phaser.Point} velocity - The velocity, or rate of change in speed of the Body. Measured in pixels per second.
|
2014-03-05 02:36:08 +00:00
|
|
|
*/
|
|
|
|
this.velocity = new Phaser.Point();
|
|
|
|
|
2014-03-06 06:27:16 +00:00
|
|
|
/**
|
2015-03-23 10:11:30 +00:00
|
|
|
* @property {Phaser.Point} newVelocity - The new velocity. Calculated during the Body.preUpdate and applied to its position.
|
2014-03-06 06:27:16 +00:00
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
this.newVelocity = new Phaser.Point(0, 0);
|
|
|
|
|
2014-03-20 00:20:02 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} deltaMax - The Sprite position is updated based on the delta x/y values. You can set a cap on those (both +-) using deltaMax.
|
|
|
|
*/
|
|
|
|
this.deltaMax = new Phaser.Point(0, 0);
|
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
/**
|
2015-03-23 10:11:30 +00:00
|
|
|
* @property {Phaser.Point} acceleration - The acceleration is the rate of change of the velocity. Measured in pixels per second squared.
|
2014-03-05 02:36:08 +00:00
|
|
|
*/
|
|
|
|
this.acceleration = new Phaser.Point();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} drag - The drag applied to the motion of the Body.
|
|
|
|
*/
|
|
|
|
this.drag = new Phaser.Point();
|
|
|
|
|
|
|
|
/**
|
2014-03-11 16:26:03 +00:00
|
|
|
* @property {boolean} allowGravity - Allow this Body to be influenced by gravity? Either world or local.
|
2014-03-11 02:49:55 +00:00
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.allowGravity = true;
|
|
|
|
|
|
|
|
/**
|
2014-03-11 16:26:03 +00:00
|
|
|
* @property {Phaser.Point} gravity - A local gravity applied to this Body. If non-zero this over rides any world gravity, unless Body.allowGravity is set to false.
|
2014-03-11 02:49:55 +00:00
|
|
|
*/
|
|
|
|
this.gravity = new Phaser.Point(0, 0);
|
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
/**
|
2015-03-23 10:11:30 +00:00
|
|
|
* @property {Phaser.Point} bounce - The elasticity of the Body when colliding. bounce.x/y = 1 means full rebound, bounce.x/y = 0.5 means 50% rebound velocity.
|
2014-03-05 02:36:08 +00:00
|
|
|
*/
|
|
|
|
this.bounce = new Phaser.Point();
|
|
|
|
|
2016-05-16 12:53:12 +00:00
|
|
|
/**
|
|
|
|
* The elasticity of the Body when colliding with the World bounds.
|
|
|
|
* By default this property is `null`, in which case `Body.bounce` is used instead. Set this property
|
|
|
|
* to a Phaser.Point object in order to enable a World bounds specific bounce value.
|
|
|
|
* @property {Phaser.Point} worldBounce
|
|
|
|
*/
|
|
|
|
this.worldBounce = null;
|
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
/**
|
|
|
|
* @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);
|
|
|
|
|
2015-01-18 12:18:13 +00:00
|
|
|
/**
|
2015-01-28 17:18:19 +00:00
|
|
|
* @property {Phaser.Point} friction - The amount of movement that will occur if another object 'rides' this one.
|
2015-01-18 12:18:13 +00:00
|
|
|
*/
|
|
|
|
this.friction = new Phaser.Point(1, 0);
|
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
/**
|
2015-03-23 10:11:30 +00:00
|
|
|
* @property {number} angularVelocity - The angular velocity controls the rotation speed of the Body. It is measured in radians per second.
|
2014-03-05 02:36:08 +00:00
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.angularVelocity = 0;
|
|
|
|
|
|
|
|
/**
|
2015-03-23 10:11:30 +00:00
|
|
|
* @property {number} angularAcceleration - The angular acceleration is the rate of change of the angular velocity. Measured in radians per second squared.
|
2014-03-05 02:36:08 +00:00
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.angularAcceleration = 0;
|
|
|
|
|
|
|
|
/**
|
2015-03-23 10:11:30 +00:00
|
|
|
* @property {number} angularDrag - The drag applied during the rotation of the Body.
|
2014-03-05 02:36:08 +00:00
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.angularDrag = 0;
|
|
|
|
|
|
|
|
/**
|
2015-03-23 10:11:30 +00:00
|
|
|
* @property {number} maxAngular - The maximum angular velocity in radians per second that the Body can reach.
|
2014-03-05 02:36:08 +00:00
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.maxAngular = 1000;
|
|
|
|
|
|
|
|
/**
|
2015-03-23 10:11:30 +00:00
|
|
|
* @property {number} mass - The mass of the Body. When two bodies collide their mass is used in the calculation to determine the exchange of velocity.
|
2014-03-05 02:36:08 +00:00
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.mass = 1;
|
|
|
|
|
2014-03-13 15:41:56 +00:00
|
|
|
/**
|
2015-03-23 10:11:30 +00:00
|
|
|
* @property {number} angle - The angle of the Body in radians, as calculated by its angularVelocity.
|
2014-03-13 15:41:56 +00:00
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
this.angle = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} speed - The speed of the Body as calculated by its velocity.
|
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
this.speed = 0;
|
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
/**
|
|
|
|
* @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;
|
|
|
|
|
|
|
|
/**
|
2014-03-14 04:49:55 +00:00
|
|
|
* If you have a Body that is being moved around the world via a tween or a Group motion, but its local x/y position never
|
|
|
|
* actually changes, then you should set Body.moves = false. Otherwise it will most likely fly off the screen.
|
|
|
|
* If you want the physics system to move the body around, then set moves to true.
|
2015-03-18 21:00:38 +00:00
|
|
|
* @property {boolean} moves - Set to true to allow the Physics system to move this Body, otherwise false to move it manually.
|
2014-03-05 02:36:08 +00:00
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.moves = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2014-03-05 03:18:24 +00:00
|
|
|
/**
|
|
|
|
* Set the checkCollision properties to control which directions collision is processed for this Body.
|
|
|
|
* For example checkCollision.up = false means it won't collide when the collision happened while moving up.
|
|
|
|
* @property {object} checkCollision - An object containing allowed collision.
|
|
|
|
*/
|
|
|
|
this.checkCollision = { 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 };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This object is populated with boolean values when the Body collides with the World bounds or a Tile.
|
|
|
|
* For example if blocked.up is true then the Body cannot move up.
|
|
|
|
* @property {object} blocked - An object containing on which faces this Body is blocked from moving, if any.
|
|
|
|
*/
|
2014-03-13 21:14:10 +00:00
|
|
|
this.blocked = { up: false, down: false, left: false, right: false };
|
2014-03-06 06:27:16 +00:00
|
|
|
|
2014-03-13 23:15:32 +00:00
|
|
|
/**
|
|
|
|
* If this is an especially small or fast moving object then it can sometimes skip over tilemap collisions if it moves through a tile in a step.
|
|
|
|
* Set this padding value to add extra padding to its bounds. tilePadding.x applied to its width, y to its height.
|
2015-03-18 21:00:38 +00:00
|
|
|
* @property {Phaser.Point} tilePadding - Extra padding to be added to this sprite's dimensions when checking for tile collision.
|
2014-03-13 23:15:32 +00:00
|
|
|
*/
|
|
|
|
this.tilePadding = new Phaser.Point();
|
|
|
|
|
2014-03-28 01:42:49 +00:00
|
|
|
/**
|
2015-02-25 02:18:05 +00:00
|
|
|
* @property {boolean} dirty - If this Body in a preUpdate (true) or postUpdate (false) state?
|
2014-03-28 01:42:49 +00:00
|
|
|
*/
|
2015-02-25 02:18:05 +00:00
|
|
|
this.dirty = false;
|
2014-03-28 01:42:49 +00:00
|
|
|
|
2014-08-04 12:04:11 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} skipQuadTree - If true and you collide this Sprite against a Group, it will disable the collision check from using a QuadTree.
|
|
|
|
*/
|
|
|
|
this.skipQuadTree = false;
|
|
|
|
|
2015-04-29 12:13:26 +00:00
|
|
|
/**
|
|
|
|
* If true the Body will check itself against the Sprite.getBounds() dimensions and adjust its width and height accordingly.
|
|
|
|
* If false it will compare its dimensions against the Sprite scale instead, and adjust its width height if the scale has changed.
|
|
|
|
* Typically you would need to enable syncBounds if your sprite is the child of a responsive display object such as a FlexLayer,
|
|
|
|
* or in any situation where the Sprite scale doesn't change, but its parents scale is effecting the dimensions regardless.
|
|
|
|
* @property {boolean} syncBounds
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.syncBounds = false;
|
|
|
|
|
2014-03-26 10:48:30 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} _reset - Internal cache var.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._reset = true;
|
|
|
|
|
2014-03-20 03:48:54 +00:00
|
|
|
/**
|
|
|
|
* @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 {number} _dx - Internal cache var.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._dx = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} _dy - Internal cache var.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._dy = 0;
|
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.Physics.Arcade.Body.prototype = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal method.
|
|
|
|
*
|
2014-04-01 02:54:20 +00:00
|
|
|
* @method Phaser.Physics.Arcade.Body#updateBounds
|
2014-03-05 02:36:08 +00:00
|
|
|
* @protected
|
|
|
|
*/
|
2014-03-20 00:20:02 +00:00
|
|
|
updateBounds: function () {
|
2014-03-05 02:36:08 +00:00
|
|
|
|
2015-04-29 12:13:26 +00:00
|
|
|
if (this.syncBounds)
|
|
|
|
{
|
|
|
|
var b = this.sprite.getBounds();
|
|
|
|
b.ceilAll();
|
|
|
|
|
|
|
|
if (b.width !== this.width || b.height !== this.height)
|
|
|
|
{
|
|
|
|
this.width = b.width;
|
|
|
|
this.height = b.height;
|
|
|
|
this._reset = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var asx = Math.abs(this.sprite.scale.x);
|
|
|
|
var asy = Math.abs(this.sprite.scale.y);
|
|
|
|
|
|
|
|
if (asx !== this._sx || asy !== this._sy)
|
|
|
|
{
|
|
|
|
this.width = this.sourceWidth * asx;
|
|
|
|
this.height = this.sourceHeight * asy;
|
|
|
|
this._sx = asx;
|
|
|
|
this._sy = asy;
|
|
|
|
this._reset = true;
|
|
|
|
}
|
|
|
|
}
|
2014-03-20 03:48:54 +00:00
|
|
|
|
2015-04-29 12:13:26 +00:00
|
|
|
if (this._reset)
|
2014-03-05 02:36:08 +00:00
|
|
|
{
|
|
|
|
this.halfWidth = Math.floor(this.width / 2);
|
|
|
|
this.halfHeight = Math.floor(this.height / 2);
|
2014-03-19 02:28:20 +00:00
|
|
|
this.center.setTo(this.position.x + this.halfWidth, this.position.y + this.halfHeight);
|
2014-03-05 02:36:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal method.
|
|
|
|
*
|
2014-04-01 02:54:20 +00:00
|
|
|
* @method Phaser.Physics.Arcade.Body#preUpdate
|
2014-03-05 02:36:08 +00:00
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
preUpdate: function () {
|
|
|
|
|
2015-01-10 00:30:02 +00:00
|
|
|
if (!this.enable || this.game.physics.arcade.isPaused)
|
2014-06-30 10:49:53 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-17 05:13:36 +00:00
|
|
|
this.dirty = true;
|
2014-03-28 01:42:49 +00:00
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
// Store and reset collision flags
|
|
|
|
this.wasTouching.none = this.touching.none;
|
|
|
|
this.wasTouching.up = this.touching.up;
|
|
|
|
this.wasTouching.down = this.touching.down;
|
|
|
|
this.wasTouching.left = this.touching.left;
|
|
|
|
this.wasTouching.right = this.touching.right;
|
|
|
|
|
|
|
|
this.touching.none = true;
|
|
|
|
this.touching.up = false;
|
|
|
|
this.touching.down = false;
|
|
|
|
this.touching.left = false;
|
|
|
|
this.touching.right = false;
|
|
|
|
|
2014-03-13 21:14:10 +00:00
|
|
|
this.blocked.up = false;
|
|
|
|
this.blocked.down = false;
|
|
|
|
this.blocked.left = false;
|
|
|
|
this.blocked.right = false;
|
2014-03-05 02:36:08 +00:00
|
|
|
|
2014-03-19 03:55:44 +00:00
|
|
|
this.embedded = false;
|
|
|
|
|
2014-03-26 10:48:30 +00:00
|
|
|
this.updateBounds();
|
|
|
|
|
2016-05-23 11:45:51 +00:00
|
|
|
this.position.x = (this.sprite.world.x - (this.sprite.anchor.x * this.sprite.width)) + this.sprite.scale.x * this.offset.x;
|
|
|
|
this.position.x -= this.sprite.scale.x < 0 ? this.width : 0;
|
|
|
|
|
|
|
|
this.position.y = (this.sprite.world.y - (this.sprite.anchor.y * this.sprite.height)) + this.sprite.scale.y * this.offset.y;
|
|
|
|
this.position.y -= this.sprite.scale.y < 0 ? this.height : 0;
|
2016-05-16 12:39:46 +00:00
|
|
|
|
2014-03-19 02:28:20 +00:00
|
|
|
this.rotation = this.sprite.angle;
|
|
|
|
|
2014-03-20 03:48:54 +00:00
|
|
|
this.preRotation = this.rotation;
|
|
|
|
|
2015-02-16 17:22:51 +00:00
|
|
|
if (this._reset || this.sprite.fresh)
|
2014-03-20 00:20:02 +00:00
|
|
|
{
|
|
|
|
this.prev.x = this.position.x;
|
|
|
|
this.prev.y = this.position.y;
|
|
|
|
}
|
2014-03-19 02:28:20 +00:00
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
if (this.moves)
|
|
|
|
{
|
|
|
|
this.game.physics.arcade.updateMotion(this);
|
|
|
|
|
2014-03-06 06:27:16 +00:00
|
|
|
this.newVelocity.set(this.velocity.x * this.game.time.physicsElapsed, this.velocity.y * this.game.time.physicsElapsed);
|
|
|
|
|
|
|
|
this.position.x += this.newVelocity.x;
|
|
|
|
this.position.y += this.newVelocity.y;
|
|
|
|
|
2014-03-13 15:41:56 +00:00
|
|
|
if (this.position.x !== this.prev.x || this.position.y !== this.prev.y)
|
|
|
|
{
|
|
|
|
this.angle = Math.atan2(this.velocity.y, this.velocity.x);
|
|
|
|
}
|
|
|
|
|
2016-04-05 22:06:57 +00:00
|
|
|
this.speed = Math.sqrt(this.velocity.x * this.velocity.x + this.velocity.y * this.velocity.y);
|
|
|
|
|
2014-03-06 06:27:16 +00:00
|
|
|
// Now the State update will throw collision checks at the Body
|
|
|
|
// And finally we'll integrate the new position back to the Sprite in postUpdate
|
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
if (this.collideWorldBounds)
|
|
|
|
{
|
|
|
|
this.checkWorldBounds();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-28 01:42:49 +00:00
|
|
|
this._dx = this.deltaX();
|
|
|
|
this._dy = this.deltaY();
|
|
|
|
|
2014-03-26 10:48:30 +00:00
|
|
|
this._reset = false;
|
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal method.
|
|
|
|
*
|
2014-04-01 02:54:20 +00:00
|
|
|
* @method Phaser.Physics.Arcade.Body#postUpdate
|
2014-03-05 02:36:08 +00:00
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
postUpdate: function () {
|
|
|
|
|
2014-04-15 01:50:25 +00:00
|
|
|
// Only allow postUpdate to be called once per frame
|
2015-02-17 05:13:36 +00:00
|
|
|
if (!this.enable || !this.dirty)
|
2014-04-15 01:50:25 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-25 02:18:05 +00:00
|
|
|
this.dirty = false;
|
|
|
|
|
2014-03-10 14:33:18 +00:00
|
|
|
if (this.deltaX() < 0)
|
2014-03-06 06:27:16 +00:00
|
|
|
{
|
|
|
|
this.facing = Phaser.LEFT;
|
|
|
|
}
|
|
|
|
else if (this.deltaX() > 0)
|
|
|
|
{
|
|
|
|
this.facing = Phaser.RIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.deltaY() < 0)
|
|
|
|
{
|
|
|
|
this.facing = Phaser.UP;
|
|
|
|
}
|
|
|
|
else if (this.deltaY() > 0)
|
|
|
|
{
|
|
|
|
this.facing = Phaser.DOWN;
|
|
|
|
}
|
|
|
|
|
2014-03-14 04:49:55 +00:00
|
|
|
if (this.moves)
|
|
|
|
{
|
2014-03-20 03:48:54 +00:00
|
|
|
this._dx = this.deltaX();
|
|
|
|
this._dy = this.deltaY();
|
2014-03-20 00:20:02 +00:00
|
|
|
|
2014-03-20 03:48:54 +00:00
|
|
|
if (this.deltaMax.x !== 0 && this._dx !== 0)
|
2014-03-20 00:20:02 +00:00
|
|
|
{
|
2014-03-20 03:48:54 +00:00
|
|
|
if (this._dx < 0 && this._dx < -this.deltaMax.x)
|
2014-03-20 00:20:02 +00:00
|
|
|
{
|
2014-03-20 03:48:54 +00:00
|
|
|
this._dx = -this.deltaMax.x;
|
2014-03-20 00:20:02 +00:00
|
|
|
}
|
2014-03-20 03:48:54 +00:00
|
|
|
else if (this._dx > 0 && this._dx > this.deltaMax.x)
|
2014-03-20 00:20:02 +00:00
|
|
|
{
|
2014-03-20 03:48:54 +00:00
|
|
|
this._dx = this.deltaMax.x;
|
2014-03-20 00:20:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-20 03:48:54 +00:00
|
|
|
if (this.deltaMax.y !== 0 && this._dy !== 0)
|
2014-03-20 00:20:02 +00:00
|
|
|
{
|
2014-03-28 01:42:49 +00:00
|
|
|
if (this._dy < 0 && this._dy < -this.deltaMax.y)
|
2014-03-20 00:20:02 +00:00
|
|
|
{
|
2014-03-20 03:48:54 +00:00
|
|
|
this._dy = -this.deltaMax.y;
|
2014-03-20 00:20:02 +00:00
|
|
|
}
|
2014-03-20 03:48:54 +00:00
|
|
|
else if (this._dy > 0 && this._dy > this.deltaMax.y)
|
2014-03-20 00:20:02 +00:00
|
|
|
{
|
2014-03-20 03:48:54 +00:00
|
|
|
this._dy = this.deltaMax.y;
|
2014-03-20 00:20:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-25 02:18:05 +00:00
|
|
|
this.sprite.position.x += this._dx;
|
|
|
|
this.sprite.position.y += this._dy;
|
|
|
|
this._reset = true;
|
2014-03-14 04:49:55 +00:00
|
|
|
}
|
|
|
|
|
2014-03-19 02:28:20 +00:00
|
|
|
this.center.setTo(this.position.x + this.halfWidth, this.position.y + this.halfHeight);
|
2014-03-05 02:36:08 +00:00
|
|
|
|
|
|
|
if (this.allowRotation)
|
|
|
|
{
|
|
|
|
this.sprite.angle += this.deltaZ();
|
|
|
|
}
|
|
|
|
|
2014-03-20 00:20:02 +00:00
|
|
|
this.prev.x = this.position.x;
|
|
|
|
this.prev.y = this.position.y;
|
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal method.
|
|
|
|
*
|
2014-04-01 02:54:20 +00:00
|
|
|
* @method Phaser.Physics.Arcade.Body#checkWorldBounds
|
2014-03-05 02:36:08 +00:00
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
checkWorldBounds: function () {
|
|
|
|
|
2015-07-22 00:23:24 +00:00
|
|
|
var pos = this.position;
|
|
|
|
var bounds = this.game.physics.arcade.bounds;
|
|
|
|
var check = this.game.physics.arcade.checkCollision;
|
|
|
|
|
2016-05-16 12:53:12 +00:00
|
|
|
var bx = (this.worldBounce) ? -this.worldBounce.x : -this.bounce.x;
|
|
|
|
var by = (this.worldBounce) ? -this.worldBounce.y : -this.bounce.y;
|
|
|
|
|
2015-07-22 00:23:24 +00:00
|
|
|
if (pos.x < bounds.x && check.left)
|
2014-03-05 02:36:08 +00:00
|
|
|
{
|
2015-07-22 00:23:24 +00:00
|
|
|
pos.x = bounds.x;
|
2016-05-16 12:53:12 +00:00
|
|
|
this.velocity.x *= bx;
|
2014-03-14 03:26:06 +00:00
|
|
|
this.blocked.left = true;
|
2014-03-05 02:36:08 +00:00
|
|
|
}
|
2015-07-22 00:23:24 +00:00
|
|
|
else if (this.right > bounds.right && check.right)
|
2014-03-05 02:36:08 +00:00
|
|
|
{
|
2015-07-22 00:23:24 +00:00
|
|
|
pos.x = bounds.right - this.width;
|
2016-05-16 12:53:12 +00:00
|
|
|
this.velocity.x *= bx;
|
2014-03-14 03:26:06 +00:00
|
|
|
this.blocked.right = true;
|
2014-03-05 02:36:08 +00:00
|
|
|
}
|
|
|
|
|
2015-07-22 00:23:24 +00:00
|
|
|
if (pos.y < bounds.y && check.up)
|
2014-03-05 02:36:08 +00:00
|
|
|
{
|
2015-07-22 00:23:24 +00:00
|
|
|
pos.y = bounds.y;
|
2016-05-16 12:53:12 +00:00
|
|
|
this.velocity.y *= by;
|
2014-03-14 03:26:06 +00:00
|
|
|
this.blocked.up = true;
|
2014-03-05 02:36:08 +00:00
|
|
|
}
|
2015-07-22 00:23:24 +00:00
|
|
|
else if (this.bottom > bounds.bottom && check.down)
|
2014-03-05 02:36:08 +00:00
|
|
|
{
|
2015-07-22 00:23:24 +00:00
|
|
|
pos.y = bounds.bottom - this.height;
|
2016-05-16 12:53:12 +00:00
|
|
|
this.velocity.y *= by;
|
2014-03-14 03:26:06 +00:00
|
|
|
this.blocked.down = true;
|
2014-03-05 02:36:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* You can modify the size of the physics Body to be any dimension you need.
|
2016-05-23 12:16:21 +00:00
|
|
|
* This allows you to make it smaller, or larger, than the parent Sprite.
|
|
|
|
* You can also control the x and y offset of the Body. This is the position of the
|
|
|
|
* Body relative to the top-left of the Sprite _texture_.
|
2014-03-05 02:36:08 +00:00
|
|
|
*
|
2016-05-23 12:16:21 +00:00
|
|
|
* For example: If you have a Sprite with a texture that is 80x100 in size,
|
|
|
|
* and you want the physics body to be 32x32 pixels in the middle of the texture, you would do:
|
|
|
|
*
|
|
|
|
* `setSize(32, 32, 24, 34)`
|
|
|
|
*
|
|
|
|
* Where the first two parameters is the new Body size (32x32 pixels).
|
|
|
|
* 24 is the horizontal offset of the Body from the top-left of the Sprites texture, and 34
|
|
|
|
* is the vertical offset.
|
2016-04-07 16:01:16 +00:00
|
|
|
*
|
2014-04-01 02:54:20 +00:00
|
|
|
* @method Phaser.Physics.Arcade.Body#setSize
|
2014-03-05 02:36:08 +00:00
|
|
|
* @param {number} width - The width of the Body.
|
|
|
|
* @param {number} height - The height of the Body.
|
2016-05-23 12:16:21 +00:00
|
|
|
* @param {number} [offsetX] - The X offset of the Body from the top-left of the Sprites texture.
|
|
|
|
* @param {number} [offsetY] - The Y offset of the Body from the top-left of the Sprites texture.
|
2014-03-05 02:36:08 +00:00
|
|
|
*/
|
|
|
|
setSize: function (width, height, offsetX, offsetY) {
|
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (offsetX === undefined) { offsetX = this.offset.x; }
|
|
|
|
if (offsetY === undefined) { offsetY = this.offset.y; }
|
2014-03-05 02:36:08 +00:00
|
|
|
|
|
|
|
this.sourceWidth = width;
|
|
|
|
this.sourceHeight = height;
|
|
|
|
this.width = this.sourceWidth * this._sx;
|
|
|
|
this.height = this.sourceHeight * this._sy;
|
|
|
|
this.halfWidth = Math.floor(this.width / 2);
|
|
|
|
this.halfHeight = Math.floor(this.height / 2);
|
|
|
|
this.offset.setTo(offsetX, offsetY);
|
|
|
|
|
2014-03-19 02:28:20 +00:00
|
|
|
this.center.setTo(this.position.x + this.halfWidth, this.position.y + this.halfHeight);
|
2014-03-05 02:36:08 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets all Body values (velocity, acceleration, rotation, etc)
|
|
|
|
*
|
2014-04-01 02:54:20 +00:00
|
|
|
* @method Phaser.Physics.Arcade.Body#reset
|
2014-03-13 15:57:49 +00:00
|
|
|
* @param {number} x - The new x position of the Body.
|
2014-04-01 02:54:20 +00:00
|
|
|
* @param {number} y - The new y position of the Body.
|
2014-03-05 02:36:08 +00:00
|
|
|
*/
|
2014-03-13 15:57:49 +00:00
|
|
|
reset: function (x, y) {
|
2014-03-05 02:36:08 +00:00
|
|
|
|
2014-03-20 03:48:54 +00:00
|
|
|
this.velocity.set(0);
|
|
|
|
this.acceleration.set(0);
|
2014-03-05 02:36:08 +00:00
|
|
|
|
2015-02-05 05:12:31 +00:00
|
|
|
this.speed = 0;
|
2014-03-05 02:36:08 +00:00
|
|
|
this.angularVelocity = 0;
|
|
|
|
this.angularAcceleration = 0;
|
|
|
|
|
2016-05-23 11:54:41 +00:00
|
|
|
this.position.x = (x - (this.sprite.anchor.x * this.sprite.width)) + this.sprite.scale.x * this.offset.x;
|
2016-05-23 11:45:51 +00:00
|
|
|
this.position.x -= this.sprite.scale.x < 0 ? this.width : 0;
|
|
|
|
|
2016-05-23 11:54:41 +00:00
|
|
|
this.position.y = (y - (this.sprite.anchor.y * this.sprite.height)) + this.sprite.scale.y * this.offset.y;
|
2016-05-23 11:45:51 +00:00
|
|
|
this.position.y -= this.sprite.scale.y < 0 ? this.height : 0;
|
2014-03-20 03:48:54 +00:00
|
|
|
|
|
|
|
this.prev.x = this.position.x;
|
|
|
|
this.prev.y = this.position.y;
|
|
|
|
|
|
|
|
this.rotation = this.sprite.angle;
|
2014-03-13 15:57:49 +00:00
|
|
|
this.preRotation = this.rotation;
|
2014-03-20 03:48:54 +00:00
|
|
|
|
|
|
|
this._sx = this.sprite.scale.x;
|
|
|
|
this._sy = this.sprite.scale.y;
|
2014-06-30 10:49:53 +00:00
|
|
|
|
2014-03-19 02:28:20 +00:00
|
|
|
this.center.setTo(this.position.x + this.halfWidth, this.position.y + this.halfHeight);
|
2014-03-05 02:36:08 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-04-01 02:54:20 +00:00
|
|
|
/**
|
|
|
|
* Tests if a world point lies within this Body.
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.Body#hitTest
|
|
|
|
* @param {number} x - The world x coordinate to test.
|
|
|
|
* @param {number} y - The world y coordinate to test.
|
|
|
|
* @return {boolean} True if the given coordinates are inside this Body, otherwise false.
|
|
|
|
*/
|
|
|
|
hitTest: function (x, y) {
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2016-05-23 22:02:04 +00:00
|
|
|
return Phaser.Rectangle.contains(this, x, y);
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2014-04-01 02:54:20 +00:00
|
|
|
},
|
|
|
|
|
2014-03-14 03:26:06 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the bottom of this Body is in contact with either the world bounds or a tile.
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.Body#onFloor
|
|
|
|
* @return {boolean} True if in contact with either the world bounds or a tile.
|
|
|
|
*/
|
|
|
|
onFloor: function () {
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2014-03-14 03:26:06 +00:00
|
|
|
return this.blocked.down;
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2014-03-14 03:26:06 +00:00
|
|
|
},
|
2015-02-10 23:36:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the top of this Body is in contact with either the world bounds or a tile.
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.Body#onTop
|
|
|
|
* @return {boolean} True if in contact with either the world bounds or a tile.
|
|
|
|
*/
|
|
|
|
onCeiling: function(){
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2015-02-10 23:36:35 +00:00
|
|
|
return this.blocked.up;
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2015-02-10 23:36:35 +00:00
|
|
|
},
|
2014-03-14 03:26:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if either side of this Body is in contact with either the world bounds or a tile.
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.Body#onWall
|
|
|
|
* @return {boolean} True if in contact with either the world bounds or a tile.
|
|
|
|
*/
|
|
|
|
onWall: function () {
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2014-03-14 03:26:06 +00:00
|
|
|
return (this.blocked.left || this.blocked.right);
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2014-03-14 03:26:06 +00:00
|
|
|
},
|
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
/**
|
|
|
|
* Returns the absolute delta x value.
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.Body#deltaAbsX
|
|
|
|
* @return {number} The absolute delta value.
|
|
|
|
*/
|
|
|
|
deltaAbsX: function () {
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX());
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the absolute delta y value.
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.Body#deltaAbsY
|
|
|
|
* @return {number} The absolute delta value.
|
|
|
|
*/
|
|
|
|
deltaAbsY: function () {
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
return (this.deltaY() > 0 ? this.deltaY() : -this.deltaY());
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the delta x value. The difference between Body.x now and in the previous step.
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.Body#deltaX
|
|
|
|
* @return {number} The delta value. Positive if the motion was to the right, negative if to the left.
|
|
|
|
*/
|
|
|
|
deltaX: function () {
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2014-03-06 06:27:16 +00:00
|
|
|
return this.position.x - this.prev.x;
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the delta y value. The difference between Body.y now and in the previous step.
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.Body#deltaY
|
|
|
|
* @return {number} The delta value. Positive if the motion was downwards, negative if upwards.
|
|
|
|
*/
|
|
|
|
deltaY: function () {
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2014-03-06 06:27:16 +00:00
|
|
|
return this.position.y - this.prev.y;
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
},
|
|
|
|
|
2014-03-06 06:27:16 +00:00
|
|
|
/**
|
|
|
|
* Returns the delta z value. The difference between Body.rotation now and in the previous step.
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.Body#deltaZ
|
|
|
|
* @return {number} The delta value. Positive if the motion was clockwise, negative if anti-clockwise.
|
|
|
|
*/
|
2014-03-05 02:36:08 +00:00
|
|
|
deltaZ: function () {
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
return this.rotation - this.preRotation;
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2016-04-07 16:01:16 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys this Body.
|
|
|
|
*
|
|
|
|
* First it calls Group.removeFromHash if the Game Object this Body belongs to is part of a Group.
|
|
|
|
* Then it nulls the Game Objects body reference, and nulls this Body.sprite reference.
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.Body#destroy
|
|
|
|
*/
|
|
|
|
destroy: function () {
|
|
|
|
|
|
|
|
if (this.sprite.parent && this.sprite.parent instanceof Phaser.Group)
|
|
|
|
{
|
|
|
|
this.sprite.parent.removeFromHash(this.sprite);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.sprite.body = null;
|
|
|
|
this.sprite = null;
|
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-04-07 16:01:16 +00:00
|
|
|
* @name Phaser.Physics.Arcade.Body#left
|
|
|
|
* @property {number} left - The x position of the Body. The same as `Body.x`.
|
2014-03-05 02:36:08 +00:00
|
|
|
*/
|
2016-04-07 16:01:16 +00:00
|
|
|
Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "left", {
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
get: function () {
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2016-04-07 16:01:16 +00:00
|
|
|
return this.position.x;
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Phaser.Physics.Arcade.Body#right
|
|
|
|
* @property {number} right - The right value of this Body (same as Body.x + Body.width)
|
2014-03-06 06:27:16 +00:00
|
|
|
* @readonly
|
2014-03-05 02:36:08 +00:00
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "right", {
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
get: function () {
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2014-03-06 06:27:16 +00:00
|
|
|
return this.position.x + this.width;
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2014-03-06 06:27:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2016-04-07 16:01:16 +00:00
|
|
|
/**
|
|
|
|
* @name Phaser.Physics.Arcade.Body#top
|
|
|
|
* @property {number} top - The y position of the Body. The same as `Body.y`.
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "top", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
|
|
|
return this.position.y;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Phaser.Physics.Arcade.Body#bottom
|
|
|
|
* @property {number} bottom - The bottom value of this Body (same as Body.y + Body.height)
|
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "bottom", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
|
|
|
return this.position.y + this.height;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-03-06 06:27:16 +00:00
|
|
|
/**
|
|
|
|
* @name Phaser.Physics.Arcade.Body#x
|
|
|
|
* @property {number} x - The x position.
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "x", {
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2014-03-06 06:27:16 +00:00
|
|
|
get: function () {
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2014-03-06 06:27:16 +00:00
|
|
|
return this.position.x;
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
2014-03-28 01:42:49 +00:00
|
|
|
|
2014-03-06 06:27:16 +00:00
|
|
|
this.position.x = value;
|
|
|
|
}
|
2014-03-05 02:36:08 +00:00
|
|
|
|
2014-03-06 06:27:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Phaser.Physics.Arcade.Body#y
|
|
|
|
* @property {number} y - The y position.
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "y", {
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2014-03-06 06:27:16 +00:00
|
|
|
get: function () {
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2014-03-06 06:27:16 +00:00
|
|
|
return this.position.y;
|
2016-04-07 13:32:53 +00:00
|
|
|
|
2014-03-06 06:27:16 +00:00
|
|
|
},
|
2014-03-05 02:36:08 +00:00
|
|
|
|
2014-03-06 06:27:16 +00:00
|
|
|
set: function (value) {
|
2014-03-28 01:42:49 +00:00
|
|
|
|
2014-03-06 06:27:16 +00:00
|
|
|
this.position.y = value;
|
2014-03-28 01:42:49 +00:00
|
|
|
|
2014-03-05 02:36:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2014-03-06 06:27:16 +00:00
|
|
|
|
2014-03-13 15:41:56 +00:00
|
|
|
/**
|
|
|
|
* Render Sprite Body.
|
|
|
|
*
|
2014-07-05 22:08:00 +00:00
|
|
|
* @method Phaser.Physics.Arcade.Body#render
|
2014-03-13 15:41:56 +00:00
|
|
|
* @param {object} context - The context to render to.
|
|
|
|
* @param {Phaser.Physics.Arcade.Body} body - The Body to render the info of.
|
2014-07-05 22:08:00 +00:00
|
|
|
* @param {string} [color='rgba(0,255,0,0.4)'] - color of the debug info to be rendered. (format is css color string).
|
2014-03-13 15:41:56 +00:00
|
|
|
* @param {boolean} [filled=true] - Render the objected as a filled (default, true) or a stroked (false)
|
|
|
|
*/
|
2014-07-05 21:50:13 +00:00
|
|
|
Phaser.Physics.Arcade.Body.render = function (context, body, color, filled) {
|
2014-03-13 15:41:56 +00:00
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (filled === undefined) { filled = true; }
|
2014-03-13 15:41:56 +00:00
|
|
|
|
|
|
|
color = color || 'rgba(0,255,0,0.4)';
|
|
|
|
|
2016-04-14 12:23:28 +00:00
|
|
|
if (filled)
|
2014-03-13 15:41:56 +00:00
|
|
|
{
|
2016-04-14 12:23:28 +00:00
|
|
|
context.fillStyle = color;
|
|
|
|
context.fillRect(body.position.x - body.game.camera.x, body.position.y - body.game.camera.y, body.width, body.height);
|
2014-03-13 15:41:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-14 12:23:28 +00:00
|
|
|
context.strokeStyle = color;
|
|
|
|
context.strokeRect(body.position.x - body.game.camera.x, body.position.y - body.game.camera.y, body.width, body.height);
|
2014-03-13 15:41:56 +00:00
|
|
|
}
|
|
|
|
|
2014-03-23 08:31:39 +00:00
|
|
|
};
|
2014-03-13 15:41:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Render Sprite Body Physics Data as text.
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.Body#renderBodyInfo
|
|
|
|
* @param {Phaser.Physics.Arcade.Body} body - The Body to render the info of.
|
|
|
|
* @param {number} x - X position of the debug info to be rendered.
|
|
|
|
* @param {number} y - Y position of the debug info to be rendered.
|
|
|
|
* @param {string} [color='rgb(255,255,255)'] - color of the debug info to be rendered. (format is css color string).
|
|
|
|
*/
|
|
|
|
Phaser.Physics.Arcade.Body.renderBodyInfo = function (debug, body) {
|
|
|
|
|
|
|
|
debug.line('x: ' + body.x.toFixed(2), 'y: ' + body.y.toFixed(2), 'width: ' + body.width, 'height: ' + body.height);
|
2014-03-28 01:42:49 +00:00
|
|
|
debug.line('velocity x: ' + body.velocity.x.toFixed(2), 'y: ' + body.velocity.y.toFixed(2), 'deltaX: ' + body._dx.toFixed(2), 'deltaY: ' + body._dy.toFixed(2));
|
2014-03-14 03:26:06 +00:00
|
|
|
debug.line('acceleration x: ' + body.acceleration.x.toFixed(2), 'y: ' + body.acceleration.y.toFixed(2), 'speed: ' + body.speed.toFixed(2), 'angle: ' + body.angle.toFixed(2));
|
|
|
|
debug.line('gravity x: ' + body.gravity.x, 'y: ' + body.gravity.y, 'bounce x: ' + body.bounce.x.toFixed(2), 'y: ' + body.bounce.y.toFixed(2));
|
2014-03-13 15:41:56 +00:00
|
|
|
debug.line('touching left: ' + body.touching.left, 'right: ' + body.touching.right, 'up: ' + body.touching.up, 'down: ' + body.touching.down);
|
2014-03-14 03:26:06 +00:00
|
|
|
debug.line('blocked left: ' + body.blocked.left, 'right: ' + body.blocked.right, 'up: ' + body.blocked.up, 'down: ' + body.blocked.down);
|
2014-03-13 15:41:56 +00:00
|
|
|
|
2014-03-23 08:31:39 +00:00
|
|
|
};
|
2014-03-13 15:41:56 +00:00
|
|
|
|
2014-03-06 06:27:16 +00:00
|
|
|
Phaser.Physics.Arcade.Body.prototype.constructor = Phaser.Physics.Arcade.Body;
|