From 66bdf56349d3e4367d3abcc2e3ba28ab3e2907cd Mon Sep 17 00:00:00 2001 From: photonstorm <rdavey@gmail.com> Date: Sun, 2 Mar 2014 11:04:04 +0000 Subject: [PATCH] The physics world is now cleared on state swap (fixes #505) --- src/core/StateManager.js | 5 +++++ src/physics/World.js | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/core/StateManager.js b/src/core/StateManager.js index 4416f7e5a..bffda116c 100644 --- a/src/core/StateManager.js +++ b/src/core/StateManager.js @@ -286,6 +286,11 @@ Phaser.StateManager.prototype = { this.game.world.destroy(); + if (this.game.physics) + { + this.game.physics.clear(); + } + if (this._clearCache === true) { this.game.cache.destroy(); diff --git a/src/physics/World.js b/src/physics/World.js index 4957303ae..2ca0a844b 100644 --- a/src/physics/World.js +++ b/src/physics/World.js @@ -455,6 +455,19 @@ Phaser.Physics.World.prototype = { }, /** + * Clears all bodies from the simulation. + * + * @method Phaser.Physics.World#clear + */ + clear: function () { + + this.world.clear(); + + }, + + /** + * Clears all bodies from the simulation and unlinks World from Game. Should only be called on game shutdown. Call `clear` on a State change. + * * @method Phaser.Physics.World#destroy */ destroy: function () {