If you load an image and provide a key that was already in-use in the Cache, then the old image is now destroyed (via Cache.removeImage) and the new image takes its place.

This commit is contained in:
photonstorm 2015-02-18 16:58:08 +00:00
parent 72d1c13b6b
commit 9879fc6387
2 changed files with 7 additions and 0 deletions

View file

@ -149,6 +149,7 @@ We've also removed functions and properties from Pixi classes that Phaser doesn'
* InputHandler.enableDrag with a boundsRect set now takes into account the Sprites anchor when limiting the drag (thanks @unindented #1593) * InputHandler.enableDrag with a boundsRect set now takes into account the Sprites anchor when limiting the drag (thanks @unindented #1593)
* InputHandler.enableDrag with a boundsSprite set now takes into account both the Sprites anchor and the boundsSprite anchor when limiting the drag. * InputHandler.enableDrag with a boundsSprite set now takes into account both the Sprites anchor and the boundsSprite anchor when limiting the drag.
* Sound in Web Audio now uses AudioContext.onended to trigger when it will stop playing instead of using a time based value. This is only used if the sound doesn't loop and isn't an audio sprite, but will give a much more accurate `Sound.onStop` event. It also prevents short audio files from being cut off during playback (#1471) and accounts for time spent decoding. * Sound in Web Audio now uses AudioContext.onended to trigger when it will stop playing instead of using a time based value. This is only used if the sound doesn't loop and isn't an audio sprite, but will give a much more accurate `Sound.onStop` event. It also prevents short audio files from being cut off during playback (#1471) and accounts for time spent decoding.
* If you load an image and provide a key that was already in-use in the Cache, then the old image is now destroyed (via `Cache.removeImage`) and the new image takes its place.
### Bug Fixes ### Bug Fixes

View file

@ -495,6 +495,7 @@ Phaser.Cache.prototype = {
/** /**
* Adds an Image file into the Cache. The file must have already been loaded, typically via Phaser.Loader, but can also have been loaded into the DOM. * Adds an Image file into the Cache. The file must have already been loaded, typically via Phaser.Loader, but can also have been loaded into the DOM.
* If an image already exists in the cache with the same key then it is removed and destroyed, and the new image inserted in its place.
* *
* @method Phaser.Cache#addImage * @method Phaser.Cache#addImage
* @param {string} key - The unique key by which you will reference this object. * @param {string} key - The unique key by which you will reference this object.
@ -503,6 +504,11 @@ Phaser.Cache.prototype = {
*/ */
addImage: function (key, url, data) { addImage: function (key, url, data) {
if (this.checkImageKey(key))
{
this.removeImage(key);
}
this._images[key] = { url: url, data: data }; this._images[key] = { url: url, data: data };
this._images[key].frame = new Phaser.Frame(0, 0, 0, data.width, data.height, key, this.game.rnd.uuid()); this._images[key].frame = new Phaser.Frame(0, 0, 0, data.width, data.height, key, this.game.rnd.uuid());