2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2019-01-15 16:20:22 +00:00
|
|
|
* @copyright 2019 Photon Storm Ltd.
|
2018-02-12 16:01:20 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2017-11-09 15:31:48 +00:00
|
|
|
var CircleContains = require('../../geom/circle/Contains');
|
|
|
|
var Class = require('../../utils/Class');
|
|
|
|
var CONST = require('./const');
|
|
|
|
var RectangleContains = require('../../geom/rectangle/Contains');
|
|
|
|
var Vector2 = require('../../math/Vector2');
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
|
|
|
* @classdesc
|
2018-06-13 16:41:50 +00:00
|
|
|
* A Static Arcade Physics Body.
|
|
|
|
*
|
|
|
|
* A Static Body never moves, and isn't automatically synchronized with its parent Game Object.
|
|
|
|
* That means if you make any change to the parent's origin, position, or scale after creating or adding the body, you'll need to update the Body manually.
|
|
|
|
*
|
|
|
|
* A Static Body can collide with other Bodies, but is never moved by collisions.
|
|
|
|
*
|
|
|
|
* Its dynamic counterpart is {@link Phaser.Physics.Arcade.Body}.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @class StaticBody
|
2018-10-10 09:49:13 +00:00
|
|
|
* @memberof Phaser.Physics.Arcade
|
2018-02-09 03:44:23 +00:00
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-10-19 11:32:43 +00:00
|
|
|
* @param {Phaser.Physics.Arcade.World} world - The Arcade Physics simulation this Static Body belongs to.
|
|
|
|
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object this Static Body belongs to.
|
2018-02-09 03:44:23 +00:00
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
var StaticBody = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
function StaticBody (world, gameObject)
|
|
|
|
{
|
2018-05-23 14:17:26 +00:00
|
|
|
var width = (gameObject.width) ? gameObject.width : 64;
|
|
|
|
var height = (gameObject.height) ? gameObject.height : 64;
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-10-19 11:32:43 +00:00
|
|
|
* The Arcade Physics simulation this Static Body belongs to.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#world
|
2018-02-09 04:08:01 +00:00
|
|
|
* @type {Phaser.Physics.Arcade.World}
|
2018-02-09 03:44:23 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.world = world;
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-10-19 11:32:43 +00:00
|
|
|
* The Game Object this Static Body belongs to.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#gameObject
|
|
|
|
* @type {Phaser.GameObjects.GameObject}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.gameObject = gameObject;
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-10-19 11:32:43 +00:00
|
|
|
* Whether the Static Body's boundary is drawn to the debug display.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#debugShowBody
|
2018-02-09 04:08:01 +00:00
|
|
|
* @type {boolean}
|
2018-02-09 03:44:23 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 16:32:31 +00:00
|
|
|
this.debugShowBody = world.defaults.debugShowStaticBody;
|
2018-02-09 03:44:23 +00:00
|
|
|
|
|
|
|
/**
|
2018-10-19 11:32:43 +00:00
|
|
|
* The color of this Static Body on the debug display.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#debugBodyColor
|
2018-02-09 04:08:01 +00:00
|
|
|
* @type {integer}
|
2018-02-09 03:44:23 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 16:32:31 +00:00
|
|
|
this.debugBodyColor = world.defaults.staticBodyDebugColor;
|
2017-11-09 15:31:48 +00:00
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-10-19 11:32:43 +00:00
|
|
|
* Whether this Static Body is updated by the physics simulation.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#enable
|
|
|
|
* @type {boolean}
|
|
|
|
* @default true
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.enable = true;
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-10-19 11:32:43 +00:00
|
|
|
* Whether this Static Body's boundary is circular (`true`) or rectangular (`false`).
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#isCircle
|
|
|
|
* @type {boolean}
|
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.isCircle = false;
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-10-19 11:32:43 +00:00
|
|
|
* If this Static Body is circular, this is the unscaled radius of the Static Body's boundary, as set by {@link #setCircle}, in source pixels.
|
|
|
|
* The true radius is equal to `halfWidth`.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#radius
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.radius = 0;
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-10-19 11:32:43 +00:00
|
|
|
* The offset of this Static Body's actual position from any updated position.
|
|
|
|
*
|
|
|
|
* Unlike a dynamic Body, a Static Body does not follow its Game Object. As such, this offset is only applied when resizing the Static Body.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#offset
|
2018-02-09 04:08:01 +00:00
|
|
|
* @type {Phaser.Math.Vector2}
|
2018-02-09 03:44:23 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.offset = new Vector2();
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-10-19 11:32:43 +00:00
|
|
|
* The position of this Static Body within the simulation.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#position
|
2018-02-09 04:08:01 +00:00
|
|
|
* @type {Phaser.Math.Vector2}
|
2018-02-09 03:44:23 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.position = new Vector2(gameObject.x - gameObject.displayOriginX, gameObject.y - gameObject.displayOriginY);
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-10-19 11:32:43 +00:00
|
|
|
* The width of the Static Body's boundary, in pixels.
|
|
|
|
* If the Static Body is circular, this is also the Static Body's diameter.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#width
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-05-23 14:17:26 +00:00
|
|
|
this.width = width;
|
2017-11-09 15:31:48 +00:00
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-10-19 11:32:43 +00:00
|
|
|
* The height of the Static Body's boundary, in pixels.
|
|
|
|
* If the Static Body is circular, this is also the Static Body's diameter.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#height
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-05-23 14:17:26 +00:00
|
|
|
this.height = height;
|
2017-11-09 15:31:48 +00:00
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-10-19 11:32:43 +00:00
|
|
|
* Half the Static Body's width, in pixels.
|
|
|
|
* If the Static Body is circular, this is also the Static Body's radius.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#halfWidth
|
2018-02-09 04:08:01 +00:00
|
|
|
* @type {number}
|
2018-02-09 03:44:23 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-02-15 01:51:36 +00:00
|
|
|
this.halfWidth = Math.abs(this.width / 2);
|
2017-11-09 15:31:48 +00:00
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-10-19 11:32:43 +00:00
|
|
|
* Half the Static Body's height, in pixels.
|
|
|
|
* If the Static Body is circular, this is also the Static Body's radius.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#halfHeight
|
2018-02-09 04:08:01 +00:00
|
|
|
* @type {number}
|
2018-02-09 03:44:23 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-02-15 01:51:36 +00:00
|
|
|
this.halfHeight = Math.abs(this.height / 2);
|
2017-11-09 15:31:48 +00:00
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-10-19 11:32:43 +00:00
|
|
|
* The center of the Static Body's boundary.
|
|
|
|
* This is the midpoint of its `position` (top-left corner) and its bottom-right corner.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#center
|
2018-02-09 04:08:01 +00:00
|
|
|
* @type {Phaser.Math.Vector2}
|
2018-02-09 03:44:23 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.center = new Vector2(gameObject.x + this.halfWidth, gameObject.y + this.halfHeight);
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-10-19 11:32:43 +00:00
|
|
|
* A constant zero velocity used by the Arcade Physics simulation for calculations.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#velocity
|
2018-02-09 04:08:01 +00:00
|
|
|
* @type {Phaser.Math.Vector2}
|
2018-10-09 12:40:00 +00:00
|
|
|
* @readonly
|
2018-02-09 03:44:23 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-02-15 01:51:36 +00:00
|
|
|
this.velocity = Vector2.ZERO;
|
2017-11-09 15:31:48 +00:00
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-10-19 11:32:43 +00:00
|
|
|
* A constant `false` value expected by the Arcade Physics simulation.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#allowGravity
|
|
|
|
* @type {boolean}
|
2018-10-09 12:40:00 +00:00
|
|
|
* @readonly
|
2018-02-09 03:44:23 +00:00
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.allowGravity = false;
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* Gravitational force applied specifically to this Body. Values are in pixels per second squared. Always zero for a Static Body.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#gravity
|
2018-02-09 04:08:01 +00:00
|
|
|
* @type {Phaser.Math.Vector2}
|
2018-10-09 12:40:00 +00:00
|
|
|
* @readonly
|
2018-02-09 03:44:23 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-02-15 01:51:36 +00:00
|
|
|
this.gravity = Vector2.ZERO;
|
2017-11-09 15:31:48 +00:00
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* Rebound, or restitution, following a collision, relative to 1. Always zero for a Static Body.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#bounce
|
2018-02-09 04:08:01 +00:00
|
|
|
* @type {Phaser.Math.Vector2}
|
2018-10-09 12:40:00 +00:00
|
|
|
* @readonly
|
2018-02-09 03:44:23 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-02-15 01:51:36 +00:00
|
|
|
this.bounce = Vector2.ZERO;
|
2017-11-09 15:31:48 +00:00
|
|
|
|
|
|
|
// If true this Body will dispatch events
|
2018-02-09 03:44:23 +00:00
|
|
|
|
|
|
|
/**
|
2018-11-07 17:43:43 +00:00
|
|
|
* Whether the simulation emits a `worldbounds` event when this StaticBody collides with the world boundary.
|
|
|
|
* Always false for a Static Body. (Static Bodies never collide with the world boundary and never trigger a `worldbounds` event.)
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#onWorldBounds
|
|
|
|
* @type {boolean}
|
2018-11-07 17:43:43 +00:00
|
|
|
* @readonly
|
2018-02-09 03:44:23 +00:00
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.onWorldBounds = false;
|
2018-02-09 03:44:23 +00:00
|
|
|
|
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* Whether the simulation emits a `collide` event when this StaticBody collides with another.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#onCollide
|
|
|
|
* @type {boolean}
|
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.onCollide = false;
|
2018-02-09 03:44:23 +00:00
|
|
|
|
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* Whether the simulation emits an `overlap` event when this StaticBody overlaps with another.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#onOverlap
|
|
|
|
* @type {boolean}
|
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.onOverlap = false;
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* The StaticBody's inertia, relative to a default unit (1). With `bounce`, this affects the exchange of momentum (velocities) during collisions.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#mass
|
|
|
|
* @type {number}
|
|
|
|
* @default 1
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.mass = 1;
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* Whether this object can be moved by collisions with another body.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#immovable
|
|
|
|
* @type {boolean}
|
|
|
|
* @default true
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.immovable = true;
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-11-07 17:43:43 +00:00
|
|
|
* A flag disabling the default horizontal separation of colliding bodies. Pass your own `collideHandler` to the collider.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#customSeparateX
|
|
|
|
* @type {boolean}
|
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.customSeparateX = false;
|
2018-02-09 03:44:23 +00:00
|
|
|
|
|
|
|
/**
|
2018-11-07 17:43:43 +00:00
|
|
|
* A flag disabling the default vertical separation of colliding bodies. Pass your own `collideHandler` to the collider.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#customSeparateY
|
|
|
|
* @type {boolean}
|
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.customSeparateY = false;
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* The amount of horizontal overlap (before separation), if this Body is colliding with another.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#overlapX
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.overlapX = 0;
|
2018-02-09 03:44:23 +00:00
|
|
|
|
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* The amount of vertical overlap (before separation), if this Body is colliding with another.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#overlapY
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.overlapY = 0;
|
2018-02-09 03:44:23 +00:00
|
|
|
|
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* The amount of overlap (before separation), if this StaticBody is circular and colliding with another circular body.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#overlapR
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.overlapR = 0;
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-11-07 17:43:43 +00:00
|
|
|
* Whether this StaticBody has ever overlapped with another while both were not moving.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#embedded
|
|
|
|
* @type {boolean}
|
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.embedded = false;
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* Whether this StaticBody interacts with the world boundary.
|
2018-11-07 17:43:43 +00:00
|
|
|
* Always false for a Static Body. (Static Bodies never collide with the world boundary.)
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#collideWorldBounds
|
|
|
|
* @type {boolean}
|
2018-11-07 17:43:43 +00:00
|
|
|
* @readonly
|
2018-02-09 03:44:23 +00:00
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.collideWorldBounds = false;
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* Whether this StaticBody is checked for collisions and for which directions. You can set `checkCollision.none = false` to disable collision checks.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#checkCollision
|
2019-02-13 14:45:36 +00:00
|
|
|
* @type {Phaser.Physics.Arcade.Types.ArcadeBodyCollision}
|
2018-02-09 03:44:23 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.checkCollision = { none: false, up: true, down: true, left: true, right: true };
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-11-07 17:43:43 +00:00
|
|
|
* Whether this StaticBody has ever collided with another body and in which direction.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#touching
|
2019-02-13 14:45:36 +00:00
|
|
|
* @type {Phaser.Physics.Arcade.Types.ArcadeBodyCollision}
|
2018-02-09 03:44:23 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.touching = { none: true, up: false, down: false, left: false, right: false };
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-11-07 17:43:43 +00:00
|
|
|
* Whether this StaticBody was colliding with another body during the last step or any previous step, and in which direction.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#wasTouching
|
2019-02-13 14:45:36 +00:00
|
|
|
* @type {Phaser.Physics.Arcade.Types.ArcadeBodyCollision}
|
2018-02-09 03:44:23 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.wasTouching = { none: true, up: false, down: false, left: false, right: false };
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-11-07 17:43:43 +00:00
|
|
|
* Whether this StaticBody has ever collided with a tile or the world boundary.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#blocked
|
2019-02-13 14:45:36 +00:00
|
|
|
* @type {Phaser.Physics.Arcade.Types.ArcadeBodyCollision}
|
2018-02-09 03:44:23 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.blocked = { none: true, up: false, down: false, left: false, right: false };
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* The StaticBody's physics type (static by default).
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#physicsType
|
2018-02-09 04:08:01 +00:00
|
|
|
* @type {integer}
|
2018-11-07 17:43:43 +00:00
|
|
|
* @default Phaser.Physics.Arcade.STATIC_BODY
|
2018-02-09 03:44:23 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
this.physicsType = CONST.STATIC_BODY;
|
2018-06-01 18:52:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The calculated change in the Body's horizontal position during the current step.
|
|
|
|
* For a static body this is always zero.
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#_dx
|
|
|
|
* @type {number}
|
|
|
|
* @private
|
|
|
|
* @default 0
|
|
|
|
* @since 3.10.0
|
|
|
|
*/
|
|
|
|
this._dx = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The calculated change in the Body's vertical position during the current step.
|
|
|
|
* For a static body this is always zero.
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#_dy
|
|
|
|
* @type {number}
|
|
|
|
* @private
|
|
|
|
* @default 0
|
|
|
|
* @since 3.10.0
|
|
|
|
*/
|
|
|
|
this._dy = 0;
|
2018-02-15 01:51:36 +00:00
|
|
|
},
|
2017-11-09 15:31:48 +00:00
|
|
|
|
2018-02-15 01:51:36 +00:00
|
|
|
/**
|
|
|
|
* Changes the Game Object this Body is bound to.
|
|
|
|
* First it removes its reference from the old Game Object, then sets the new one.
|
|
|
|
* You can optionally update the position and dimensions of this Body to reflect that of the new Game Object.
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.StaticBody#setGameObject
|
2018-02-15 14:31:15 +00:00
|
|
|
* @since 3.1.0
|
2018-02-15 01:51:36 +00:00
|
|
|
*
|
|
|
|
* @param {Phaser.GameObjects.GameObject} gameObject - The new Game Object that will own this Body.
|
|
|
|
* @param {boolean} [update=true] - Reposition and resize this Body to match the new Game Object?
|
|
|
|
*
|
|
|
|
* @return {Phaser.Physics.Arcade.StaticBody} This Static Body object.
|
2018-06-13 16:41:50 +00:00
|
|
|
*
|
|
|
|
* @see Phaser.Physics.Arcade.StaticBody#updateFromGameObject
|
2018-02-15 01:51:36 +00:00
|
|
|
*/
|
|
|
|
setGameObject: function (gameObject, update)
|
|
|
|
{
|
|
|
|
if (gameObject && gameObject !== this.gameObject)
|
|
|
|
{
|
|
|
|
// Remove this body from the old game object
|
|
|
|
this.gameObject.body = null;
|
2018-02-09 03:44:23 +00:00
|
|
|
|
2018-02-15 01:51:36 +00:00
|
|
|
gameObject.body = this;
|
2017-11-09 15:31:48 +00:00
|
|
|
|
2018-02-15 01:51:36 +00:00
|
|
|
// Update our reference
|
|
|
|
this.gameObject = gameObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update)
|
|
|
|
{
|
|
|
|
this.updateFromGameObject();
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates this Static Body so that its position and dimensions are updated
|
|
|
|
* based on the current Game Object it is bound to.
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.StaticBody#updateFromGameObject
|
2018-02-15 14:31:15 +00:00
|
|
|
* @since 3.1.0
|
2018-02-15 01:51:36 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Physics.Arcade.StaticBody} This Static Body object.
|
|
|
|
*/
|
|
|
|
updateFromGameObject: function ()
|
|
|
|
{
|
|
|
|
this.world.staticTree.remove(this);
|
|
|
|
|
|
|
|
var gameObject = this.gameObject;
|
|
|
|
|
|
|
|
gameObject.getTopLeft(this.position);
|
|
|
|
|
|
|
|
this.width = gameObject.displayWidth;
|
|
|
|
this.height = gameObject.displayHeight;
|
|
|
|
|
|
|
|
this.halfWidth = Math.abs(this.width / 2);
|
|
|
|
this.halfHeight = Math.abs(this.height / 2);
|
|
|
|
|
|
|
|
this.center.set(this.position.x + this.halfWidth, this.position.y + this.halfHeight);
|
|
|
|
|
|
|
|
this.world.staticTree.insert(this);
|
|
|
|
|
|
|
|
return this;
|
2017-11-09 15:31:48 +00:00
|
|
|
},
|
|
|
|
|
2018-04-05 07:48:35 +00:00
|
|
|
/**
|
2018-09-24 22:20:43 +00:00
|
|
|
* Sets the offset of the body.
|
2018-04-05 07:48:35 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.StaticBody#setOffset
|
|
|
|
* @since 3.4.0
|
|
|
|
*
|
2018-09-24 22:20:43 +00:00
|
|
|
* @param {number} x - The horizontal offset of the Body from the Game Object's center.
|
|
|
|
* @param {number} y - The vertical offset of the Body from the Game Object's center.
|
2018-04-05 07:48:35 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Physics.Arcade.StaticBody} This Static Body object.
|
|
|
|
*/
|
|
|
|
setOffset: function (x, y)
|
|
|
|
{
|
|
|
|
if (y === undefined) { y = x; }
|
|
|
|
|
|
|
|
this.world.staticTree.remove(this);
|
|
|
|
|
2018-04-11 04:16:08 +00:00
|
|
|
this.position.x -= this.offset.x;
|
|
|
|
this.position.y -= this.offset.y;
|
|
|
|
|
2018-04-05 07:48:35 +00:00
|
|
|
this.offset.set(x, y);
|
|
|
|
|
2018-04-11 04:16:08 +00:00
|
|
|
this.position.x += this.offset.x;
|
|
|
|
this.position.y += this.offset.y;
|
|
|
|
|
2018-04-05 07:48:35 +00:00
|
|
|
this.updateCenter();
|
|
|
|
|
|
|
|
this.world.staticTree.insert(this);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-07-25 01:05:51 +00:00
|
|
|
* Sets the size of the body.
|
2018-07-31 08:39:22 +00:00
|
|
|
* Resets the width and height to match current frame, if no width and height provided and a frame is found.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.StaticBody#setSize
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-07-31 08:39:22 +00:00
|
|
|
* @param {integer} [width] - The width of the Body in pixels. Cannot be zero. If not given, and the parent Game Object has a frame, it will use the frame width.
|
|
|
|
* @param {integer} [height] - The height of the Body in pixels. Cannot be zero. If not given, and the parent Game Object has a frame, it will use the frame height.
|
|
|
|
* @param {number} [offsetX] - The horizontal offset of the Body from the Game Object's center.
|
|
|
|
* @param {number} [offsetY] - The vertical offset of the Body from the Game Object's center.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
2018-02-09 04:08:01 +00:00
|
|
|
* @return {Phaser.Physics.Arcade.StaticBody} This Static Body object.
|
2018-02-09 03:44:23 +00:00
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
setSize: function (width, height, offsetX, offsetY)
|
|
|
|
{
|
|
|
|
if (offsetX === undefined) { offsetX = this.offset.x; }
|
|
|
|
if (offsetY === undefined) { offsetY = this.offset.y; }
|
|
|
|
|
2018-07-31 08:39:22 +00:00
|
|
|
var gameObject = this.gameObject;
|
|
|
|
|
|
|
|
if (!width && gameObject.frame)
|
|
|
|
{
|
|
|
|
width = gameObject.frame.realWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!height && gameObject.frame)
|
|
|
|
{
|
|
|
|
height = gameObject.frame.realHeight;
|
|
|
|
}
|
|
|
|
|
2017-11-09 15:31:48 +00:00
|
|
|
this.world.staticTree.remove(this);
|
|
|
|
|
2018-02-15 01:51:36 +00:00
|
|
|
this.width = width;
|
|
|
|
this.height = height;
|
|
|
|
|
|
|
|
this.halfWidth = Math.floor(width / 2);
|
|
|
|
this.halfHeight = Math.floor(height / 2);
|
|
|
|
|
2017-11-09 15:31:48 +00:00
|
|
|
this.offset.set(offsetX, offsetY);
|
|
|
|
|
|
|
|
this.updateCenter();
|
|
|
|
|
|
|
|
this.isCircle = false;
|
|
|
|
this.radius = 0;
|
|
|
|
|
|
|
|
this.world.staticTree.insert(this);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* Sets this Static Body to have a circular body and sets its sizes and position.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.StaticBody#setCircle
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-09-28 10:04:19 +00:00
|
|
|
* @param {number} radius - The radius of the StaticBody, in pixels.
|
|
|
|
* @param {number} [offsetX] - The horizontal offset of the StaticBody from its Game Object, in pixels.
|
|
|
|
* @param {number} [offsetY] - The vertical offset of the StaticBody from its Game Object, in pixels.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
2018-02-09 04:08:01 +00:00
|
|
|
* @return {Phaser.Physics.Arcade.StaticBody} This Static Body object.
|
2018-02-09 03:44:23 +00:00
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
setCircle: function (radius, offsetX, offsetY)
|
|
|
|
{
|
|
|
|
if (offsetX === undefined) { offsetX = this.offset.x; }
|
|
|
|
if (offsetY === undefined) { offsetY = this.offset.y; }
|
|
|
|
|
|
|
|
if (radius > 0)
|
|
|
|
{
|
|
|
|
this.world.staticTree.remove(this);
|
|
|
|
|
|
|
|
this.isCircle = true;
|
|
|
|
|
2018-02-15 01:51:36 +00:00
|
|
|
this.radius = radius;
|
2017-11-09 15:31:48 +00:00
|
|
|
|
2018-02-15 01:51:36 +00:00
|
|
|
this.width = radius * 2;
|
|
|
|
this.height = radius * 2;
|
2017-11-09 15:31:48 +00:00
|
|
|
|
|
|
|
this.halfWidth = Math.floor(this.width / 2);
|
|
|
|
this.halfHeight = Math.floor(this.height / 2);
|
|
|
|
|
|
|
|
this.offset.set(offsetX, offsetY);
|
|
|
|
|
|
|
|
this.updateCenter();
|
|
|
|
|
|
|
|
this.world.staticTree.insert(this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.isCircle = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* Updates the StaticBody's `center` from its `position` and dimensions.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.StaticBody#updateCenter
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 16:32:31 +00:00
|
|
|
updateCenter: function ()
|
2017-11-09 15:31:48 +00:00
|
|
|
{
|
2017-11-09 16:32:31 +00:00
|
|
|
this.center.set(this.position.x + this.halfWidth, this.position.y + this.halfHeight);
|
|
|
|
},
|
2017-11-09 15:31:48 +00:00
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-12-12 12:39:47 +00:00
|
|
|
* Resets this Body to the given coordinates. Also positions its parent Game Object to the same coordinates.
|
2018-06-13 16:41:50 +00:00
|
|
|
* Similar to `updateFromGameObject`, but doesn't modify the Body's dimensions.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.StaticBody#reset
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-12-12 12:39:47 +00:00
|
|
|
* @param {number} [x] - The x coordinate to reset the body to. If not given will use the parent Game Object's coordinate.
|
|
|
|
* @param {number} [y] - The y coordinate to reset the body to. If not given will use the parent Game Object's coordinate.
|
2018-02-09 03:44:23 +00:00
|
|
|
*/
|
2017-11-09 16:32:31 +00:00
|
|
|
reset: function (x, y)
|
|
|
|
{
|
2018-02-15 01:51:36 +00:00
|
|
|
var gameObject = this.gameObject;
|
2017-11-09 15:31:48 +00:00
|
|
|
|
2018-02-15 01:51:36 +00:00
|
|
|
if (x === undefined) { x = gameObject.x; }
|
|
|
|
if (y === undefined) { y = gameObject.y; }
|
2017-11-09 16:32:31 +00:00
|
|
|
|
|
|
|
this.world.staticTree.remove(this);
|
|
|
|
|
2018-12-12 12:39:47 +00:00
|
|
|
gameObject.setPosition(x, y);
|
|
|
|
|
2018-02-15 01:51:36 +00:00
|
|
|
gameObject.getTopLeft(this.position);
|
2017-11-09 15:31:48 +00:00
|
|
|
|
|
|
|
this.updateCenter();
|
|
|
|
|
|
|
|
this.world.staticTree.insert(this);
|
|
|
|
},
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* NOOP function. A Static Body cannot be stopped.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.StaticBody#stop
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-09 04:08:01 +00:00
|
|
|
* @return {Phaser.Physics.Arcade.StaticBody} This Static Body object.
|
2018-02-09 03:44:23 +00:00
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
stop: function ()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* Returns the x and y coordinates of the top left and bottom right points of the StaticBody.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.StaticBody#getBounds
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2019-02-13 14:45:36 +00:00
|
|
|
* @param {Phaser.Physics.Arcade.Types.ArcadeBodyBounds} obj - The object which will hold the coordinates of the bounds.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
2019-02-13 14:45:36 +00:00
|
|
|
* @return {Phaser.Physics.Arcade.Types.ArcadeBodyBounds} The same object that was passed with `x`, `y`, `right` and `bottom` values matching the respective values of the StaticBody.
|
2018-02-09 03:44:23 +00:00
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
getBounds: function (obj)
|
|
|
|
{
|
|
|
|
obj.x = this.x;
|
|
|
|
obj.y = this.y;
|
|
|
|
obj.right = this.right;
|
|
|
|
obj.bottom = this.bottom;
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
},
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-09-24 22:20:43 +00:00
|
|
|
* Checks to see if a given x,y coordinate is colliding with this Static Body.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.StaticBody#hitTest
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-09-28 10:04:19 +00:00
|
|
|
* @param {number} x - The x coordinate to check against this body.
|
|
|
|
* @param {number} y - The y coordinate to check against this body.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
2018-09-28 10:04:19 +00:00
|
|
|
* @return {boolean} `true` if the given coordinate lies within this body, otherwise `false`.
|
2018-02-09 03:44:23 +00:00
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
hitTest: function (x, y)
|
|
|
|
{
|
|
|
|
return (this.isCircle) ? CircleContains(this, x, y) : RectangleContains(this, x, y);
|
|
|
|
},
|
|
|
|
|
2018-08-29 15:35:13 +00:00
|
|
|
/**
|
|
|
|
* NOOP
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.StaticBody#postUpdate
|
|
|
|
* @since 3.12.0
|
|
|
|
*/
|
|
|
|
postUpdate: function ()
|
|
|
|
{
|
|
|
|
},
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* The absolute (non-negative) change in this StaticBody's horizontal position from the previous step. Always zero.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.StaticBody#deltaAbsX
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-09-28 10:04:19 +00:00
|
|
|
* @return {number} Always zero for a Static Body.
|
2018-02-09 03:44:23 +00:00
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
deltaAbsX: function ()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
},
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* The absolute (non-negative) change in this StaticBody's vertical position from the previous step. Always zero.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.StaticBody#deltaAbsY
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-09-28 10:04:19 +00:00
|
|
|
* @return {number} Always zero for a Static Body.
|
2018-02-09 03:44:23 +00:00
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
deltaAbsY: function ()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
},
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* The change in this StaticBody's horizontal position from the previous step. Always zero.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.StaticBody#deltaX
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-10-19 11:32:43 +00:00
|
|
|
* @return {number} The change in this StaticBody's velocity from the previous step. Always zero.
|
2018-02-09 03:44:23 +00:00
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
deltaX: function ()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
},
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* The change in this StaticBody's vertical position from the previous step. Always zero.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.StaticBody#deltaY
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-10-19 11:32:43 +00:00
|
|
|
* @return {number} The change in this StaticBody's velocity from the previous step. Always zero.
|
2018-02-09 03:44:23 +00:00
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
deltaY: function ()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
},
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-10-19 16:45:05 +00:00
|
|
|
* The change in this StaticBody's rotation from the previous step. Always zero.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.StaticBody#deltaZ
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-10-19 11:32:43 +00:00
|
|
|
* @return {number} The change in this StaticBody's rotation from the previous step. Always zero.
|
2018-02-09 03:44:23 +00:00
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
deltaZ: function ()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
},
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-06-13 16:41:50 +00:00
|
|
|
* Disables this Body and marks it for destruction during the next step.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.StaticBody#destroy
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
destroy: function ()
|
|
|
|
{
|
2018-02-15 01:51:36 +00:00
|
|
|
this.enable = false;
|
|
|
|
|
|
|
|
this.world.pendingDestroy.set(this);
|
2017-11-09 15:31:48 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* Draws a graphical representation of the StaticBody for visual debugging purposes.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.StaticBody#drawDebug
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-09-28 10:04:19 +00:00
|
|
|
* @param {Phaser.GameObjects.Graphics} graphic - The Graphics object to use for the debug drawing of the StaticBody.
|
2018-02-09 03:44:23 +00:00
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
drawDebug: function (graphic)
|
|
|
|
{
|
|
|
|
var pos = this.position;
|
|
|
|
|
2018-11-16 16:43:53 +00:00
|
|
|
var x = pos.x + this.halfWidth;
|
|
|
|
var y = pos.y + this.halfHeight;
|
|
|
|
|
2017-11-09 15:31:48 +00:00
|
|
|
if (this.debugShowBody)
|
|
|
|
{
|
|
|
|
graphic.lineStyle(1, this.debugBodyColor, 1);
|
2018-11-20 10:21:02 +00:00
|
|
|
|
2018-11-16 16:43:53 +00:00
|
|
|
if (this.isCircle)
|
|
|
|
{
|
|
|
|
graphic.strokeCircle(x, y, this.width / 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
graphic.strokeRect(pos.x, pos.y, this.width, this.height);
|
|
|
|
}
|
|
|
|
|
2017-11-09 15:31:48 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* Indicates whether the StaticBody is going to be showing a debug visualization during postUpdate.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.StaticBody#willDrawDebug
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-09-28 10:04:19 +00:00
|
|
|
* @return {boolean} Whether or not the StaticBody is going to show the debug visualization during postUpdate.
|
2018-02-09 03:44:23 +00:00
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
willDrawDebug: function ()
|
|
|
|
{
|
|
|
|
return this.debugShowBody;
|
|
|
|
},
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* Sets the Mass of the StaticBody. Will set the Mass to 0.1 if the value passed is less than or equal to zero.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.StaticBody#setMass
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-09-28 10:04:19 +00:00
|
|
|
* @param {number} value - The value to set the Mass to. Values of zero or less are changed to 0.1.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
2018-02-09 04:08:01 +00:00
|
|
|
* @return {Phaser.Physics.Arcade.StaticBody} This Static Body object.
|
2018-02-09 03:44:23 +00:00
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
setMass: function (value)
|
|
|
|
{
|
|
|
|
if (value <= 0)
|
|
|
|
{
|
|
|
|
// Causes havoc otherwise
|
|
|
|
value = 0.1;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.mass = value;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 04:08:01 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* The x coordinate of the StaticBody.
|
2018-02-09 04:08:01 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#x
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
x: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.position.x;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
2018-02-15 01:51:36 +00:00
|
|
|
this.world.staticTree.remove(this);
|
|
|
|
|
2017-11-09 15:31:48 +00:00
|
|
|
this.position.x = value;
|
2017-11-09 16:32:31 +00:00
|
|
|
|
|
|
|
this.world.staticTree.insert(this);
|
2017-11-09 15:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2018-02-09 04:08:01 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* The y coordinate of the StaticBody.
|
2018-02-09 04:08:01 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#y
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
y: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.position.y;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
2018-02-15 01:51:36 +00:00
|
|
|
this.world.staticTree.remove(this);
|
|
|
|
|
2017-11-09 15:31:48 +00:00
|
|
|
this.position.y = value;
|
2017-11-09 16:32:31 +00:00
|
|
|
|
|
|
|
this.world.staticTree.insert(this);
|
2017-11-09 15:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2018-02-09 04:08:01 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* Returns the left-most x coordinate of the area of the StaticBody.
|
2018-02-09 04:08:01 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#left
|
|
|
|
* @type {number}
|
2018-10-09 12:40:00 +00:00
|
|
|
* @readonly
|
2018-02-09 04:08:01 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
left: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.position.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2018-02-09 04:08:01 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* The right-most x coordinate of the area of the StaticBody.
|
2018-02-09 04:08:01 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#right
|
|
|
|
* @type {number}
|
2018-10-09 12:40:00 +00:00
|
|
|
* @readonly
|
2018-02-09 04:08:01 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
right: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.position.x + this.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2018-02-09 04:08:01 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* The highest y coordinate of the area of the StaticBody.
|
2018-02-09 04:08:01 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#top
|
|
|
|
* @type {number}
|
2018-10-09 12:40:00 +00:00
|
|
|
* @readonly
|
2018-02-09 04:08:01 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
top: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.position.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2018-02-09 04:08:01 +00:00
|
|
|
/**
|
2018-09-28 10:04:19 +00:00
|
|
|
* The lowest y coordinate of the area of the StaticBody. (y + height)
|
2018-02-09 04:08:01 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.StaticBody#bottom
|
|
|
|
* @type {number}
|
2018-10-09 12:40:00 +00:00
|
|
|
* @readonly
|
2018-02-09 04:08:01 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 15:31:48 +00:00
|
|
|
bottom: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.position.y + this.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = StaticBody;
|