SoundManager.destroy is a new method that will destroy all current sounds and reset any callbacks.

StateManager.clearCurrentState now handles the process of clearing down the current state and is now called if the Game is destroyed.
Game.destroy now clears the current state, activating its shutdown callback if it had one. It also now destroys the SoundManager, stopping any currently running sounds (#1092)
This commit is contained in:
photonstorm 2014-08-29 11:37:47 +01:00
parent 69b9e5eb7c
commit 26a55bd202
4 changed files with 70 additions and 29 deletions

View file

@ -93,6 +93,9 @@ Version 2.1.0 - "Cairhien" - -in development-
* P2.PointProxy.mx and my values are get and set in meters with no pixel conversion taking place.
* P2.InversePointProxy.mx and my values are get and set in meters with no pixel conversion taking place.
* Pointer.dirty is a new boolean that is set by the InputHandler. It tells the Pointer to re-check all interactive objects it may be over on the next update, regardless if it has moved position or not. This helps solve issues where you may have a Button that on click generates a pop-up window that now obscures the Button (thanks @jflowers45 #882)
* SoundManager.destroy is a new method that will destroy all current sounds and reset any callbacks.
* StateManager.clearCurrentState now handles the process of clearing down the current state and is now called if the Game is destroyed.
* Game.destroy now clears the current state, activating its shutdown callback if it had one. It also now destroys the SoundManager, stopping any currently running sounds (#1092)
### Updates

View file

@ -741,7 +741,7 @@ Phaser.Game.prototype = {
},
/**
* Nuke the entire game from orbit
* Nukes the entire game from orbit.
*
* @method Phaser.Game#destroy
*/
@ -749,10 +749,12 @@ Phaser.Game.prototype = {
this.raf.stop();
this.state.destroy();
this.sound.destroy();
this.scale.destroy();
this.stage.destroy();
this.input.destroy();
this.state.destroy();
this.physics.destroy();
this.state = null;

View file

@ -305,33 +305,7 @@ Phaser.StateManager.prototype = {
if (this._pendingState && this.game.isBooted)
{
// Already got a state running?
if (this.current)
{
if (this.onShutDownCallback)
{
this.onShutDownCallback.call(this.callbackContext, this.game);
}
this.game.tweens.removeAll();
this.game.camera.reset();
this.game.input.reset(true);
this.game.physics.clear();
this.game.time.removeAll();
if (this._clearWorld)
{
this.game.world.shutdown();
if (this._clearCache === true)
{
this.game.cache.destroy();
}
}
}
this.clearCurrentState();
this.setCurrentState(this._pendingState);
@ -365,6 +339,44 @@ Phaser.StateManager.prototype = {
},
/**
* This method clears the current State, calling its shutdown callback. The process also removes any active tweens,
* resets the camera, resets input, clears physics, removes timers and if set clears the world and cache too.
*
* @method Phaser.StateManager#clearCurrentState
*/
clearCurrentState: function () {
if (this.current)
{
if (this.onShutDownCallback)
{
this.onShutDownCallback.call(this.callbackContext, this.game);
}
this.game.tweens.removeAll();
this.game.camera.reset();
this.game.input.reset(true);
this.game.physics.clear();
this.game.time.removeAll();
if (this._clearWorld)
{
this.game.world.shutdown();
if (this._clearCache === true)
{
this.game.cache.destroy();
}
}
}
},
/**
* Checks if a given phaser state is valid. A State is considered valid if it has at least one of the core functions: preload, create, update or render.
*
@ -614,6 +626,8 @@ Phaser.StateManager.prototype = {
*/
destroy: function () {
this.clearCurrentState();
this.callbackContext = null;
this.onInitCallback = null;

View file

@ -500,6 +500,28 @@ Phaser.SoundManager.prototype = {
}
}
},
/**
* Stops all the sounds in the game, then destroys them and finally clears up any callbacks.
*
* @method Phaser.SoundManager#destroy
*/
destroy: function () {
this.stopAll();
for (var i = 0; i < this._sounds.length; i++)
{
if (this._sounds[i])
{
this._sounds[i].destroy();
}
}
this._sounds = [];
this.onSoundDecode.dispose();
}
};