Unable to get Volume

Hello,

I’m still quite new to Phaser and I’m having trouble getting the current volume of a played sound.

I play my sound with the following code:

const currentSound = this.sound.add("myMusic", { volume: 0.6 });
currentSound.play();

This works great and I can hear the sound.

However, I’m trying to get the volume of this played sound by doing the following:

currentSound.volume;

However, volume is not defined since the return type of add() is of Phaser.Sound.BaseSound.

I’ve been following various tutorials where this field was accessible. Do I not have Phaser 3 configured correctly?

I am currently using Phaser 3.24.1

Thanks!

Here’s the references I’ve been following:


I think that’s an error in Phaser’s type declarations.

If you’re using TypeScript, you can use a type assertion to avoid it. If you’re not using TypeScript, you can ignore the error.