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.

    The sound sits at the renderable's getAbsolutePosition(), which is where its anchorPoint sits: its center under the (0.5, 0.5) default of a Renderable or a Sprite, but its TOP-LEFT corner under the (0, 0) of an Entity or of any object loaded from Tiled. For a large entity, such as a boss, that puts the sound half its size up and to the left of where it looks to be.

    loop?: boolean

    Loop playback when the region ends. Defaults to the region's own loop flag (the third element of its sprite entry), else 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.