66 */
77
88var Class = require ( '../utils/Class' ) ;
9+ var Clone = require ( '../utils/object/Clone' ) ;
910var EventEmitter = require ( 'eventemitter3' ) ;
1011var NOOP = require ( '../utils/NOOP' ) ;
1112
@@ -63,6 +64,16 @@ var BaseSoundManager = new Class({
6364 */
6465 this . game = game ;
6566
67+ /**
68+ * Local reference to the JSON Cache, as used by Audio Sprites.
69+ *
70+ * @name Phaser.Sound.BaseSoundManager#jsonCache
71+ * @type {Phaser.Cache.BaseCache }
72+ * @readOnly
73+ * @since 3.7.0
74+ */
75+ this . jsonCache = game . cache . json ;
76+
6677 /**
6778 * An array containing all added sounds.
6879 *
@@ -186,6 +197,8 @@ var BaseSoundManager = new Class({
186197
187198 /**
188199 * Adds a new audio sprite sound into the sound manager.
200+ * Audio Sprites are a combination of audio files and a JSON configuration.
201+ * The JSON follows the format of that created by https://github.com/tonistiigi/audiosprite
189202 *
190203 * @method Phaser.Sound.BaseSoundManager#addAudioSprite
191204 * @since 3.0.0
@@ -197,9 +210,11 @@ var BaseSoundManager = new Class({
197210 */
198211 addAudioSprite : function ( key , config )
199212 {
213+ if ( config === undefined ) { config = { } ; }
214+
200215 var sound = this . add ( key , config ) ;
201216
202- sound . spritemap = this . game . cache . json . get ( key ) . spritemap ;
217+ sound . spritemap = this . jsonCache . get ( key ) . spritemap ;
203218
204219 for ( var markerName in sound . spritemap )
205220 {
@@ -208,13 +223,17 @@ var BaseSoundManager = new Class({
208223 continue ;
209224 }
210225
226+ var markerConfig = Clone ( config ) ;
227+
211228 var marker = sound . spritemap [ markerName ] ;
212229
230+ markerConfig . loop = ( marker . hasOwnProperty ( 'loop' ) ) ? marker . loop : false ;
231+
213232 sound . addMarker ( {
214233 name : markerName ,
215234 start : marker . start ,
216235 duration : marker . end - marker . start ,
217- config : config
236+ config : markerConfig
218237 } ) ;
219238 }
220239
0 commit comments