phaser
phaser copied to clipboard
audio follow does not honor the Z axis of the object
If X and Y of the object being followed is honored, why not the Z?
Would appreciate this addition. 🙏
Here's the diff to make it work:
--- WebAudioSound.js 2025-05-11 11:03:59
+++ WebAudioSound2.js 2025-05-11 10:59:39
@@ -551,7 +551,39 @@ var WebAudioSound = new Class({
set: function (value) {
if (this.spatialNode) {
this.spatialNode.positionY.value = value;
+ }
+ }
+ },
+
+ /**
+ * Sets the z position of this Sound in Spatial Audio space.
+ *
+ * This only has any effect if the sound was created with a SpatialSoundConfig object.
+ *
+ * Also see the `WebAudioSoundManager.setListenerPosition` method.
+ *
+ * If you find that the sound becomes too quiet, too quickly, as it moves away from
+ * the listener, then try different `refDistance` property values when configuring
+ * the spatial sound.
+ *
+ * @name Phaser.Sound.WebAudioSound#y
+ * @type {number}
+ * @since 3.60.0
+ */
+ z: {
+
+ get: function () {
+ if (this.spatialNode) {
+ return this.spatialNode.positionZ;
+ } else {
+ return 0;
}
+ },
+
+ set: function (value) {
+ if (this.spatialNode) {
+ this.spatialNode.positionZ.value = value;
+ }
}
},
@@ -567,12 +599,16 @@ var WebAudioSound = new Class({
if (this.isPlaying && this.spatialSource) {
var x = GetFastValue(this.spatialSource, 'x', null);
var y = GetFastValue(this.spatialSource, 'y', null);
+ var z = GetFastValue(this.spatialSource, 'z', null);
if (x && x !== this._spatialx) {
this._spatialx = this.spatialNode.positionX.value = x;
}
if (y && y !== this._spatialy) {
this._spatialy = this.spatialNode.positionY.value = y;
+ }
+ if (z && z !== this._spatialz) {
+ this._spatialz = this.spatialNode.positionZ.value = z;
}
}