Small World Engine API Reference - v0.76.20
    Preparing search index...

    Class AudioSystem

    A basic Audio System that wraps the Web Audio API. Supports loading sounds and playing them globally or spatially.

    Index
    • Parameters

      • Optionalcontext: AudioContext

        An AudioContext to use instead of creating one -- lets tests (and any code that already owns a shared context) inject their own instead of relying on the global window.AudioContext.

      Returns AudioSystem

    context: AudioContext
    masterGain: GainNode
    musicGain: GainNode
    sfxGain: GainNode
    • Loads an audio file and decodes it into a buffer.

      Parameters

      • url: string

        The URL of the audio file.

      • name: string

        The unique name to identify the sound.

      Returns Promise<void>

    • Plays a global (non-spatial) sound.

      Parameters

      • name: string
      • loop: boolean = false
      • volume: number = 1.0

      Returns AudioBufferSourceNode | null

    • Generates a retro synthesized footstep thud. See SynthSFX.playFootstep.

      Returns void

    • Generates a retro "Ugh!" hurt sound. See SynthSFX.playHurt.

      Returns void

    • Plays a global (non-spatial) music track through the music bus, so it responds to setMusicVolume() independently of sound effects.

      Parameters

      • name: string
      • loop: boolean = true
      • volume: number = 1.0

      Returns AudioBufferSourceNode | null

    • Generates a retro "Pew Pew" laser/gunshot sound. See SynthSFX.playShoot.

      Returns void

    • Plays a 3D spatial sound at a given position.

      Parameters

      • name: string
      • position: Vector3D
      • loop: boolean = false
      • volume: number = 1.0
      • refDistance: number = 2.0
      • maxDistance: number = 20.0

      Returns { panner: PannerNode; source: AudioBufferSourceNode } | null

    • Generates a procedural synth tone (e.g., for musical instruments or physical impacts). See SynthSFX.playTone.

      Parameters

      • frequency: number = 440

        The base frequency in Hz.

      • duration: number = 0.5

        The duration of the tone in seconds.

      • volume: number = 0.5

        The starting volume.

      • type: OscillatorType = "sine"

        The oscillator type.

      Returns void

    • Must be called after a user interaction to resume the audio context on some browsers.

      Returns void

    • Set the global master volume (0.0 to 1.0)

      Parameters

      • value: number

      Returns void

    • Set the Music volume (0.0 to 1.0)

      Parameters

      • value: number

      Returns void

    • Set the Reverb level (0.0 to 1.0)

      Parameters

      • value: number

      Returns void

    • Set the SFX volume (0.0 to 1.0)

      Parameters

      • value: number

      Returns void

    • Starts a creepy, pulsing low-frequency background drone. See SynthSFX.startDrone.

      Returns void

    • Starts a procedural fire crackling noise at a specific 3D location. See SynthSFX.startFire.

      Parameters

      • position: Vector3D
      • volume: number = 1.0

      Returns void