mwg API
    Preparing search index...

    Class Sound

    A sound effect, pooled so the same clip can overlap itself. A dozen arrows landing in the same second must not cut each other off, which a single <audio> element would - the next play just steals the oldest of the pool, round-robin, rather than restarting the one already mid-sound.

    import { Sound } from '@datamoc/mwg/audio';

    const hit = new Sound('sounds/hit.mp3', { poolSize: 6, caption: 'a sword strikes' });
    hit.play(); // safe to call several times in the same second
    Index
    plays: number = 0

    how many times play actually started a clip (not counting calls made while suspended), for a test to assert on without a microphone

    volume: number
    • Plays one instance from the pool.

      Parameters

      • gain: number = 1

        multiplied into the sound's own volume, for a distance-attenuated one-shot (Positional.SoundSource.playFor); 1 leaves it at volume.

      • pitch: number = 1

        played back at this rate, matching HTMLAudioElement.playbackRate (1 is unchanged, above 1 higher and faster, below 1 lower and slower) - a footstep or a hit that always sounds identical reads as a loop faster than one with a little variance. There is no matching pan parameter: a plain <audio> element has no pan of its own to set, and Positional.audioPan already made the deliberate call to report a number rather than own a panner node a game does not necessarily want - the same reasoning applies here.

      Returns void

    • Cuts in-flight one-shots and silences later play calls until resume - the page-hide half of Music.suspend. One-shots have nothing to restart, so resume only re-enables.

      Returns void