lpbr Posted March 5, 2018 Share Posted March 5, 2018 I have an array with a list of sounds and then I loop barely like this to add them to the game: for (var i=0;i<=aSounds.length-1;i++) window[aSounds[i].name+'_snd'] = game.add.audio(aSounds[i].name); To play the sound at the desired points of my code I just do: window[me.name+'_snd'].play() // works fine However I am not managing to STOP the sound with: window[me.name+'_snd'].stop(); // instead to stop the sound it just restarts What am I doing wrong? Thanks! Link to comment Share on other sites More sharing options...
PixelPicoSean Posted March 6, 2018 Share Posted March 6, 2018 Nothing wrong with the code, check whether your code plays those sound unexpectedly. And I believe this is a Phaser 2 related topic. lpbr 1 Link to comment Share on other sites More sharing options...
lpbr Posted March 6, 2018 Author Share Posted March 6, 2018 I figured the cause of the problem. I used the onStop event to loop the sound so when it stopped (finished to play) it started again. Of course when I was clicking to force stop it fired the event and restarted the sound. I should use onLoop instead. Link to comment Share on other sites More sharing options...
Recommended Posts