Aego Русский

Audio Zone 2D

While the listener is inside Area, Bus is turned to Gain.

component audio.AudioZone2D
On this page

Try it

Change a zone's bus gain

The listener is inside the purple zone, which selects a world-layer target of 0.25 for the music bus. The marker reads that target from the audio service. No sound is played.

Set Gain to 0.75. After the scene restarts, the real zone changes the world's music-bus target and the marker turns green. Fade is zero; Reset returns the target to 0.25.

Starts the scene; open the example parameters to experiment.
Open in AegoDownload example project
Scene3 nodes
Zone
Transform
position[0, 0]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")tintColor#5b21b64dsizeVec2[4, 3]
Audio Zone 2D
areaRect[-2, -1.5, 4, 3]busenummusicgainfloat0.25fadeTimefloat0
Indicator
Transform
position[0, 0]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")tintColor#f59e0bffsizeVec2[2, 2]orderint1
Camera
Transform
position[0, 0]rotation0scale[1, 1]
Camera 2D
zoomfloat40clearColorColor#111827ffscaleenumfitVirtualvirtualVec2[960, 540]activebooltrue
Scriptmain.aes
package demo

import "aego/audio"

// The marker reads the target selected by the audio service, not Zone.Gain.
// There is no audio source: observing the mixer does not play a sound.
script GainIndicator {
    func Update(dt float) {
        if audio.WorldBusGain(audio.Bus.Music) > 0.5 {
            node.Get<SpriteRenderer>().Tint = Color{0.05, 0.8, 0.25, 1}
        } else {
            node.Get<SpriteRenderer>().Tint = Color{1, 0.5, 0.05, 1}
        }
    }
}

Fields

NameTypeDefaultDescription
AreaRect(-4, -3, 8, 6)

Rectangle in this node's space.

Busenummusic

Bus the zone turns down or up.

one of: master, music, sfx, ui, ambience, voice
Gainfloat0.5

Volume of the bus inside the zone, 0 to 1.

0 – 1
Priorityint0

Among overlapping zones on one bus the highest priority wins, then the one entered later.

Fade Timefloat0.5

Seconds to fade in and out of the zone.

≥ 0