Aego Русский

Scripting

import "aego/audio"

@export var Jump AssetRef<AudioEvent>
@export var Theme AssetRef<Clip>

func Ready() {
  audio.Music(Theme, 1.5)
}

func OnJump() {
  audio.PlayEvent(Jump)
}
Function
Play(clip) Sound, PlayWith(clip, options) Sound play a clip on its bus, or with PlayOptions
PlayAt(clip, position) Sound play a clip at a world position, spatial
PlayEvent(event) Sound, PlayEventAt(event, position) Sound play an audio event; a spatial event follows the node of the script
Music(clip, seconds) Sound, StopMusic(seconds) loop music with a crossfade, fade it out
BusVolume(bus) float, SetBusVolume(bus, volume), Mute(bus, on) session volume of a bus, on top of the player's settings
Pause(on) pause or resume every sound of this world
Builtin(name) AssetRef<Clip> a built-in clip: Beep, Click, Hum or Melody

PlayOptions has 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. Sound has Done(), Playing(), Stop(), StopFade(seconds), Pause(), Resume(), SetVolume, SetPitch, SetPan, Position() and the signal Completed(finished bool); yield waits for it, and a nil sound is done. Every play belongs to the node of the script and stops when the node is destroyed.

Component methods: AudioSource2D.Play(), Stop(), StopFade(seconds) and IsPlaying(), and the signals Started and Finished(finished bool).

package demo

import (
    "aego/audio"
    "aego/log"
)

script Chime {
    var hum audio.Sound
    var frames int

    func Ready() {
        hum = audio.PlayWith(audio.Builtin("Hum"), audio.PlayOptions{Volume: 0.5, Pitch: 1.5, Loop: true})
        hum.Completed.Connect(Ended)
        log.Info("the hum plays: " + string(hum.Playing()))
    }

    func Ended(finished bool) {
        log.Info("the hum ended, finished " + string(finished))
    }

    func Update(dt float) {
        frames++
        if frames == 60 {
            hum.StopFade(0.2)
            log.Info("fading at " + string(hum.Position()) + " s")
        }
    }
}