A room transition can interrupt itself: the player approaches a doorway, then immediately backs away. Restarting the two sounds or creating a fresh fade from an assumed endpoint can make that reversal audible.
One approach is to start two looping layers together, keep them running, and move a single current blend toward its latest target. Zone changes update only that target. In this example, 0 is rain, 1 is campfire, and 0.5 is the doorway.
func set_target(value: float) -> void:
target_mix = clampf(value, 0.0, 1.0)
func _process(delta: float) -> void:
if started and delta > 0.0:
mix = move_toward(mix, target_mix,
delta / maxf(fade_seconds, 0.001))
apply_gains()
That is the transition excerpt, not the full controller. In apply_gains(), use cos(mix * PI / 2) for layer A and sin(mix * PI / 2) for B, multiplied by each layer's base level and a mute factor. Start quietly and leave headroom. At the midpoint both weights are about 0.707: an equal-power curve does not guarantee equal perceived loudness across different recordings.
Integration checks worth trying:
- Reverse direction halfway through a fade. The current blend should continue from where it was, and neither loop should restart.
- Leave both sources running through their loop boundary and listen in the actual game.
- Mute and unmute. Decide whether you want to preserve position; this example changes gains while playback continues.
- Stop and start again. This deliberately restarts both sources, unlike a zone change.
- For a browser build, test from a fresh session with a real click or tap to start audio. Editor playback alone does not test browser autoplay permission.
Complete free Godot example, explanation and browser audition. The guide includes the actual Godot source project; its small browser audition is a separate Web Audio implementation of the same technique. On phones, choose itch's Run asset pack, then Start audio.
Disclosure: this is a Northleaf Studio resource, with AI-assisted code/writing and procedural audio. Only our two existing free rain/campfire loops are included. New example code is MIT; the sounds keep their original commercial-project/no-sound-pack-resale license. No purchase is required. The complete project was tested in Godot 4.7.2 on Linux; other versions and physical phones are unverified.





























































