My game has several different cannons / guns, and every time you shoot, it plays a small ‘pew’ sound effect. However, it seems Phaser 3 does not have a way to support extremely fast repeating sounds, which is a problem for my machine guns. With some of the faster guns, you can’t even hear the audio play. and with slower ones, it clips off the moment the next projectile is shot. How can I make it so the audio finishes it’s duration? This is my code for the shooting (ignore the lilbig logic)
Depending on the result you are looking for, there could be a few different solutions. If you want to have multiple instances of the sound playing at once, for example each time you shoot a bullet we want to trigger an instance of the ‘pew’ sound, you could create pool of these audio objects and then play each one as a bullet is fired.
If you just want to reuse the single audio instance, before you call the play method, you could check if the audio is already playing, and if so, increment a counter to keep track of the number of ‘pew’ sounds that need to be played. For this to work, you would need to listen for the complete event for once the audio is done playing, and when that happens, decrease the counter and play the pew sound again.
Check my answer here. It is about building simple audio manager with slots, that allows you to play the same sound multiple times. It works well for me.