From 10b3dbf74a02a2a018d1e7bee21e3f5e16af230e Mon Sep 17 00:00:00 2001 From: photonstorm Date: Thu, 27 Feb 2014 21:41:54 +0000 Subject: [PATCH] Loader.replaceInFileList wouldn't over-write the previous entry correctly, which caused the Loader.image overwrite parameter to fail (thanks basoko, fixes #493) --- README.md | 1 + src/loader/Loader.js | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c4fb1d4c..f1945108 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,7 @@ Bug Fixes: * You can now safely destroy a Group and the 'destroyChildren' boolean will propogate fully down the display list. * Calling destroy on an already destroyed object would throw a run-time error. Now checked for and aborted. * Calling destroy while in an Input Event callback now works for either the parent Group or the calling object itself. +* Loader.replaceInFileList wouldn't over-write the previous entry correctly, which caused the Loader.image overwrite parameter to fail (thanks basoko, fixes #493) TO DO: diff --git a/src/loader/Loader.js b/src/loader/Loader.js index ea196898..6008a25d 100644 --- a/src/loader/Loader.js +++ b/src/loader/Loader.js @@ -198,6 +198,31 @@ Phaser.Loader.prototype = { }, + /** + * Gets the fileList index for the given key. + * + * @method Phaser.Loader#getAssetIndex + * @param {string} type - The type asset you want to check. + * @param {string} key - Key of the asset you want to check. + * @return {number} The index of this key in the filelist, or -1 if not found. + */ + getAssetIndex: function (type, key) { + + if (this._fileList.length > 0) + { + for (var i = 0; i < this._fileList.length; i++) + { + if (this._fileList[i].type === type && this._fileList[i].key === key) + { + return i; + } + } + } + + return -1; + + }, + /** * Gets the asset that is queued for load. * @@ -302,10 +327,16 @@ Phaser.Loader.prototype = { } } - if (this.checkKeyExists(type, key) === false) + var index = this.getAssetIndex(type, key); + + if (index === -1) { this._fileList.push(entry); } + else + { + this._fileList[index] = entry; + } },