mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 21:24:09 +00:00
Loader.resetLocked is a boolean that allows you to control what happens when the loader is reset, *which happens automatically on a State change*. If you set resetLocked
to true
it allows you to populate the loader queue in one State, then swap to another State without having the queue erased, and start the load going from there. After the load has completed you could then disable the lock again as needed.
Loader.reset has a new optional 2nd parameter `clearEvents` which if set to `true` (the default is false) will reset all event listeners bound to the Loader.
This commit is contained in:
parent
ec732e497f
commit
c154b8c785
2 changed files with 40 additions and 6 deletions
|
@ -80,7 +80,9 @@ The URL is always transformed through transformUrl, which can make adding some o
|
|||
|
||||
This also incorporates the fast-cache path for Images tags that can greatly speed up the responsiveness of image loading.
|
||||
|
||||
Thanks to @pnstickne for this update.
|
||||
Loader.resetLocked is a boolean that allows you to control what happens when the loader is reset, *which happens automatically on a State change*. If you set `resetLocked` to `true` it allows you to populate the loader queue in one State, then swap to another State without having the queue erased, and start the load going from there. After the load has completed you could then disable the lock again as needed.
|
||||
|
||||
Thanks to @pnstickne for vast majority of this update.
|
||||
|
||||
### New Features
|
||||
|
||||
|
@ -113,6 +115,7 @@ Thanks to @pnstickne for this update.
|
|||
* Body.reset now resets the Body.speed value to zero.
|
||||
* Device.touch checks if `window.navigator.maxTouchPoints` is `>= 1` rather than > 1, which now allows touch events to work properly in Chrome mobile emulation.
|
||||
* Loader.XDomainRequest wasn't used for atlas json loading. It has now been moved to the `xhrLoad` method to ensure it's used for all request if required (thanks @draconisNoctis #1601)
|
||||
* Loader.reset has a new optional 2nd parameter `clearEvents` which if set to `true` (the default is false) will reset all event listeners bound to the Loader.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
|
|
|
@ -28,6 +28,13 @@ Phaser.Loader = function (game) {
|
|||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* If true all calls to Loader.reset will be ignored. Useful if you need to create a load queue before swapping to a preloader state.
|
||||
* @property {boolean} resetLocked
|
||||
* @default
|
||||
*/
|
||||
this.resetLocked = false;
|
||||
|
||||
/**
|
||||
* True if the Loader is in the process of loading the queue.
|
||||
* @property {boolean} isLoading
|
||||
|
@ -396,15 +403,25 @@ Phaser.Loader.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Reset the loader and clear any queued assets.
|
||||
* Reset the loader and clear any queued assets. If `Loader.resetLocked` is true this operation will abort.
|
||||
*
|
||||
* This will abort any loading and clear any queued assets.
|
||||
*
|
||||
* Optionally you can clear any associated events.
|
||||
*
|
||||
* @method Phaser.Loader#reset
|
||||
* @protected
|
||||
* @param {boolean} [hard=false] - If true then the preload sprite and other artifacts may also be cleared.
|
||||
* @param {boolean} [clearEvents=false] - If true then the all Loader signals will have removeAll called on them.
|
||||
*/
|
||||
reset: function (hard) {
|
||||
reset: function (hard, clearEvents) {
|
||||
|
||||
if (typeof clearEvents === 'undefined') { clearEvents = false; }
|
||||
|
||||
if (this.resetLocked)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (hard)
|
||||
{
|
||||
|
@ -423,6 +440,16 @@ Phaser.Loader.prototype = {
|
|||
this._loadedPackCount = 0;
|
||||
this._loadedFileCount = 0;
|
||||
|
||||
if (clearEvents)
|
||||
{
|
||||
this.onLoadStart.removeAll();
|
||||
this.onLoadComplete.removeAll();
|
||||
this.onPackComplete.removeAll();
|
||||
this.onFileStart.removeAll();
|
||||
this.onFileComplete.removeAll();
|
||||
this.onFileError.removeAll();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -757,14 +784,14 @@ Phaser.Loader.prototype = {
|
|||
* @method Phaser.Loader#audiosprite
|
||||
* @param {string} key - Unique asset key of the audio file.
|
||||
* @param {Array|string} urls - An array containing the URLs of the audio files, i.e.: [ 'audiosprite.mp3', 'audiosprite.ogg', 'audiosprite.m4a' ] or a single string containing just one URL.
|
||||
* @param {string} atlasURL - The URL of the audiosprite configuration json.
|
||||
* @param {string} jsonURL - The URL of the audiosprite configuration json.
|
||||
* @return {Phaser.Loader} This Loader instance.
|
||||
*/
|
||||
audiosprite: function(key, urls, atlasURL) {
|
||||
audiosprite: function(key, urls, jsonURL) {
|
||||
|
||||
this.audio(key, urls);
|
||||
|
||||
this.json(key + '-audioatlas', atlasURL);
|
||||
this.json(key + '-audioatlas', jsonURL);
|
||||
|
||||
return this;
|
||||
|
||||
|
@ -1398,6 +1425,10 @@ Phaser.Loader.prototype = {
|
|||
this.audio(file.key, file.urls, file.autoDecode);
|
||||
break;
|
||||
|
||||
case "audiosprite":
|
||||
this.audio(file.key, file.urls, file.jsonURL);
|
||||
break;
|
||||
|
||||
case "tilemap":
|
||||
this.tilemap(file.key, file.url, file.data, Phaser.Tilemap[file.format]);
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue