Jump to content

Sound effect glitches


Nek0
 Share

Recommended Posts

Wondering what the best way to play a sound effect in Phaser 2 is. So far I've been doing something like this:

sfx = new Audio('sound1.mp3'); sfx.volume = .5; sfx.play()

The same variable "sfx" gets used for each sound, it's just reassigned on the spot as 'sound2.mp3', 'sound3.mp3', etc. I'm sure this is the wrong way, but it does get it all done in a single line per sound effect. Nevertheless this method causes a small delay which causes the game to freeze for 1/10 of a second the first time it is played, which then causes objects to fall through floors occasionally. I looked at some of the sound examples, but the ones I saw were quite long and I'm wondering if there's a briefer solution to this.

Link to comment
Share on other sites

  • 2 weeks later...

me neither =P i'm still rather new at this.

thanks for the above advice though. it did point me in the right direction. implementing sound effects this way does make things run smoother. that example, however, shows how to play 1 music file 1 time. i'm looking to play multiple sound effects multiple times. so far the sfx run ok, but they don't seem to play over each other the way the old method did, i.e. explosions running through explode.mp3 being played 10 times in 1 second will only play the 10th sound effect all the way through, the rest get cut off because it seems to want to overwrite the previous one with the newer one each time. any way to play the full sound 10 times in rapid succession?

Link to comment
Share on other sites

ah yes, that solves it. "soundeffect.allowMultiple = true" was the missing link.

the odd thing is i recall looking at that exact example and even click tested the sounds and they DIDN'T stack. i must've been looking at the wrong VERSION of the example or something? anyway thanks again. as ever you're a lifesaver.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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