Hello!
I just started using Phaser 3.
I have a sound file. Let’s say it’s 5 seconds in duration.
I immediately play the sound with:
sound.play(id, { volume: 1});
After let’s say after 3 seconds, I now want to fade out the sound:
const currentSound = sound.get(id);
this.tweens.add({
targets: currentSound,
volume: 0,
duration: 1000,
});
This is great since the sound plays for 3 seconds and then fades away by 4 seconds.
However, when I increase the duration of the fade out to something beyond the sound file’s duration (say a duration of 8000), I get an error in the updateTweenData:
TypeError: Cannot set property 'volume' of null
I believe it’s because the sound has finished but the tween is still attempting to adjust its volume.
Is there a good way to guard against tween durations outside of the sound’s length?
Is there a way I can get the current “elapsed” time of the sound and adjust my tween’s duration to something within the remaining time of my sound?
Thanks!