phaser - v4.0.0-rc.4
    Preparing search index...

    Class HTML5AudioSoundManager

    HTML5AudioSoundManager

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    audioPlayDelay: number

    Value representing time difference, in seconds, between calling play method on an audio tag and when it actually starts playing. It is used to achieve more accurate delayed sound playback.

    You might need to tweak this value to get the desired results since audio play delay varies depending on the browser/platform.

    detune: number

    Global detuning of all sounds in cents. The range of the value is -1200 to 1200, but we recommend setting it to 50.

    game: Game

    Local reference to game.

    gameLostFocus: boolean

    Flag used to track if the game has lost focus.

    jsonCache: BaseCache

    Local reference to the JSON Cache, as used by Audio Sprites.

    listenerPosition: Math.Vector2

    The Spatial Audio listener position.

    Only available with WebAudio.

    You can modify the x/y properties of this Vec2 directly to adjust the listener position within the game world.

    locked: boolean

    Mobile devices require sounds to be triggered from an explicit user action, such as a tap, before any sound can be loaded/played on a web page. Set to true if the audio system is currently locked awaiting user interaction.

    loopEndOffset: number

    A value by which we should offset the loop end marker of the looping sound to compensate for lag, caused by changing audio tag playback position, in order to achieve gapless looping.

    You might need to tweak this value to get the desired results since loop lag varies depending on the browser/platform.

    mute: boolean

    Global mute setting.

    override: boolean

    Flag indicating whether if there are no idle instances of HTML5 Audio tag, for any particular sound, if one of the used tags should be hijacked and used for succeeding playback or if succeeding Phaser.Sound.HTML5AudioSound#play call should be ignored.

    pauseOnBlur: boolean

    Flag indicating if sounds should be paused when game looses focus, for instance when user switches to another tab/program/app.

    rate: number

    Global playback rate at which all the sounds will be played. Value of 1.0 plays the audio at full speed, 0.5 plays the audio at half speed and 2.0 doubles the audio's playback speed.

    volume: number

    Global volume setting.

    Methods

    • 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

    • 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

    • Gets all sounds in this Sound Manager.

      You can optionally specify a key, in which case only Sound instances that match the given key will be returned.

      Type Parameters

      Parameters

      • Optionalkey: string

        Optional asset key. If given, only Sound instances with this key will be returned.

      Returns T[]

    • Method used internally by Phaser.Sound.HTML5AudioSound class methods and property setters to check if sound manager is locked and then either perform action immediately or queue it to be performed once the sound manager gets unlocked.

      Parameters

      • sound: HTML5AudioSound

        Sound object on which to perform queued action.

      • prop: string

        Name of the method to be called or property to be assigned a value to.

      • Optionalvalue: any

        An optional parameter that either holds an array of arguments to be passed to the method call or value to be set to the property.

      Returns boolean

    • When a key is given, returns true if any sound with that key is playing.

      When no key is given, returns true if any sound is playing.

      Parameters

      • key: string

        Sound asset key.

      Returns boolean

    • Return the listeners registered for a given event.

      Parameters

      • event: string | symbol

        The event name.

      Returns Function[]

    • 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

    • 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

    • Add a one-time 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

    • Adds a new sound to the sound manager and plays it.

      The sound will be automatically removed (destroyed) once playback ends.

      This lets you play a new sound on the fly without the need to keep a reference to it.

      Parameters

      • key: string

        Asset key for the sound.

      • Optionalextra: SoundConfig | SoundMarker

        An optional additional object containing settings to be applied to the sound. It could be either config or marker object.

      Returns boolean

    • Adds a new audio sprite sound to the sound manager and plays it. The sprite will be automatically removed (destroyed) once playback ends. This lets you play a new sound on the fly without the need to keep a reference to it.

      Parameters

      • key: string

        Asset key for the sound.

      • spriteName: string

        The name of the sound sprite to play.

      • Optionalconfig: SoundConfig

        An optional config object containing default sound settings.

      Returns boolean

    • Removes all sounds from the sound manager that have an asset key matching the given value. The removed sounds are destroyed before removal.

      Parameters

      • key: string

        The key to match when removing sound objects.

      Returns number

    • 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

    • Sets the global detuning of all sounds in cents. The range of the value is -1200 to 1200, but we recommend setting it to 50.

      Parameters

      • value: number

        The range of the value is -1200 to 1200, but we recommend setting it to 50.

      Returns this

    • Sets the X and Y position of the Spatial Audio listener on this Web Audios context.

      If you call this method with no parameters it will default to the center-point of the game canvas. Depending on the type of game you're making, you may need to call this method constantly to reset the listener position as the camera scrolls.

      Calling this method does nothing on HTML5Audio.

      Parameters

      • Optionalx: number

        The x position of the Spatial Audio listener.

      • Optionaly: number

        The y position of the Spatial Audio listener.

      Returns void

    • Sets the global playback rate at which all the sounds will be played.

      For example, a value of 1.0 plays the audio at full speed, 0.5 plays the audio at half speed and 2.0 doubles the audios playback speed.

      Parameters

      • value: number

        Global playback rate at which all the sounds will be played.

      Returns this

    • Update method called on every game step. Removes destroyed sounds and updates every active sound in the game.

      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