No-audio implementation of the Sound Manager. It is used if audio has been disabled in the game config or the device doesn't support any audio.
It represents a graceful degradation of Sound Manager logic that provides minimal functionality and prevents Phaser projects that use audio from breaking on devices that don't support any audio playback technologies.
new NoAudioSoundManager(game)
name | type | description |
---|---|---|
game | Phaser.Game |
Reference to the current game instance. |
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.
Flag used to track if the game has lost focus.
Local reference to the JSON Cache, as used by Audio Sprites.
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.
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.
Global mute setting.
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.
Global volume setting.
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
.
Destroys all the sounds in the game and all associated events.
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. |
Returns all sounds from this Sound Manager that are currently
playing. That is, Sound instances that have their isPlaying
property set to true
.
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.
name | type | description |
---|---|---|
key | string |
Sound asset key. |
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
.
Empty function for the No Audio Sound Manager.
Empty function for the No Audio Sound Manager.
Empty function for the No Audio Sound Manager.
Empty function for the No Audio Sound Manager.
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
.
Empty function for the No Audio Sound Manager.
This method does nothing but return 'false' for the No Audio Sound Manager, to maintain compatibility with the other Sound Managers.
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. |
Always 'false' for the No Audio Sound Manager.
This method does nothing but return 'false' for the No Audio Sound Manager, to maintain compatibility with the other Sound Managers.
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. |
Always 'false' for the No Audio Sound Manager.
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
.
Empty function for the No Audio Sound Manager.
Empty function for the No Audio Sound Manager.
This Sound Manager.
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.
name | type | arguments | description |
---|---|---|---|
x | number | <optional> |
The x position of the Spatial Audio listener. |
y | number | <optional> |
The y position of the Spatial Audio listener. |
Empty function for the No Audio Sound Manager.
Empty function for the No Audio Sound Manager.
This Sound Manager.
Empty function for the No Audio Sound Manager.
Removes all listeners.
Empty function for the No Audio Sound Manager.
Stops any sounds matching the given key.
name | type | description |
---|---|---|
key | string |
Sound asset key. |
Empty function for the No Audio Sound Manager.
Empty function for the No Audio Sound Manager.