melonJS
    Preparing search index...

    Interface PlayOptions

    Options accepted by audio.play in place of the positional loop argument.

    Every field is optional, and the positional form play(name, loop, onend, volume) continues to work unchanged.

    interface PlayOptions {
        at?: { x: number; y: number; z?: number };
        follow?: Renderable;
        loop?: boolean;
        onend?: () => void;
        sprite?: string;
        stopWithTarget?: boolean;
        volume?: number;
    }
    Index
    at?: { x: number; y: number; z?: number }

    Place this sound at a fixed world point. Same coordinates and same defaults as follow, for something that does not move.

    Mutually exclusive with follow: passing both throws, rather than quietly picking one and leaving the other looking broken.

    follow?: Renderable

    Place this sound at a renderable and keep it there, re-reading its world position every frame. Tracking stops when the renderable is destroyed.

    Positions are WORLD pixels, with +y down like everything else in melonJS; the Y flip Web Audio wants is applied for you. Sounds placed this way are given the pixel-shaped panner defaults, which audio.setSpatialDefaults() can change and audio.panner() overrides.

    loop?: boolean

    Loop playback when the region ends. Defaults to false.

    onend?: () => void

    Called when this instance finishes playing.

    sprite?: string

    Name of a region declared in the clip's sprite map. Omit to play the whole clip.

    stopWithTarget?: boolean

    Stop the sound when the renderable it follows is destroyed, rather than leaving it playing where the renderable was. Defaults to false.

    Note that stopping discards the playback id, so keep this false for a looping sound you intend to reposition and resume later.

    volume?: number

    Playback volume, 0.0..1.0. Defaults to the current global volume.