Aego Русский

Audio

Sound in Aego is imported clips, played by components, scripts and audio events, and mixed on buses that the player sets in Settings. Sounds are presentation: they never change the game state, and a rewind or a replay is silent.

Quick start: drop a .wav into the project, add Audio Source 2D to a node, set Clip and Play On Start, and press Play.

Piece Purpose
Clip an imported .wav, .ogg or .mp3 file
Audio Source 2D plays a clip or an audio event from its node
Audio Listener 2D the ears of spatial sound
Audio Zone 2D turns a bus down or up while the listener is inside
Audio Event a data asset: variants, randomness, a voice limit and space
aego/audio the script API

Audio runs during Play and in aego run. In edit mode the Inspector previews clips, and the Scene View shows the ranges of spatial sources and the zones.

In Try it, the ball hums while it rolls from wall to wall and clicks when it hits one. The camera carries the listener, so the hum pans and fades as the ball moves. Tick Replay on the script to start the hum again. The browser starts sound after the first click on the page.

Try it

Change the example parameters and compare the result. Reset restores the initial scene.

Starts the scene; open the example parameters to experiment.
Open in AegoDownload example project
Scene5 nodes
Ground
Transform
position[0, 2]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")layerint0orderint0tintColor#4b5563fforiginVec2[0.5, 0.5]sizeVec2[30, 0.6]flipXboolfalseflipYboolfalseblendenumpremultipliedfilterenumnearest
Rigid Body 2D
typeenumstaticmassModeenumautomassfloat0gravityScalefloat1linearDampingfloat0angularDampingfloat0fixedRotationboolfalsebulletboolfalseallowSleepbooltrueinterpolateboolfalselayerlayer0masklayer mask-1
Box Collider 2D
offsetVec2[0, 0]isTriggerboolfalsefrictionfloat0.2restitutionfloat0densityfloat1sizeVec2[30, 0.6]
WallLeft
Transform
position[-13, -1]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")layerint0orderint0tintColor#4b5563fforiginVec2[0.5, 0.5]sizeVec2[0.6, 6]flipXboolfalseflipYboolfalseblendenumpremultipliedfilterenumnearest
Rigid Body 2D
typeenumstaticmassModeenumautomassfloat0gravityScalefloat1linearDampingfloat0angularDampingfloat0fixedRotationboolfalsebulletboolfalseallowSleepbooltrueinterpolateboolfalselayerlayer0masklayer mask-1
Box Collider 2D
offsetVec2[0, 0]isTriggerboolfalsefrictionfloat0.2restitutionfloat0.3densityfloat1sizeVec2[0.6, 6]
WallRight
Transform
position[13, -1]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")layerint0orderint0tintColor#4b5563fforiginVec2[0.5, 0.5]sizeVec2[0.6, 6]flipXboolfalseflipYboolfalseblendenumpremultipliedfilterenumnearest
Rigid Body 2D
typeenumstaticmassModeenumautomassfloat0gravityScalefloat1linearDampingfloat0angularDampingfloat0fixedRotationboolfalsebulletboolfalseallowSleepbooltrueinterpolateboolfalselayerlayer0masklayer mask-1
Box Collider 2D
offsetVec2[0, 0]isTriggerboolfalsefrictionfloat0.2restitutionfloat0.3densityfloat1sizeVec2[0.6, 6]
Ball
Transform
position[-6, 1.2]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")layerint0orderint1tintColor#f59e0bfforiginVec2[0.5, 0.5]sizeVec2[1, 1]flipXboolfalseflipYboolfalseblendenumpremultipliedfilterenumnearest
Rigid Body 2D
typeenumdynamicmassModeenumautomassfloat0gravityScalefloat1linearDampingfloat0.2angularDampingfloat0fixedRotationboolfalsebulletboolfalseallowSleepboolfalseinterpolatebooltruelayerlayer0masklayer mask-1
Circle Collider 2D
offsetVec2[0, 0]isTriggerboolfalsefrictionfloat0.6restitutionfloat0.1densityfloat1radiusfloat0.5
Audio Source 2D
clipClipasset("ae900000000000000000000000000a03")eventAssetRef<data>asset("00000000000000000000000000000000")volumefloat0.8pitchfloat1panfloat0busenumsfxloopbooltrueplayOnStartbooltruespatialbooltrueminDistancefloat2maxDistancefloat18rolloffCurve{ ease=outQuad }panWidthfloat0.9pauseWithenumgame
Camera
Transform
position[0, -1]rotation0scale[1, 1]
Camera 2D
zoomfloat34viewportRect[0, 0, 1, 1]maskint-1orderint0clearbooltrueclearColorColor#111827ffscaleenumfitVirtualvirtualVec2[960, 540]activebooltrue
Scriptmain.aes
package demo

import (
    "aego/audio"
    "aego/physics"
)

// Roller rolls the humming ball from wall to wall and clicks on every wall hit; tick Replay to start the hum again.
script Roller {
    @export var Speed float = 6
    @export var Bump AssetRef<Clip>
    @export(tip="Tick to start the sound of the ball again")
    var Replay bool

    var dir float = 1

    func Update(dt float) {
        if Replay {
            Replay = false
            src := node.Get<AudioSource2D>()
            if src != nil {
                src.Play()
            }
        }
        body := node.Get<Body2D>()
        body.SetVelocity(Vec2{dir * Speed, body.Velocity.Y})
    }

    func OnCollisionEnter(other NodeRef, c physics.Contact) {
        if c.Normal.X > 0.5 || c.Normal.X < -0.5 {
            dir = -dir
            audio.PlayAt(Bump, node.Position())
        }
    }
}