mwg API
    Preparing search index...

    Class SfxSound

    The data-driven counterpart of Sound: it plays an SfxDefinition (or the id of one in a bank) through a backend, with the same play(gain, pitch) shape so a SoundSource can attenuate it, and a pan on top. It applies the definition's retrigger rule, asks the shared arbiter for a voice, fires the caption, and hands the backend a deterministic seed.

    import { SfxArbiter, SfxBank, SfxSound, SoundSource, AudioListener, type SfxBackend } from '@datamoc/mwg/audio';

    declare const chip: SfxBackend;

    const bank = new SfxBank([{ id: 'arrow', priority: 5, caption: 'an arrow flies' }]);
    const arrow = new SfxSound(chip, 'arrow', { bank, arbiter: new SfxArbiter(), frame: () => 0 });
    new SoundSource(arrow, { x: 3, y: 4 }).playFor(new AudioListener());
    Index
    plays: number = 0

    how many plays reached the backend, for a test to assert on without a speaker

    volume: number
    • plays the effect; returns false when it was ignored, refused by the arbiter or the backend had no voice

      Parameters

      • gain: number = 1
      • pitch: number = 1
      • pan: number = 0

      Returns boolean