Zones
While the listener is inside the Area of an Audio Zone 2D, the zone's Bus is turned to its Gain over Fade Time. The area is a rectangle in the zone node's space.
audio.WorldBusGain(bus) reports the last world-layer target selected by zones. The actual mixer also applies fade, session volume and player settings.
- Among overlapping zones on one bus the highest Priority wins, then the zone entered later. Leaving one zone leaves the others in place.
- Zones act on the world layer of the mixer, under the player's settings and the session, and end with the world.
- A zone changes the whole bus, not one source: use it for muffling music indoors or quieting ambience near a menu.
In Try it, the music bus drops to a fifth while the listening ball rolls through the purple area, and comes back when it leaves. Set Gain to 0 to silence the music inside, or raise Fade Time for a slower change.
Try it
Change the example parameters and compare the result. Reset restores the initial scene.
Starts the scene; open the example parameters to experiment.
Scene5 nodes
Ground
Transform
position[0, 2]rotation0scale[1, 1]
Rigid Body 2D
typeenumstaticmassModeenumautomassfloat0gravityScalefloat1linearDampingfloat0angularDampingfloat0fixedRotationboolfalsebulletboolfalseallowSleepbooltrueinterpolateboolfalselayerlayer0masklayer mask-1
Music
Transform
position[0, 0]rotation0scale[1, 1]
Audio Source 2D
clipClipasset("ae900000000000000000000000000a04")eventAssetRef<data>asset("00000000000000000000000000000000")volumefloat0.8pitchfloat1panfloat0busenummusicloopbooltrueplayOnStartbooltruespatialboolfalseminDistancefloat1maxDistancefloat10rolloffCurve{ ease=outQuad }panWidthfloat0.8pauseWithenumnever
Ball
Transform
position[-8, 1.2]rotation0scale[1, 1]
Rigid Body 2D
typeenumdynamicmassModeenumautomassfloat0gravityScalefloat1linearDampingfloat0angularDampingfloat0fixedRotationbooltruebulletboolfalseallowSleepboolfalseinterpolatebooltruelayerlayer0masklayer mask-1
Camera
Transform
position[-8, 0]rotation0scale[1, 1]
Virtual Camera 2D
priorityint0outputstring""zoomfloat0blendTimefloat0.6blendCurveCurve{ ease=inOutQuad }timeDomainenumunscaleduseBoundsboolfalseboundsRect[0, 0, 0, 0]snapToPixelsboolfalse
Camera Follow 2D
targetNodeRefnode("a0d40000000000000000000000000004")deadzoneRect[0.45, 0.4, 0.1, 0.2]dampingVec2[5, 5]lookaheadVec2[0, 0]maxLookaheadVec2[0, 0]lookaheadSmoothingfloat3snapDistancefloat20
Scriptmain.aes
package demo
// Walker rolls the listening ball through the zone and back; inside it the music bus drops to the zone's Gain.
script Walker {
@export var Speed float = 5
@export var Every float = 4
var t float = 4
var dir float = 1
func Update(dt float) {
t += dt
if t < Every {
return
}
t = 0
body := node.Get<Body2D>()
body.SetVelocity(Vec2{dir * Speed, 0})
dir = -dir
}
}