Sound in particular place

Hey Tom, you definitely can. One way that comes to mind is simply increasing volume based on distance, so in an update loop or on an onPlayerMove event, you could have something like:

let distanceThreshold = 400; //This is the max distance from the object. Any farther and no sound is played.
let distanceToObject = Phaser.Math.Distance.Between(player.x, player.y, soundObj.x, soundObj.y);
let normalizedSound = 1 - (distanceToObject / distanceThreshold);
sound.volume = normalizedSound;

Also, as Jackfreak said, sound perception isn’t linear, so you could add a curve to the volume to make it seem more realistic. In order to do this, simply add an easing function to the normalizedSound. So, sound.volume = normalizedSound; turns into sound.volume = Phaser.Math.Easing.Sine.In(normalizedSound);

4 Likes