Jump to content

Playing sounds one after another


keysabyl
 Share

Recommended Posts

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

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);      }    });}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...