keysabyl Posted August 7, 2015 Share Posted August 7, 2015 I want to play 5 sounds one after another in an educational game for my kids. I will do that with sounds in an array: var sounds = ["sound1"," sound2"," sound3"," sound4", " sound5"];.... preload:function(){...for(i=0;i<sounds.length;i++){ game.load.audio(sounds[i],["ProgSounds/"+sounds[i]+".mp3","ProgSounds/"+sounds[i]+".ogg"]);}....} create:function(){...for(i=0;i<sounds.length;i++) { sounds[i] = game.add.audio(sounds[i], 1);}... playSounds:function(){ for (i=0; i < sounds.length; i++){ sounds[i].play(); }} For the moment I hear all the 5 sounds at the same time. Is there a way with Phaser to hear each sound one after another? I was looking already for several hours, but can't find a solution. I tried to work with a timer, the property isPlaying, ...Hopefully there's someone who can help me. Thanks for it in advance. Link to comment Share on other sites More sharing options...
Tilde Posted August 7, 2015 Share Posted August 7, 2015 I figured this out for a dialogue system in my game!playSequence: function(soundArray) { soundArray[0].play(); soundArray.forEach(function(element, index, array) { if (soundArray[index + 1]) { soundArray[index].onStop.addOnce(function() { soundArray[index + 1].play(); }, this); } });} yahiko and georgejfrick 2 Link to comment Share on other sites More sharing options...
keysabyl Posted August 11, 2015 Author Share Posted August 11, 2015 This works !!! Thanks a lot for the quick response. I'm a newbie (I worked with flash), but I chose for Phaser, because it has a perfect community. You are perfect, in other words! Tilde 1 Link to comment Share on other sites More sharing options...
georgejfrick Posted August 11, 2015 Share Posted August 11, 2015 Hey @keysabyl I'm also working on some educational stuff, and I have found that packing my sounds leads to better performance and I'm able to do more processing tricks like playing sounds in succession. You might consider packing the sounds into one file per format and then adding sound markers. -George Tilde 1 Link to comment Share on other sites More sharing options...
Recommended Posts