Class containing all the shared state and behavior of a sound object, independent of the implementation.
new BaseSound(manager, key, [config])
name | type | arguments | description |
---|---|---|---|
manager | Phaser.Sound.BaseSoundManager |
Reference to the current sound manager instance. |
|
key | string |
Asset key for the sound. |
|
config | Phaser.Types.Sound.SoundConfig | <optional> |
An optional config object containing default sound settings. |
Currently playing marker. 'null' if whole sound is playing.
A value representing the duration, in seconds. It could be total sound duration or a marker duration.
Flag indicating if sound is currently paused.
Flag indicating if sound is currently playing.
Asset key for the sound.
Local reference to the sound manager.
Object containing markers definitions.
Flag indicating if destroy method was called on this sound.
The total duration of the sound in seconds.
A property that holds the value of sound's actual playback rate, after its rate and detune values has been combined with global rate and detune values.
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
.
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.
name | type | description |
---|---|---|
marker | Phaser.Types.Sound.SoundMarker |
Marker object. |
Whether the marker was added successfully.
Method used internally for applying config values to some of the sound properties.
Method used internally to calculate total playback rate of the sound.
Destroys this sound and all associated events and marks it for removal from the sound manager.
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.
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
.
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 the sound. This only works if the sound is currently playing.
You can inspect the isPlaying
and isPaused
properties to check the state.
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.
name | type | arguments | Default | description |
---|---|---|---|---|
markerName | string | Phaser.Types.Sound.SoundConfig | <optional> | '' |
If you want to play a marker then provide the marker name here. Alternatively, this parameter can be a SoundConfig object. |
config | Phaser.Types.Sound.SoundConfig | <optional> |
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. |
Whether the sound started playing successfully.
Remove all listeners, or those of the specified event.
name | type | arguments | description |
---|---|---|---|
event | string | symbol | <optional> |
The event name. |
this
.
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
.
Removes a marker from the sound.
name | type | description |
---|---|---|
markerName | string |
The name of the marker to remove. |
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.
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.
Whether the sound was resumed successfully.
Removes all listeners.
Stop playing this sound.
Whether the sound was stopped successfully.
Update method called automatically by sound manager on every game step.
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. |
Updates previously added marker.
name | type | description |
---|---|---|
marker | Phaser.Types.Sound.SoundMarker |
Marker object with updated values. |
Whether the marker was updated successfully.