Hello,
I’m still trying to understand the best way to play my audio in Phaser.
I have a single audio file that’s a 5 second consistent “bleep” for debugging.
In a preloading scene, I load my audio with:
preloadingScene.load.audio("key", "url");
In a game scene, I play my audio with:
gameScene.sound.play("key", {volume: 0});
const currentSound = gameScene.sound.get("key");
if (currentSound) {
const tween = gameScene.tweens.add({
targets: currentSound,
volume: 1,
duration: 4000,
onStart: () => { console.log("audio started");},
onComplete: () => {console.log("audio complete");},
});
currentSound.on("complete", () => {
tween.stop();
});
}
It’s strange since I can run my game and sometimes when the audio starts the audio fade in does work. However out of 10 times I run my game, the fade in fails about 75% of the time and I just hear a consistent “bleep” without any sign of fading in.
When the fade in doesn’t work, I still see my “audio started” and “audio complete” logs appear with the correct timing ("audio started’ is displayed and I can count to 4 until the “audio complete” appears). It’s as if volume
variable of the tween is stuck to 1.
- Is there a some sort of tween reset I’m missing to make sure the tween values are being set correctly?
- I’ve been seeing a variety of examples of how to play audio. For my two scene environment, is this the best way to handle playing audio?
- Is there a way to log what the “volume” property is doing during the tween? Perhaps that might give me some clues as to why it appears to be stuck at ‘1’.
Thank you.