From e3480ffd3cf9790b471a3e2850e841b9ada8e169 Mon Sep 17 00:00:00 2001 From: Stefan Holmgren Date: Sun, 16 Mar 2014 12:14:46 +0100 Subject: [PATCH] Add destroy methods to Ninja Body, AABB and Circle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Sprite.destroy() method calls the Body’s destroy() method if a body exists. If using Ninja physics, destroying a Sprite will not work, since the destroy method wasn’t implemented in Ninja’s Body. Also added destroy() methods to Ninja’s AABB and Circle. Tile already have a destroy() method. --- src/physics/ninja/AABB.js | 10 ++++++++++ src/physics/ninja/Body.js | 17 ++++++++++++++++- src/physics/ninja/Circle.js | 10 ++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/physics/ninja/AABB.js b/src/physics/ninja/AABB.js index a171b2b7c..a73066584 100644 --- a/src/physics/ninja/AABB.js +++ b/src/physics/ninja/AABB.js @@ -1002,6 +1002,16 @@ Phaser.Physics.Ninja.AABB.prototype = { return Phaser.Physics.Ninja.AABB.COL_NONE; + }, + + /** + * Destroys this AABB's reference to Body and System + * + * @method Phaser.Physics.Ninja.AABB#destroy + */ + destroy: function() { + this.body = null; + this.system = null; } } diff --git a/src/physics/ninja/Body.js b/src/physics/ninja/Body.js index ea026bd7c..05126d67a 100644 --- a/src/physics/ninja/Body.js +++ b/src/physics/ninja/Body.js @@ -417,8 +417,23 @@ Phaser.Physics.Ninja.Body.prototype = { */ deltaY: function () { return this.shape.pos.y - this.shape.oldpos.y; - } + }, + /** + * Destroys this body's reference to the sprite and system, and destroys its shape. + * + * @method Phaser.Physics.Ninja.Body#destroy + */ + destroy: function() { + this.sprite = null; + this.system = null; + this.aabb = null; + this.tile = null; + this.circle = null; + + this.shape.destroy(); + this.shape = null; + } }; /** diff --git a/src/physics/ninja/Circle.js b/src/physics/ninja/Circle.js index 73dd62d59..a4ba3dbb9 100644 --- a/src/physics/ninja/Circle.js +++ b/src/physics/ninja/Circle.js @@ -2606,6 +2606,16 @@ Phaser.Physics.Ninja.Circle.prototype = { } return Phaser.Physics.Ninja.Circle.COL_NONE; + }, + + /** + * Destroys this Circle's reference to Body and System + * + * @method Phaser.Physics.Ninja.Circle#destroy + */ + destroy: function() { + this.body = null; + this.system = null; } }