PokéRogue
    Preparing search index...

    Class representing a single background music track.

    Operations on a BGM object may be deferred for an indefinite amount of time until the underlying Phaser sound object loads. It is not possible to preload these sounds as they are massive. For this reason, a BGM object is liable to be destroyed before any/all of these operations complete, including the music actually starting. The exception is callbacks registered to onEnd, which will always run regardless of if the music is able to start and stop cleanly.

    Index

    Constructors

    • Parameters

      • key: string

        The bgm to use

      • loop: boolean

        Whether to loop the bgm

      • loopPoint: number = 0

        (Default 0) The starting point of the loop, in seconds

      Returns BackgroundMusic

    Properties

    destroyed: boolean = false

    Whether this BGM has been evicted from memory.

    endCallbacks: (() => void)[] = []

    Callbacks registered via onEnd, awaiting the end of the track or destruction.

    ended: boolean = false

    Whether this track has ended (either naturally or via destroy).

    key: string

    The key for the audio file

    pendingCalls: (() => void)[] = []

    Operations queued before the sound finished loading.

    sound: AnySound | undefined

    The underlying sound instance used to stream music.

    refCounts: Map<string, number> = ...

    Maps the number of active BGM objects for a particular key.

    This will almost always be 1, but with i.e. paused/resumed music it may be more.

    Accessors

    Methods

    • Fade the volume to zero over duration ms.

      Parameters

      • duration: number

        Fade time in milliseconds

      • fixed: boolean = false

        (Default false) Whether duration should ignore game speed

      • destroy: boolean = true

        (Default true) Whether to destroy the bgm after fading out, or just pause it

      Returns void

    • Add a callback to run when this track ends.

      Parameters

      • callback: () => void

        The callback to run

      Returns void

      Callbacks added here are guaranteed to run exactly once, so operations like phase transitions on BGM end are safe.

    • Begin playing after delay real-time milliseconds.

      Parameters

      • delay: number

        The delay before play in milliseconds (speed-sensitive unless FixedInt is passed)

      • Optionalvolume: number

        Volume to play at

      Returns void

    • Run an operation immediately, or defer it until the sound has loaded.

      Parameters

      • operation: (sound: AnySound) => void

        The function to run on ready

      Returns void