phaser
phaser copied to clipboard
sound.play() doesn't play simultaneous sounds
When I call .play() for a sound more than once, the previous plays are stopped when the new one starts so they don't play simultaneously. Sounds played using using audiosprites do play simultaneously. I'm using webaudio:
public preload() {
log(preload)
this.load.audio("falling", ["assets/audio/mixkit-short-whistle-fall-406.mp3", "assets/audio/mixkit-short-whistle-fall-406.ogg"])
}
public create() {
this.fallingSound = this.sound.add("falling", { loop: false }) ...
then in update() or on a collision I am calling this.fallingSound.play()
A sound object has only one playback position.
You need to create a second sound object or use this.sound.play('falling')
instead.
Thank you very much for the information. I wish it were reflected in the documentation.
@steveja42 It is actually!
https://photonstorm.github.io/phaser3-docs/Phaser.Sound.HTML5AudioSoundManager.html
To play multiple instances of the same HTML5 Audio sound, you need to provide an instances value when loading the sound with the Loader
That doesn't explain the difference between this.sound.play(key) and asoundInstance.play() that you pointed out. Also when I used instances in the loader asoundInstance.play() still started over every time so I don't see that instances did anything.
@steveja42 Fair enough
I believe you still need to use this.sound.play(key)
otherwise calling play()
on the instance directly will just restart that instance, as you mentioned
Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master
branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.