mwg API
    Preparing search index...

    Class Music

    Background music with crossfade: switching tracks fades the old one out and the new one in over the same span, rather than cutting straight from one to the other. Like AnimatedSprite, nothing advances on its own - call update(dt) from the scene.

    import { Music } from '@datamoc/mw_games/audio';

    const music = new Music({ volume: 0.7 });
    music.play('music/town.mp3', 2); // crossfades in over 2 seconds

    // in the game loop:
    music.update(1 / 60);
    Index
    volume: number
    • Parameters

      • path: string
      • fadeDuration: number = 1

        seconds; 0 switches immediately with no crossfade

      Returns void

    • Plays the supplied sequence repeatedly. This is deliberately small and backend-agnostic: callers can repeat entries to weight a track, while HTMLAudioElement's optional onended advances the queue when available.

      Parameters

      • paths: readonly string[]
      • fadeDuration: number = 1

      Returns void

    • Parameters

      • fadeDuration: number = 1

      Returns void