ArcadePhysics.Body has a new boolean property enable. If false the body won't be checked for any collision or overlaps, or have its pre or post update methods called. Use this for easy toggling of physics bodies without having to destroy or re-create the Body object itself.

This commit is contained in:
photonstorm 2014-05-27 11:22:20 +01:00
parent 5b9bd96583
commit 9c35dfde0c
5 changed files with 15 additions and 8 deletions

View file

@ -70,6 +70,7 @@ Version 2.0.6 - "Jornhill" - -in development-
* Phaser.Keyboard.lastChar will return the string value of the last key pressed.
* Phaser.Keyboard.lastKey will return the most recently pressed Key object.
* RetroFont.updateOffset allows you to modify the offsetX/Y values used by the font during rendering.
* ArcadePhysics.Body has a new boolean property `enable`. If `false` the body won't be checked for any collision or overlaps, or have its pre or post update methods called. Use this for easy toggling of physics bodies without having to destroy or re-create the Body object itself.
### Bug Fixes

View file

@ -206,7 +206,7 @@ Phaser.Sprite.prototype.preUpdate = function() {
this._cache[1] = this.world.y;
this._cache[2] = this.rotation;
if (this.body)
if (this.body && this.body.enable)
{
this.body.preUpdate();
}
@ -281,7 +281,7 @@ Phaser.Sprite.prototype.preUpdate = function() {
this.animations.update();
if (this.body)
if (this.body && this.body.enable)
{
this.body.preUpdate();
}
@ -320,7 +320,7 @@ Phaser.Sprite.prototype.postUpdate = function() {
this.key.render();
}
if (this.exists && this.body)
if (this.exists && this.body && this.body.enable)
{
this.body.postUpdate();
}

View file

@ -173,7 +173,7 @@ Phaser.TileSprite.prototype.preUpdate = function() {
this._cache[1] = this.world.y;
this._cache[2] = this.rotation;
if (this.body)
if (this.body && this.body.enable)
{
this.body.preUpdate();
}
@ -241,7 +241,7 @@ Phaser.TileSprite.prototype.preUpdate = function() {
this.tilePosition.y += this._scroll.y * this.game.time.physicsElapsed;
}
if (this.body)
if (this.body && this.body.enable)
{
this.body.preUpdate();
}
@ -274,7 +274,7 @@ Phaser.TileSprite.prototype.update = function() {
*/
Phaser.TileSprite.prototype.postUpdate = function() {
if (this.exists && this.body)
if (this.exists && this.body && this.body.enable)
{
this.body.postUpdate();
}

View file

@ -30,6 +30,12 @@ Phaser.Physics.Arcade.Body = function (sprite) {
*/
this.type = Phaser.Physics.ARCADE;
/**
* @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;
/**
* @property {Phaser.Point} offset - The offset of the Physics Body from the Sprite x/y position.
*/

View file

@ -741,7 +741,7 @@ Phaser.Physics.Arcade.prototype = {
*/
separate: function (body1, body2, processCallback, callbackContext, overlapOnly) {
if (!this.intersects(body1, body2))
if (!body1.enable || !body2.enable || !this.intersects(body1, body2))
{
return false;
}
@ -1062,7 +1062,7 @@ Phaser.Physics.Arcade.prototype = {
separateTile: function (i, body, tile) {
// We re-check for collision in case body was separated in a previous step
if (!tile.intersects(body.position.x, body.position.y, body.right, body.bottom))
if (!body.enable || !tile.intersects(body.position.x, body.position.y, body.right, body.bottom))
{
// no collision so bail out (separted in a previous step)
return false;