Added TextureManager.removeKey method and invoke it from Texture.destroy. Fix #4461

This commit is contained in:
Richard Davey 2019-04-06 11:35:58 +01:00
parent 199f5989e6
commit 382fed3de7
3 changed files with 25 additions and 2 deletions

View file

@ -60,6 +60,7 @@ Notes:
* `Tween.remove` is a new method that immediately removes the Tween from the TweenManager, regardless of what state the tween is in. Once called the tween will no longer exist within any internal TweenManager arrays.
* `SceneManager.isPaused` is a new method that will return if the given Scene is currently paused or not (thanks @samme)
* `ScenePlugin.isPaused` is a new method that will return if the given Scene is currently paused or not (thanks @samme)
* `TextureManager.removeKey` is a new method that will remove a key from the Texture Manager without destroying the texture itself.
### Updates
@ -73,6 +74,7 @@ Notes:
* The `Clock.now` property value is now synced to be the `TimeStep.time` value when the Clock plugin boots and is no longer `Date.now()` until the first update (thanks @Antriel)
* `Graphics.strokePoints` has renamed the second argument from `autoClose` to `closeShape`. There is also a new third argument `closePath`, which defaults to `true` and automatically closes the path before stroking it. The `endIndex` argument is now the fourth argument, instead of the third.
* `Graphics.fillPoints` has renamed the second argument from `autoClose` to `closeShape`. There is also a new third argument `closePath`, which defaults to `true` and automatically closes the path before filling it. The `endIndex` argument is now the fourth argument, instead of the third.
* Calling `Texture.destroy` will now call `TextureManager.removeKey` to ensure the key is removed from the manager, should you destroy a texture directly, rather than going via `TextureManager.remove`. Fix #4461 (thanks @BigZaphod)
### Bug Fixes

View file

@ -461,6 +461,9 @@ var Texture = new Class({
this.source = [];
this.dataSource = [];
this.frames = {};
this.manager.removeKey(this.key);
this.manager = null;
}

View file

@ -213,8 +213,6 @@ var TextureManager = new Class({
// By this point key should be a Texture, if not, the following fails anyway
if (this.list.hasOwnProperty(key.key))
{
delete this.list[key.key];
key.destroy();
this.emit(Events.REMOVE, key.key);
@ -223,6 +221,26 @@ var TextureManager = new Class({
return this;
},
/**
* Removes a key from the Texture Manager but does not destroy the Texture that was using the key.
*
* @method Phaser.Textures.TextureManager#removeKey
* @since 3.17.0
*
* @param {string} key - The key to remove from the texture list.
*
* @return {Phaser.Textures.TextureManager} The Texture Manager.
*/
removeKey: function (key)
{
if (this.list.hasOwnProperty(key))
{
delete this.list[key];
}
return this;
},
/**
* Adds a new Texture to the Texture Manager created from the given Base64 encoded data.
*