Skip to content

Commit 9995edb

Browse files
committed
Loader - documentation
Updated/corrected various documentation.
1 parent 7889739 commit 9995edb

1 file changed

Lines changed: 44 additions & 31 deletions

File tree

src/loader/Loader.js

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
/**
99
* The Loader handles loading all external content such as Images, Sounds, Texture Atlases and data files.
10-
* It uses a combination of Image() loading and xhr and provides progress and completion callbacks.
10+
* It uses a combination of tag loading (eg. Image elements) and XHR and provides progress and completion callbacks.
1111
*
1212
* @class Phaser.Loader
1313
* @constructor
@@ -32,13 +32,13 @@ Phaser.Loader = function (game) {
3232
*/
3333
this.hasLoaded = false;
3434

35-
/**
35+
/**
3636
* You can optionally link a sprite to the preloader.
3737
*
3838
* The Sprites width or height will be cropped based on the percentage loaded.
3939
* This property is an object containing: sprite, rect, direction, width and height
4040
*
41-
* @property {object} preloadSprite
41+
* @property {?object} preloadSprite
4242
*/
4343
this.preloadSprite = null;
4444

@@ -50,14 +50,14 @@ Phaser.Loader = function (game) {
5050

5151
/**
5252
* If you want to append a URL before the path of any asset you can set this here.
53-
* Useful if you need to allow an asset url to be configured outside of the game code.
54-
* MUST have / on the end of it!
53+
* Useful if allowing the asset base url to be configured outside of the game code.
54+
* The string _must_ end an "/".
5555
* @property {string} baseURL
5656
*/
5757
this.baseURL = '';
5858

5959
/**
60-
* This event is dispatched when the loading process starts, before the first file has been requested
60+
* This event is dispatched when the loading process starts: before the first file has been requested,
6161
* but after all the initial packs have been loaded.
6262
*
6363
* @property {Phaser.Signal} onLoadStart
@@ -81,7 +81,8 @@ Phaser.Loader = function (game) {
8181
this.onPackComplete = new Phaser.Signal();
8282

8383
/**
84-
* This event is dispatched immediately before a file starts loading. It's possible the file may still error (404, etc) after this event is sent.
84+
* This event is dispatched immediately before a file starts loading.
85+
* It's possible the file may fail (eg. download error, invalid format) after this event is sent.
8586
*
8687
* Params: `(progress, file key, file url)`
8788
*
@@ -161,8 +162,7 @@ Phaser.Loader = function (game) {
161162

162163
/**
163164
* True when the first file (not pack) has loading started.
164-
* This used to to control disoatching `onLoadStart` which happens after any initial
165-
* packs are loaded.
165+
* This used to to control dispatching `onLoadStart` which happens after any initial packs are loaded.
166166
*
167167
* @property {boolean} _initialPacksLoaded
168168
* @private
@@ -232,9 +232,12 @@ Phaser.Loader.PHYSICS_PHASER_JSON = 4;
232232
Phaser.Loader.prototype = {
233233

234234
/**
235-
* You can set a Sprite to be a "preload" sprite by passing it to this method.
235+
* Set a Sprite to be a "preload" sprite by passing it to this method.
236+
*
236237
* A "preload" sprite will have its width or height crop adjusted based on the percentage of the loader in real-time.
237-
* This allows you to easily make loading bars for games. Note that Sprite.visible = true will be set when calling this.
238+
* This allows you to easily make loading bars for games.
239+
*
240+
* The sprite will automatically be made visible when calling this.
238241
*
239242
* @method Phaser.Loader#setPreloadSprite
240243
* @param {Phaser.Sprite|Phaser.Image} sprite - The sprite or image that will be cropped during the load.
@@ -265,9 +268,11 @@ Phaser.Loader.prototype = {
265268

266269
/**
267270
* Called automatically by ScaleManager when the game resizes in RESIZE scalemode.
271+
*
268272
* We use this to adjust the height of the preloading sprite, if set.
269273
*
270274
* @method Phaser.Loader#resize
275+
* @protected
271276
*/
272277
resize: function () {
273278

@@ -279,8 +284,9 @@ Phaser.Loader.prototype = {
279284
},
280285

281286
/**
282-
* Check whether asset exists with a specific key.
283-
* Use Phaser.Cache to access loaded assets, e.g. Phaser.Cache#checkImageKey
287+
* Check whether a file/asset with a specific key is queued to be loaded.
288+
*
289+
* To access a loaded asset use Phaser.Cache, eg. {@link Phaser.Cache#checkImageKey}
284290
*
285291
* @method Phaser.Loader#checkKeyExists
286292
* @param {string} type - The type asset you want to check.
@@ -294,12 +300,15 @@ Phaser.Loader.prototype = {
294300
},
295301

296302
/**
297-
* Gets the fileList index for the given key.
303+
* Get the queue-index of the file/asset with a specific key.
304+
*
305+
* Only assets in the download file queue will be found.
298306
*
299307
* @method Phaser.Loader#getAssetIndex
300308
* @param {string} type - The type asset you want to check.
301309
* @param {string} key - Key of the asset you want to check.
302310
* @return {number} The index of this key in the filelist, or -1 if not found.
311+
* The index may change and should only be used immediately following this call
303312
*/
304313
getAssetIndex: function (type, key) {
305314

@@ -316,12 +325,14 @@ Phaser.Loader.prototype = {
316325
},
317326

318327
/**
319-
* Gets the asset that is queued for load.
328+
* Find a file/asset with a specific key.
329+
*
330+
* Only assets in the download file queue will be found.
320331
*
321332
* @method Phaser.Loader#getAsset
322333
* @param {string} type - The type asset you want to check.
323334
* @param {string} key - Key of the asset you want to check.
324-
* @return {any} Returns an object if found that has 2 properties: index and asset entry. Otherwise false.
335+
* @return {any} Returns an object if found that has 2 properties: `index` and `file`; otherwise a non-true value is returned.
325336
* The index may change and should only be used immediately following this call.
326337
*/
327338
getAsset: function (type, key) {
@@ -448,7 +459,7 @@ Phaser.Loader.prototype = {
448459
* @param {string} key - Unique asset key of this resource pack.
449460
* @param {string} [url] - URL of the Asset Pack JSON file. If you wish to pass a json object instead set this to null and pass the object as the data parameter.
450461
* @param {object} [data] - The Asset Pack JSON data. Use this to pass in a json data object rather than loading it from a URL. TODO
451-
* @param {object} [callbackContext] - Some Loader operations, like Binary and Script require a context for their callbacks. Pass the context here.
462+
* @param {object} [callbackContext=(loader)] - Some Loader operations, like Binary and Script require a context for their callbacks. Pass the context here.
452463
* @return {Phaser.Loader} This Loader instance.
453464
*/
454465
pack: function (key, url, data, callbackContext) {
@@ -593,7 +604,7 @@ Phaser.Loader.prototype = {
593604
* @param {string} key - Unique asset key of the script file.
594605
* @param {string} url - URL of the JavaScript file.
595606
* @param {function} [callback=(none)] - Optional callback that will be called after the script tag has loaded, so you can perform additional processing.
596-
* @param {object} [callbackContext=(Loader)] - The context under which the callback will be applied. If not specified it will use the callback itself as the context.
607+
* @param {object} [callbackContext=(loader)] - The context under which the callback will be applied. If not specified it will use the callback itself as the context.
597608
* @return {Phaser.Loader} This Loader instance.
598609
*/
599610
script: function (key, url, callback, callbackContext) {
@@ -681,17 +692,17 @@ Phaser.Loader.prototype = {
681692
},
682693

683694
/**
684-
* Add a new audiosprite file to the loader.
685-
*
686-
* Audio Sprites are a combination of audio files and a JSON configuration.
687-
* The JSON follows the format of that created by https://github.com/tonistiigi/audiosprite
688-
*
689-
* @method Phaser.Loader#audiosprite
690-
* @param {string} key - Unique asset key of the audio file.
691-
* @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.
692-
* @param {string} atlasURL - The URL of the audiosprite configuration json.
693-
* @return {Phaser.Loader} This Loader instance.
694-
*/
695+
* Add a new audiosprite file to the loader.
696+
*
697+
* Audio Sprites are a combination of audio files and a JSON configuration.
698+
* The JSON follows the format of that created by https://github.com/tonistiigi/audiosprite
699+
*
700+
* @method Phaser.Loader#audiosprite
701+
* @param {string} key - Unique asset key of the audio file.
702+
* @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.
703+
* @param {string} atlasURL - The URL of the audiosprite configuration json.
704+
* @return {Phaser.Loader} This Loader instance.
705+
*/
695706
audiosprite: function(key, urls, atlasURL) {
696707

697708
this.audio(key, urls);
@@ -952,7 +963,9 @@ Phaser.Loader.prototype = {
952963
},
953964

954965
/**
955-
* Remove loading request of a file; does nothing if the file is already processed.
966+
* Remove a file/asset from the loading queue.
967+
*
968+
* A file that has already started loading cannot be removed.
956969
*
957970
* @method Phaser.Loader#removeFile
958971
* @protected
@@ -973,7 +986,7 @@ Phaser.Loader.prototype = {
973986
},
974987

975988
/**
976-
* Remove all file loading requests - this is _insufficient_ to clear loading. Use `reset` instead.
989+
* Remove all file loading requests - this is _insufficient_ to stop current loading. Use `reset` instead.
977990
*
978991
* @method Phaser.Loader#removeAll
979992
* @protected

0 commit comments

Comments
 (0)