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
* See the documentation for `Phaser.Loader.FileTypes.AudioFileConfig` for more details.
211
+
*
212
+
* The URLs can be relative or absolute. If the URLs are relative the `Loader.baseURL` and `Loader.path` values will be prepended to them.
213
+
*
214
+
* Due to different browsers supporting different audio file types you should usually provide your audio files in a variety of formats.
215
+
* ogg, mp3 and m4a are the most common. If you provide an array of URLs then the Loader will determine which _one_ file to load based on
216
+
* browser support.
164
217
*
165
-
* Note: This method will only be available if the Audio File type has been built into Phaser.
218
+
* If audio has been disabled in your game, either via the game config, or lack of support from the device, then no audio will be loaded.
166
219
*
167
-
* The file is **not** loaded immediately after calling this method.
168
-
* Instead, the file is added to a queue within the Loader, which is processed automatically when the Loader starts.
220
+
* Note: The ability to load this type of file will only be available if the Audio File type has been built into Phaser.
221
+
* It is available in the default build but can be excluded from custom builds.
169
222
*
170
223
* @method Phaser.Loader.LoaderPlugin#audio
224
+
* @fires Phaser.Loader.LoaderPlugin#addFileEvent
171
225
* @since 3.0.0
172
226
*
173
-
* @param {string} key - [description]
174
-
* @param {(string|string[])} urls - [description]
175
-
* @param {object} config - [description]
176
-
* @param {object} [xhrSettings] - [description]
227
+
* @param {(string|Phaser.Loader.FileTypes.AudioFileConfig|Phaser.Loader.FileTypes.AudioFileConfig[])} key - The key to use for this file, or a file configuration object, or array of them.
228
+
* @param {(string|string[])} [urls] - The absolute or relative URL to load the audio files from.
229
+
* @param {any} [config] - An object containing an `instances` property for HTML5Audio. Defaults to 1.
230
+
* @param {XHRSettingsObject} [xhrSettings] - An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings.
177
231
*
178
-
* @return {Phaser.Loader.LoaderPlugin} The Loader.
232
+
* @return {Phaser.Loader.LoaderPlugin} The Loader instance.
* @param {Phaser.Loader.LoaderPlugin} loader - A reference to the Loader that is responsible for this file.
41
+
* @param {(string|Phaser.Loader.FileTypes.AudioSpriteFileConfig)} key - The key to use for this file, or a file configuration object.
42
+
* @param {string} jsonURL - The absolute or relative URL to load the json file from. Or a well formed JSON object to use instead.
43
+
* @param {string} [audioURL] - The absolute or relative URL to load the audio file from. If empty it will be obtained by parsing the JSON file.
44
+
* @param {any} [audioConfig] - The audio configuration options.
45
+
* @param {XHRSettingsObject} [audioXhrSettings] - An XHR Settings configuration object for the audio file. Used in replacement of the Loaders default XHR Settings.
46
+
* @param {XHRSettingsObject} [jsonXhrSettings] - An XHR Settings configuration object for the json file. Used in replacement of the Loaders default XHR Settings.
@@ -130,26 +152,106 @@ var AudioSpriteFile = new Class({
130
152
});
131
153
132
154
/**
133
-
* Adds an Audio Sprite file to the current load queue.
155
+
* Adds a JSON based Audio Sprite, or array of audio sprites, to the current load queue.
156
+
*
157
+
* You can call this method from within your Scene's `preload`, along with any other files you wish to load:
158
+
*
159
+
* ```javascript
160
+
* function preload ()
161
+
* {
162
+
* this.load.audioSprite('kyobi', 'kyobi.json', [
163
+
* 'kyobi.ogg',
164
+
* 'kyobi.mp3',
165
+
* 'kyobi.m4a'
166
+
* ]);
167
+
* }
168
+
* ```
169
+
*
170
+
* Audio Sprites are a combination of audio files and a JSON configuration.
171
+
* The JSON follows the format of that created by https://github.com/tonistiigi/audiosprite
172
+
*
173
+
* If the JSON file includes a 'resource' object then you can let Phaser parse it and load the audio
174
+
* files automatically based on its content. To do this exclude the audio URLs from the load:
175
+
*
176
+
* ```javascript
177
+
* function preload ()
178
+
* {
179
+
* this.load.audioSprite('kyobi', 'kyobi.json');
180
+
* }
181
+
* ```
182
+
*
183
+
* The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts,
184
+
* or if it's already running, when the next free load slot becomes available. This happens automatically if you
185
+
* are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued
186
+
* it means you cannot use the file immediately after calling this method, but must wait for the file to complete.
187
+
* The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the
188
+
* Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been
189
+
* loaded.
190
+
*
191
+
* If you call this from outside of `preload` then you are responsible for starting the Loader afterwards and monitoring
192
+
* its events to know when it's safe to use the asset. Please see the Phaser.Loader.LoaderPlugin class for more details.
193
+
*
194
+
* The key must be a unique String. It is used to add the file to the global Audio Cache upon a successful load.
195
+
* The key should be unique both in terms of files being loaded and files already present in the Audio Cache.
196
+
* Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file
197
+
* then remove it from the Audio Cache first, before loading a new one.
198
+
*
199
+
* Instead of passing arguments you can pass a configuration object, such as:
200
+
*
201
+
* ```javascript
202
+
* this.load.audioSprite({
203
+
* key: 'kyobi',
204
+
* jsonURL: 'audio/Kyobi.json',
205
+
* audioURL: [
206
+
* 'audio/Kyobi.ogg',
207
+
* 'audio/Kyobi.mp3',
208
+
* 'audio/Kyobi.m4a'
209
+
* ]
210
+
* });
211
+
* ```
212
+
*
213
+
* See the documentation for `Phaser.Loader.FileTypes.AudioSpriteFileConfig` for more details.
214
+
*
215
+
* Instead of passing a URL for the audio JSON data you can also pass in a well formed JSON object instead.
216
+
*
217
+
* Once the audio has finished loading you can use it create an Audio Sprite by referencing its key:
218
+
*
219
+
* ```javascript
220
+
* this.load.audioSprite('kyobi', 'kyobi.json');
221
+
* // and later in your game ...
222
+
* var music = this.sound.addAudioSprite('kyobi');
223
+
* music.play('title');
224
+
* ```
225
+
*
226
+
* If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files
227
+
* key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and
228
+
* this is what you would use to retrieve the image from the Texture Manager.
229
+
*
230
+
* The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it.
134
231
*
135
-
* Note: This method will only be available if the Audio Sprite File type has been built into Phaser.
232
+
* Due to different browsers supporting different audio file types you should usually provide your audio files in a variety of formats.
233
+
* ogg, mp3 and m4a are the most common. If you provide an array of URLs then the Loader will determine which _one_ file to load based on
234
+
* browser support.
136
235
*
137
-
* The file is **not** loaded immediately after calling this method.
138
-
* Instead, the file is added to a queue within the Loader, which is processed automatically when the Loader starts.
236
+
* If audio has been disabled in your game, either via the game config, or lack of support from the device, then no audio will be loaded.
237
+
*
238
+
* Note: The ability to load this type of file will only be available if the Audio Sprite File type has been built into Phaser.
239
+
* It is available in the default build but can be excluded from custom builds.
139
240
*
140
241
* @method Phaser.Loader.LoaderPlugin#audioSprite
242
+
* @fires Phaser.Loader.LoaderPlugin#addFileEvent
141
243
* @since 3.0.0
142
244
*
143
-
* @param {string} key - [description]
144
-
* @param {object} json - [description]
145
-
* @param {(string|string[])} urls - [description]
146
-
* @param {object} config - [description]
147
-
* @param {XHRSettingsObject} [audioXhrSettings] - Optional file specific XHR settings.
148
-
* @param {XHRSettingsObject} [jsonXhrSettings] - Optional file specific XHR settings.
245
+
* @param {(string|Phaser.Loader.FileTypes.AudioSpriteFileConfig|Phaser.Loader.FileTypes.AudioSpriteFileConfig[])} key - The key to use for this file, or a file configuration object, or an array of objects.
246
+
* @param {string} jsonURL - The absolute or relative URL to load the json file from. Or a well formed JSON object to use instead.
247
+
* @param {string} [audioURL] - The absolute or relative URL to load the audio file from. If empty it will be obtained by parsing the JSON file.
248
+
* @param {any} [audioConfig] - The audio configuration options.
249
+
* @param {XHRSettingsObject} [audioXhrSettings] - An XHR Settings configuration object for the audio file. Used in replacement of the Loaders default XHR Settings.
250
+
* @param {XHRSettingsObject} [jsonXhrSettings] - An XHR Settings configuration object for the json file. Used in replacement of the Loaders default XHR Settings.
149
251
*
150
252
* @return {Phaser.Loader.LoaderPlugin} The Loader.
0 commit comments