mwg API
    Preparing search index...

    Class SoundSource

    One positional one-shot: a Sound attached to a point in the world, heard from a listener with the distance gain audioGain computes. playFor applies that gain through Sound.play(gain), and stays silent past maxDistance rather than playing at volume 0.

    Long-running position (a waterfall, an engine) is the game's own loop calling playFor on a cadence it chooses; this is the placement and the mix, not a scheduler.

    import { AudioListener, Sound, SoundSource } from '@datamoc/mw_games/audio';

    const listener = new AudioListener({ x: 0, y: 0 });
    const arrow = new Sound('sounds/arrow.mp3');
    const source = new SoundSource(arrow, { x: 6, y: 8, refDistance: 4, maxDistance: 20 });

    const gain = source.gainTo(listener); // 0.4 at distance 10
    source.playFor(listener); // plays at that gain, or not at all when silent

    Implements

    Index
    x y
    x: number
    y: number