PokéRogue
    Preparing search index...

    Base class containing all the shared state and behavior of a sound object, independent of the audio implementation (Web Audio or HTML5 Audio). Manages playback state (play, pause, stop, seek), looping, volume, rate, detune, markers for playing sub-sections of audio, and event emission for playback lifecycle changes.

    Hierarchy (View Summary)

    Index
    currentMarker: SoundMarker

    Currently playing marker. 'null' if whole sound is playing.

    duration: number

    A value representing the duration, in seconds. It could be total sound duration or a marker duration.

    isPaused: boolean

    Flag indicating if sound is currently paused.

    isPlaying: boolean

    Flag indicating if sound is currently playing.

    key: string

    Asset key for the sound.

    Local reference to the sound manager.

    markers: { [key: string]: SoundMarker }

    Object containing markers definitions.

    pendingRemove: boolean

    Flag indicating if destroy method was called on this sound.

    totalDuration: number

    The total duration of the sound in seconds.

    totalRate: number

    A property that holds the value of sound's actual playback rate, after its rate and detune values have been combined with global rate and detune values.

    • Add a listener for a given event.

      Parameters

      • event: string | symbol

        The event name.

      • fn: Function

        The listener function.

      • Optionalcontext: any

        The context to invoke the listener with. Default this.

      Returns this

      this.

    • Adds a marker into the current sound. A marker is represented by name, start time, duration, and optionally config object. This allows you to bundle multiple sounds together into a single audio file and use markers to jump between them for playback.

      Parameters

      Returns boolean

      Whether the marker was added successfully.

    • Method used internally for applying config values to some of the sound properties.

      Returns void

    • Method used internally to calculate total playback rate of the sound.

      Returns void

    • Destroys this sound and all associated events and marks it for removal from the sound manager.

      Returns void

    • Calls each of the listeners registered for a given event.

      Parameters

      • event: string | symbol

        The event name.

      • ...args: any[]

        Additional arguments that will be passed to the event handler.

      Returns boolean

      true if the event had listeners, else false.

    • Return an array listing the events for which the emitter has registered listeners.undefined

      Returns (string | symbol)[]

      undefined

    • Return the number of listeners listening to a given event.

      Parameters

      • event: string | symbol

        The event name.

      Returns number

      The number of listeners.

    • Return the listeners registered for a given event.

      Parameters

      • event: string | symbol

        The event name.

      Returns Function[]

      The registered listeners.

    • Remove the listeners of a given event.

      Parameters

      • event: string | symbol

        The event name.

      • Optionalfn: Function

        Only remove the listeners that match this function.

      • Optionalcontext: any

        Only remove the listeners that have this context.

      • Optionalonce: boolean

        Only remove one-time listeners.

      Returns this

      this.

    • Add a listener for a given event.

      Parameters

      • event: string | symbol

        The event name.

      • fn: Function

        The listener function.

      • Optionalcontext: any

        The context to invoke the listener with. Default this.

      Returns this

      this.

    • Add a one-time listener for a given event. The listener is automatically removed the first time the event is emitted, so it will never be called more than once.

      Parameters

      • event: string | symbol

        The event name.

      • fn: Function

        The listener function.

      • Optionalcontext: any

        The context to invoke the listener with. Default this.

      Returns this

      this.

    • Pauses the sound. This only works if the sound is currently playing.

      You can inspect the isPlaying and isPaused properties to check the state.undefined

      Returns boolean

      Whether the sound was paused successfully.

    • Play this sound, or a marked section of it.

      It always plays the sound from the start. If you want to start playback from a specific time you can set 'seek' setting of the config object, provided to this call, to that value.

      Parameters

      • OptionalmarkerName: string | SoundConfig

        If you want to play a marker then provide the marker name here. Alternatively, this parameter can be a SoundConfig object. Default ''.

      • Optionalconfig: SoundConfig

        Optional sound config object to be applied to this marker or entire sound if no marker name is provided. It gets memorized for future plays of current section of the sound.

      Returns boolean

      Whether the sound started playing successfully.

    • Remove all listeners, or those of the specified event.

      Parameters

      • Optionalevent: string | symbol

        The event name.

      Returns this

      this.

    • Remove the listeners of a given event.

      Parameters

      • event: string | symbol

        The event name.

      • Optionalfn: Function

        Only remove the listeners that match this function.

      • Optionalcontext: any

        Only remove the listeners that have this context.

      • Optionalonce: boolean

        Only remove one-time listeners.

      Returns this

      this.

    • Removes a marker from the sound.

      Parameters

      • markerName: string

        The name of the marker to remove.

      Returns SoundMarker | null

      Removed marker object or 'null' if there was no marker with provided name.

    • Method used internally for resetting values of some of the config properties.

      Returns void

    • Resumes the sound. This only works if the sound is paused and not already playing.

      You can inspect the isPlaying and isPaused properties to check the state.undefined

      Returns boolean

      Whether the sound was resumed successfully.

    • Removes all listeners from this EventEmitter. This method is called automatically by the Scene Systems when the parent Scene shuts down, ensuring that all event bindings are cleared and no stale references remain.

      Returns void

    • Stop playing this sound.undefined

      Returns boolean

      Whether the sound was stopped successfully.

    • Update method called automatically by sound manager on every game step.

      Parameters

      • time: number

        The current timestamp as generated by the Request Animation Frame or SetTimeout.

      • delta: number

        The delta time elapsed since the last frame.

      Returns void

    • Updates a previously added marker with new values from the provided marker object.

      Parameters

      • marker: SoundMarker

        Marker object with updated values.

      Returns boolean

      Whether the marker was updated successfully.