mirror of
https://github.com/wassname/phaser.git
synced 2026-07-11 00:40:20 +08:00
Updated docs and more tidying up.
This commit is contained in:
+322
-77
@@ -226,6 +226,10 @@
|
||||
<a href="Phaser.Physics.Arcade.html">Arcade</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Physics.Arcade.Body.html">Body</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Plugin.html">Plugin</a>
|
||||
</li>
|
||||
@@ -344,82 +348,18 @@
|
||||
|
||||
<ul class="dropdown-menu ">
|
||||
|
||||
<li>
|
||||
<a href="global.html#audio">audio</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#bitmapText">bitmapText</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#bottom">bottom</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#button">button</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#child">child</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#emitter">emitter</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#existing.">existing.</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#graphics">graphics</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#group">group</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#HEXtoRGB">HEXtoRGB</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#renderTexture">renderTexture</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#right">right</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#sprite">sprite</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#text">text</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#tilemap">tilemap</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#tilemaplayer">tilemaplayer</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#tileset">tileset</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#tileSprite">tileSprite</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#tween">tween</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -441,87 +381,321 @@
|
||||
|
||||
<section>
|
||||
<article>
|
||||
<pre class="sunlight-highlight-javascript linenums">Phaser.Physics.Arcade.Body = function (sprite) {
|
||||
<pre class="sunlight-highlight-javascript linenums">/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @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)
|
||||
@@ -536,6 +710,12 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Internal method.
|
||||
*
|
||||
* @method Phaser.Physics.Arcade#preUpdate
|
||||
* @protected
|
||||
*/
|
||||
preUpdate: function () {
|
||||
|
||||
// Store and reset collision flags
|
||||
@@ -574,8 +754,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)
|
||||
{
|
||||
@@ -586,6 +765,12 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Internal method.
|
||||
*
|
||||
* @method Phaser.Physics.Arcade#postUpdate
|
||||
* @protected
|
||||
*/
|
||||
postUpdate: function () {
|
||||
|
||||
// Calculate forward-facing edge
|
||||
@@ -626,6 +811,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);
|
||||
@@ -633,6 +824,12 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Internal method.
|
||||
*
|
||||
* @method Phaser.Physics.Arcade#checkWorldBounds
|
||||
* @protected
|
||||
*/
|
||||
checkWorldBounds: function () {
|
||||
|
||||
if (this.x < this.game.world.bounds.x)
|
||||
@@ -659,6 +856,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;
|
||||
@@ -674,6 +882,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);
|
||||
@@ -691,18 +904,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;
|
||||
},
|
||||
@@ -713,6 +950,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", {
|
||||
|
||||
/**
|
||||
@@ -744,6 +985,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", {
|
||||
|
||||
/**
|
||||
@@ -797,7 +1042,7 @@ Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "right", {
|
||||
|
||||
<span class="jsdoc-message">
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-dev</a>
|
||||
on Fri Oct 25 2013 16:16:43 GMT+0100 (BST) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
|
||||
on Fri Oct 25 2013 17:05:24 GMT+0100 (BST) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
|
||||
</span>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user