CtlAltDel Posted August 29, 2014 Share Posted August 29, 2014 I am trying to play gunshot sounds from the player and surrounding enemies. I have several gunshot sounds in an audiosprite. Using the addMarker function I create all the different markers. I now need to play the same marker multiple times at the same time. For instance if someone fires a gun and you're firing at the same time I need the same sound twice. It seems the sound api does not support tthis. It either restarts the sound or does not play an extra sound. Any solution other than creating an object pool of sound objects and using those? Link to comment Share on other sites More sharing options...
rich Posted August 29, 2014 Share Posted August 29, 2014 You'll need multiple Sound objects (all using the same markers / source audio). Or alternatively you could move just the sounds that need to overlap (gunshot, etc) into their own sounds. Link to comment Share on other sites More sharing options...
CtlAltDel Posted August 29, 2014 Author Share Posted August 29, 2014 I'll make multiple sound objects, that will work. Maybe something for Phaser3? Link to comment Share on other sites More sharing options...
eguneys Posted August 29, 2014 Share Posted August 29, 2014 hey @rich, I have trouble with sounds as well, i described my problem here please take a look. Link to comment Share on other sites More sharing options...
CtlAltDel Posted September 30, 2014 Author Share Posted September 30, 2014 This might be of use to someone. This is my current solution using the new AudioSprite that is in the dev branch to play multiple of the same sounds.function MultiSound(game, key, maxSounds) { this.game = game; // phaser game object this.maxSounds = maxSounds || 4; // same sounds max at one time this.key = key; // key of the audiosprite this.sounds = []; var self = this; var i = 0, n = this.maxSounds; while( i < n ) { var sound = this.game.add.audioSprite(this.key); this.sounds.push(sound); i++; }}MultiSound.prototype.play = function(key, volume) { if (typeof volume === 'undefined') { volume = 1; } var i = 0, n = this.sounds.length; var started = false; while( i < n ) { var markerSound = this.sounds[i].get(key); if (!markerSound.isPlaying) { markerSound.play(key, null, volume); started = true; break; } i++; } if (!started) { // restart the first available this.sounds[0].play(key, volume); }}; Link to comment Share on other sites More sharing options...
Recommended Posts