Skip to content

Commit

Permalink
Add Cache#destroyItem
Browse files Browse the repository at this point in the history
Call `destroy` on any `base`, `data`, `frameData`, `texture` properties.
  • Loading branch information
samme committed Mar 26, 2017
1 parent 3e3fc2c commit 0006372
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/loader/Cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ Phaser.Cache.prototype = {
{
this.removeImage(key);
}

var data = (extension in Phaser.LoaderParser) ? Phaser.LoaderParser[extension](arrayBuffer) : arrayBuffer;

var texture = {
Expand Down Expand Up @@ -541,9 +541,9 @@ Phaser.Cache.prototype = {

/**
* Add a new Bitmap Font to the Cache, where the font texture is part of a Texture Atlas.
*
*
* The atlas must already exist in the cache, and be available based on the given `atlasKey`.
*
*
* The `atlasFrame` specifies the name of the frame within the atlas that the Bitmap Font is
* stored in.
*
Expand Down Expand Up @@ -2057,10 +2057,7 @@ Phaser.Cache.prototype = {
{
if (key !== '__default' && key !== '__missing')
{
if (cache[key]['destroy'])
{
cache[key].destroy();
}
this.destroyItem(cache[key]);

delete cache[key];
}
Expand All @@ -2071,6 +2068,29 @@ Phaser.Cache.prototype = {
this._urlResolver = null;
this._urlTemp = null;

},

/**
* @method Phaser.Cache#destroyItem
* @private
* @param {object} item
*/
destroyItem: function (item) {

var keys = ['base', 'data', 'frameData', 'texture'];

if (item.destroy)
{
item.destroy();
}
else
{
if (item.base && item.base.destroy) item.base.destroy();
if (item.data && item.data.destroy) item.data.destroy();
if (item.frameData && item.frameData.destroy) item.frameData.destroy();
if (item.texture && item.texture.destroy) item.texture.destroy(true);
}

}

};
Expand Down

0 comments on commit 0006372

Please sign in to comment.