Gleam - v1.0.2
    Preparing search index...

    Class Sound

    One-shot SFX. Each play call clones the registered HTMLAudioElement so the same sound can overlap itself; stop cuts every in-flight clone. Inherits registration, enable/disable, and volume from AudioBase.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    Accessors

    Methods

    Constructors

    Properties

    songs: Map<string, HTMLAudioElement> = ...

    Registered audio elements keyed by name. Subclasses read this; mutate via register.

    Accessors

    • get enabled(): boolean

      Whether playback is permitted. Setting to false invokes stop immediately.

      Returns boolean

    • set enabled(value: boolean): void

      Setting to false invokes stop immediately; subclasses (notably Music) may re-start playback when flipped back to true.

      Parameters

      • value: boolean

      Returns void

    Methods

    • Play the registered sound name once. Returns a promise that resolves when playback starts (or immediately if enabled is false) and rejects on autoplay/permission errors. Throws synchronously if no sounds are registered or name is unknown. Each call allocates a clone, so concurrent plays of the same name overlap.

      Parameters

      • name: string

      Returns Promise<void>

    • Load and register one or more audio files. Each entry may be a bare URL string (the file's basename becomes the name) or a RegisterData object. Per-song volume falls back to defaultVolume. Call once per instance — throws on a second invocation, on non-finite volume, or on volume outside [0, 1]. Load failures are logged to console.error but don't throw.

      Parameters

      • defaultVolume: number = 1
      • ...songs: (string | RegisterData)[]

      Returns void

    • Stop and forget every currently-playing clone. Also calls the base-class teardown.

      Returns void