Skip to content

Commit

Permalink
Merge pull request #961 from Phaiax/issue-bodyEnable
Browse files Browse the repository at this point in the history
Body.enable only exists in Arcade physics, so move conditions concerning...
  • Loading branch information
photonstorm committed Jul 1, 2014
2 parents 8c11ec1 + 00bf349 commit 7fa3110
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
16 changes: 8 additions & 8 deletions src/gameobjects/Sprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Phaser.Sprite = function (game, x, y, key, frame) {

/**
* A small internal cache:
*
*
* 0 = previous position.x
* 1 = previous position.y
* 2 = previous rotation
Expand Down Expand Up @@ -209,7 +209,7 @@ Phaser.Sprite.prototype.preUpdate = function() {
this._cache[1] = this.world.y;
this._cache[2] = this.rotation;

if (this.body && this.body.enable)
if (this.body)
{
this.body.preUpdate();
}
Expand Down Expand Up @@ -284,7 +284,7 @@ Phaser.Sprite.prototype.preUpdate = function() {

this.animations.update();

if (this.body && this.body.enable)
if (this.body)
{
this.body.preUpdate();
}
Expand Down Expand Up @@ -323,7 +323,7 @@ Phaser.Sprite.prototype.postUpdate = function() {
this.key.render();
}

if (this.exists && this.body && this.body.enable)
if (this.exists && this.body)
{
this.body.postUpdate();
}
Expand Down Expand Up @@ -355,7 +355,7 @@ Phaser.Sprite.prototype.postUpdate = function() {
Phaser.Sprite.prototype.loadTexture = function (key, frame) {

frame = frame || 0;

this.key = key;

if (key instanceof Phaser.RenderTexture)
Expand Down Expand Up @@ -531,10 +531,10 @@ Phaser.Sprite.prototype.updateCrop = function() {
/**
* Crop allows you to crop the texture used to display this Sprite.
* This modifies the core Sprite texture frame, so the Sprite width/height properties will adjust accordingly.
*
*
* Cropping takes place from the top-left of the Sprite and can be modified in real-time by either providing an updated rectangle object to Sprite.crop,
* or by modifying Sprite.cropRect (or a reference to it) and then calling Sprite.updateCrop.
*
*
* The rectangle object given to this method can be either a Phaser.Rectangle or any object so long as it has public x, y, width and height properties.
* A reference to the rectangle is stored in Sprite.cropRect unless the `copy` parameter is `true` in which case the values are duplicated to a local object.
*
Expand Down Expand Up @@ -809,7 +809,7 @@ Phaser.Sprite.prototype.play = function (name, frameRate, loop, killOnComplete)
* Checks to see if the bounds of this Sprite overlaps with the bounds of the given Display Object, which can be a Sprite, Image, TileSprite or anything that extends those such as a Button.
* This check ignores the Sprites hitArea property and runs a Sprite.getBounds comparison on both objects to determine the result.
* Therefore it's relatively expensive to use in large quantities (i.e. with lots of Sprites at a high frequency), but should be fine for low-volume testing where physics isn't required.
*
*
* @method Phaser.Sprite#overlap
* @memberof Phaser.Sprite
* @param {Phaser.Sprite|Phaser.Image|Phaser.TileSprite|Phaser.Button|PIXI.DisplayObject} displayObject - The display object to check against.
Expand Down
12 changes: 6 additions & 6 deletions src/gameobjects/TileSprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ Phaser.TileSprite.prototype.preUpdate = function() {
this._cache[1] = this.world.y;
this._cache[2] = this.rotation;

if (this.body && this.body.enable)
if (this.body)
{
this.body.preUpdate();
}
Expand Down Expand Up @@ -241,7 +241,7 @@ Phaser.TileSprite.prototype.preUpdate = function() {
this.tilePosition.y += this._scroll.y * this.game.time.physicsElapsed;
}

if (this.body && this.body.enable)
if (this.body)
{
this.body.preUpdate();
}
Expand Down Expand Up @@ -274,7 +274,7 @@ Phaser.TileSprite.prototype.update = function() {
*/
Phaser.TileSprite.prototype.postUpdate = function() {

if (this.exists && this.body && this.body.enable)
if (this.exists && this.body)
{
this.body.postUpdate();
}
Expand Down Expand Up @@ -333,7 +333,7 @@ Phaser.TileSprite.prototype.stopScroll = function() {
Phaser.TileSprite.prototype.loadTexture = function (key, frame) {

frame = frame || 0;

this.key = key;

if (key instanceof Phaser.RenderTexture)
Expand Down Expand Up @@ -496,7 +496,7 @@ Phaser.TileSprite.prototype.play = function (name, frameRate, loop, killOnComple
* Resets the TileSprite. This places the TileSprite at the given x/y world coordinates, resets the tilePosition and then
* sets alive, exists, visible and renderable all to true. Also resets the outOfBounds state.
* If the TileSprite has a physics body that too is reset.
*
*
* @method Phaser.TileSprite#reset
* @memberof Phaser.TileSprite
* @param {number} x - The x coordinate (in world space) to position the Sprite at.
Expand Down Expand Up @@ -525,7 +525,7 @@ Phaser.TileSprite.prototype.reset = function(x, y) {
this._cache[4] = 1;

return this;

};

/**
Expand Down
12 changes: 11 additions & 1 deletion src/physics/arcade/Body.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@ Phaser.Physics.Arcade.Body.prototype = {
*/
preUpdate: function () {

if (!this.enable)
{
return;
}

this.phase = 1;

// Store and reset collision flags
Expand Down Expand Up @@ -440,6 +445,11 @@ Phaser.Physics.Arcade.Body.prototype = {
*/
postUpdate: function () {

if (!this.enable)
{
return;
}

// Only allow postUpdate to be called once per frame
if (this.phase === 2)
{
Expand Down Expand Up @@ -612,7 +622,7 @@ Phaser.Physics.Arcade.Body.prototype = {

this._sx = this.sprite.scale.x;
this._sy = this.sprite.scale.y;

this.center.setTo(this.position.x + this.halfWidth, this.position.y + this.halfHeight);

},
Expand Down

0 comments on commit 7fa3110

Please sign in to comment.