Skip to content

Commit b00c4ad

Browse files
committed
Loader - state bug fixes
More updates for phaserjs#1330 Fixed several issues with state clearing (or lack of) resulting in incorrect behavior if the loader was re-used.
1 parent 4d16af0 commit b00c4ad

1 file changed

Lines changed: 23 additions & 17 deletions

File tree

src/loader/Loader.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -331,24 +331,28 @@ Phaser.Loader.prototype = {
331331
},
332332

333333
/**
334-
* Reset the loader. This will abort any loading and clear any queued assets.
334+
* Reset the loader.
335335
*
336-
* This also clears the `preloadSprite` property.
337-
*
338-
* This will also suppress all further loading events.
336+
* This will abort any loading and clear any queued assets.
339337
*
340338
* @method Phaser.Loader#reset
339+
* @protected
340+
* @param {boolean} [hard=false] - If true then the sprite preload and other artifacts may also be cleared.
341341
*/
342-
reset: function () {
342+
reset: function (hard) {
343+
344+
if (hard)
345+
{
346+
this.preloadSprite = null;
347+
}
343348

344-
this.preloadSprite = null;
345349
this.isLoading = false;
346350

347351
this._processingHead = 0;
348-
349352
this._fileList.length = 0;
350353
this._flightQueue.length = 0;
351354

355+
this._fileLoadStarted = false;
352356
this._totalFileCount = 0;
353357
this._totalPackCount = 0;
354358
this._loadedPackCount = 0;
@@ -962,7 +966,7 @@ Phaser.Loader.prototype = {
962966
},
963967

964968
/**
965-
* Remove all file loading requests - this is insufficient to clear loading. Use `reset` instead.
969+
* Remove all file loading requests - this is _insufficient_ to clear loading. Use `reset` instead.
966970
*
967971
* @method Phaser.Loader#removeAll
968972
* @protected
@@ -986,6 +990,7 @@ Phaser.Loader.prototype = {
986990
return;
987991
}
988992

993+
this.hasLoaded = false;
989994
this.isLoading = true;
990995

991996
this.updateProgress();
@@ -1032,19 +1037,20 @@ Phaser.Loader.prototype = {
10321037
if (file.error)
10331038
{
10341039
this.onFileError.dispatch(file.key, file);
1035-
if (file.type === 'packfile')
1036-
{
1037-
this._loadedPackCount++;
1038-
this.onPackComplete.dispatch(file.key, !file.error, this._loadedPackCount, this._totalPackCount);
1039-
}
10401040
}
10411041

1042-
// Non-error pack files are handled when processing the file list below
10431042
if (file.type !== 'packfile')
10441043
{
10451044
this._loadedFileCount++;
10461045
this.onFileComplete.dispatch(this.progress, file.key, !file.error, this._loadedFileCount, this._totalFileCount);
10471046
}
1047+
else if (file.type === 'packfile' && file.error)
1048+
{
1049+
// Non-error pack files are handled when processing the file queue below
1050+
this._loadedPackCount++;
1051+
this.onPackComplete.dispatch(file.key, !file.error, this._loadedPackCount, this._totalPackCount);
1052+
}
1053+
10481054
}
10491055
}
10501056

@@ -1157,10 +1163,10 @@ Phaser.Loader.prototype = {
11571163
this.hasLoaded = true;
11581164
this.isLoading = false;
11591165

1160-
this.removeAll();
1161-
11621166
this.onLoadComplete.dispatch();
11631167

1168+
this.reset();
1169+
11641170
},
11651171

11661172
/**
@@ -1964,7 +1970,7 @@ Phaser.Loader.prototype = {
19641970
Object.defineProperty(Phaser.Loader.prototype, "progressFloat", {
19651971

19661972
get: function () {
1967-
var progress = this._loadedFileCount / this._totalFileCount;
1973+
var progress = (this._loadedFileCount / this._totalFileCount) * 100;
19681974
return Phaser.Math.clamp(progress || 0, 0, 100);
19691975
}
19701976

0 commit comments

Comments
 (0)