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.
Scene5 nodes
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())
}
}
}
- Clips
.wav(8, 16, 24 and 32-bit PCM, 32-bit float) and.oggVorbis, mono or stereo, are imported as they are. - Audio events An audio event is a data asset of type Audio Event (Create → Data Asset → Audio Event).
- Spatial sound A spatial sound fades and pans with its distance to the listener.
- 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.
- Buses and settings Every sound plays on a bus: Music, Effects, Interface, Ambience or Voice, all under Master.
- Music, pause and rewind
audio.Music(Theme, 1.5)loops a clip on the music bus and crossfades from the music that played before;audio.StopMusic(1)fades it out. - Scripting
PlayOptionshas Volume, Pitch, Pan, Bus, Loop, FadeIn, Priority and Unscaled; Volume and Pitch 0 mean 1, and Bus Master plays on the bus of the clip. - Editor tools The editor mixes, previews and draws sound: a mixer for the buses, preview buttons on sources and the ranges of spatial sounds in the views.
- Audio on the web Browsers start sound only after a click, a key or a touch on the page; a page opened by a click, such as Try it on this site, plays at once.
- Go
ServicehasPlay,PlayAt,PlayEvent,PlayEventAt,TriggerandTriggerAtfor an event value built in Go,Music,StopMusic,Stop,Pause,SetVolume,SetPitch,SetPan,Done,Playing,PositionandPauseAll.