new HTML5AudioSoundManager(game)
name | type | description |
---|---|---|
game | Phaser.Game |
Reference to the current game instance. |
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.
Global detuning of all sounds in cents. The range of the value is -1200 to 1200, but we recommend setting it to 50.
Local reference to game.
Local reference to the JSON Cache, as used by Audio Sprites.
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.
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.
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.
Flag indicating if sounds should be paused when game looses focus, for instance when user switches to another tab/program/app.
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.
Adds a new sound into the sound manager.
name | type | arguments | description |
---|---|---|---|
key | string |
Asset key for the sound. |
|
config | Phaser.Types.Sound.SoundConfig | <optional> |
An optional config object containing default sound settings. |
The new sound instance.
Adds a new audio sprite sound into the sound manager. Audio Sprites are a combination of audio files and a JSON configuration. The JSON follows the format of that created by https://github.com/tonistiigi/audiosprite
name | type | arguments | description |
---|---|---|---|
key | string |
Asset key for the sound. |
|
config | Phaser.Types.Sound.SoundConfig | <optional> |
An optional config object containing default sound settings. |
The new audio sprite sound instance.
Add a listener for a given event.
name | type | arguments | Default | description |
---|---|---|---|---|
event | string | symbol |
The event name. |
||
fn | function |
The listener function. |
||
context | * | <optional> | this |
The context to invoke the listener with. |
this
.
Calls Phaser.Sound.BaseSoundManager#destroy method and cleans up all HTML5 Audio related stuff.
Calls each of the listeners registered for a given event.
name | type | arguments | description |
---|---|---|---|
event | string | symbol |
The event name. |
|
args | * | <optional> |
Additional arguments that will be passed to the event handler. |
true
if the event had listeners, else false
.
Return an array listing the events for which the emitter has registered listeners.
Gets the first sound in the manager matching the given key, if any.
name | type | description |
---|---|---|
key | string |
Sound asset key. |
Gets any sounds in the manager matching the given key.
name | type | description |
---|---|---|
key | string |
Sound asset key. |
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.
name | type | arguments | description |
---|---|---|---|
sound | Phaser.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. |
|
value | * | <optional> |
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. |
Whether the sound manager is locked.
Return the number of listeners listening to a given event.
name | type | description |
---|---|---|
event | string | symbol |
The event name. |
The number of listeners.
Return the listeners registered for a given event.
name | type | description |
---|---|---|
event | string | symbol |
The event name. |
The registered listeners.
Remove the listeners of a given event.
name | type | arguments | description |
---|---|---|---|
event | string | symbol |
The event name. |
|
fn | function | <optional> |
Only remove the listeners that match this function. |
context | * | <optional> |
Only remove the listeners that have this context. |
once | boolean | <optional> |
Only remove one-time listeners. |
this
.
Add a listener for a given event.
name | type | arguments | Default | description |
---|---|---|---|---|
event | string | symbol |
The event name. |
||
fn | function |
The listener function. |
||
context | * | <optional> | this |
The context to invoke the listener with. |
this
.
Method used internally for pausing sound manager if Phaser.Sound.HTML5AudioSoundManager#pauseOnBlur is set to true.
Method used internally for resuming sound manager if Phaser.Sound.HTML5AudioSoundManager#pauseOnBlur is set to true.
Add a one-time listener for a given event.
name | type | arguments | Default | description |
---|---|---|---|---|
event | string | symbol |
The event name. |
||
fn | function |
The listener function. |
||
context | * | <optional> | this |
The context to invoke the listener with. |
this
.
Pauses all the sounds in the game.
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.
name | type | arguments | description |
---|---|---|---|
key | string |
Asset key for the sound. |
|
extra | Phaser.Types.Sound.SoundConfig | Phaser.Types.Sound.SoundMarker | <optional> |
An optional additional object containing settings to be applied to the sound. It could be either config or marker object. |
Whether the sound started playing successfully.
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.
name | type | arguments | description |
---|---|---|---|
key | string |
Asset key for the sound. |
|
spriteName | string |
The name of the sound sprite to play. |
|
config | Phaser.Types.Sound.SoundConfig | <optional> |
An optional config object containing default sound settings. |
Whether the audio sprite sound started playing successfully.
Removes a sound from the sound manager. The removed sound is destroyed before removal.
name | type | description |
---|---|---|
sound | Phaser.Sound.BaseSound |
The sound object to remove. |
True if the sound was removed successfully, otherwise false.
Removes all sounds from the manager, destroying the sounds.
Remove all listeners, or those of the specified event.
name | type | arguments | description |
---|---|---|---|
event | string | symbol | <optional> |
The event name. |
this
.
Removes all sounds from the sound manager that have an asset key matching the given value. The removed sounds are destroyed before removal.
name | type | description |
---|---|---|
key | string |
The key to match when removing sound objects. |
The number of matching sound objects that were removed.
Remove the listeners of a given event.
name | type | arguments | description |
---|---|---|---|
event | string | symbol |
The event name. |
|
fn | function | <optional> |
Only remove the listeners that match this function. |
context | * | <optional> |
Only remove the listeners that have this context. |
once | boolean | <optional> |
Only remove one-time listeners. |
this
.
Resumes all the sounds in the game.
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.
name | type | description |
---|---|---|
value | number |
The range of the value is -1200 to 1200, but we recommend setting it to 50. |
This Sound Manager.
Sets the muted state of all this Sound Manager.
name | type | description |
---|---|---|
value | boolean |
|
This Sound Manager.
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.
name | type | description |
---|---|---|
value | number |
Global playback rate at which all the sounds will be played. |
This Sound Manager.
Sets the volume of this Sound Manager.
name | type | description |
---|---|---|
value | number |
The global volume of this Sound Manager. |
This Sound Manager.
Removes all listeners.
Stops all the sounds in the game.
Stops any sounds matching the given key.
name | type | description |
---|---|---|
key | string |
Sound asset key. |
Unlocks HTML5 Audio loading and playback on mobile devices on the initial explicit user interaction.
Update method called on every game step. Removes destroyed sounds and updates every active sound in the game.
name | type | description |
---|---|---|
time | number |
The current timestamp as generated by the Request Animation Frame or SetTimeout. |
delta | number |
The delta time elapsed since the last frame. |