You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* @param {Phaser.Loader.LoaderPlugin} loader - A reference to the Loader that is responsible for this file.
26
+
* @param {(string|Phaser.Loader.FileTypes.JSONFileConfig)} key - The key to use for this file, or a file configuration object.
27
+
* @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `<key>.json`, i.e. if `key` was "alien" then the URL will be "alien.json".
28
+
* @param {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file.
29
+
* @param {string} [dataKey] - When the JSON file loads only this property will be stored in the Cache.
25
30
*/
26
31
varAnimationJSONFile=newClass({
27
32
@@ -30,14 +35,22 @@ var AnimationJSONFile = new Class({
30
35
initialize:
31
36
32
37
// url can either be a string, in which case it is treated like a proper url, or an object, in which case it is treated as a ready-made JS Object
38
+
// dataKey allows you to pluck a specific object out of the JSON and put just that into the cache, rather than the whole thing
* If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files
118
+
* key. For example, if the prefix was `LEVEL1.` and the key was `Waves` the final key will be `LEVEL1.Waves` and
119
+
* this is what you would use to retrieve the text from the JSON Cache.
120
+
*
121
+
* The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it.
122
+
*
123
+
* If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "data"
124
+
* and no URL is given then the Loader will set the URL to be "data.json". It will always add `.json` as the extension, although
125
+
* this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL.
126
+
*
127
+
* You can also optionally provide a `dataKey` to use. This allows you to extract only a part of the JSON and store it in the Cache,
128
+
* rather than the whole file. For example, if your JSON data had a structure like this:
129
+
*
130
+
* ```json
131
+
* {
132
+
* "level1": {
133
+
* "baddies": {
134
+
* "aliens": {},
135
+
* "boss": {}
136
+
* }
137
+
* },
138
+
* "level2": {},
139
+
* "level3": {}
140
+
* }
141
+
* ```
61
142
*
62
-
* Note: This method will only be available if the Animation JSON File type has been built into Phaser.
143
+
* And if you only wanted to create animations from the `boss` data, then you could pass `level1.baddies.boss`as the `dataKey`.
63
144
*
64
-
* The file is **not** loaded immediately after calling this method.
65
-
* Instead, the file is added to a queue within the Loader, which is processed automatically when the Loader starts.
145
+
* Note: The ability to load this type of file will only be available if the JSON File type has been built into Phaser.
146
+
* It is available in the default build but can be excluded from custom builds.
66
147
*
67
148
* @method Phaser.Loader.LoaderPlugin#animation
149
+
* @fires Phaser.Loader.LoaderPlugin#addFileEvent
68
150
* @since 3.0.0
69
151
*
70
-
* @param {(string|array|object)} key - A unique string to be used as the key to reference this file from the Cache. Must be unique within this file type.
71
-
* @param {string} [url] - URL of the file. If `undefined` or `null` the url will be set to `<key>.json`,
72
-
* i.e. if `key` was "alien" then the URL will be "alien.json".
73
-
* @param {XHRSettingsObject} [xhrSettings] - File specific XHR settings to be used during the load. These settings are merged with the global Loader XHR settings.
152
+
* @param {(string|Phaser.Loader.FileTypes.JSONFileConfig|Phaser.Loader.FileTypes.JSONFileConfig[])} key - The key to use for this file, or a file configuration object, or array of them.
153
+
* @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `<key>.json`, i.e. if `key` was "alien" then the URL will be "alien.json".
154
+
* @param {string} [dataKey] - When the Animation JSON file loads only this property will be stored in the Cache and used to create animation data.
155
+
* @param {XHRSettingsObject} [xhrSettings] - An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings.
74
156
*
75
-
* @return {Phaser.Loader.LoaderPlugin} The Loader.
157
+
* @return {Phaser.Loader.LoaderPlugin} The Loader instance.
0 commit comments