new BaseSound(manager, key [, config])
Parameters:
Name | Type | Argument | 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. |
- Since: 3.0.0
- Source: src/sound/BaseSound.js (Line 14)
Extends
Members
-
<readonly> currentMarker :Phaser.Types.Sound.SoundMarker
-
Currently playing marker. 'null' if whole sound is playing.
Type:
- Since: 3.0.0
- Default Value:
-
- null
- Source: src/sound/BaseSound.js (Line 160)
-
<readonly> duration :number
-
A value representing the duration, in seconds. It could be total sound duration or a marker duration.
Type:
- number
- Since: 3.0.0
- Source: src/sound/BaseSound.js (Line 93)
-
<readonly> isPaused :boolean
-
Flag indicating if sound is currently paused.
Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- false
- Source: src/sound/BaseSound.js (Line 69)
-
<readonly> isPlaying :boolean
-
Flag indicating if sound is currently playing.
Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- false
- Source: src/sound/BaseSound.js (Line 58)
-
<readonly> key :string
-
Asset key for the sound.
Type:
- string
- Since: 3.0.0
- Source: src/sound/BaseSound.js (Line 48)
-
<readonly> markers :Object.<string, Phaser.Types.Sound.SoundMarker>
-
Object containing markers definitions.
Type:
- Object.<string, Phaser.Types.Sound.SoundMarker>
- Since: 3.0.0
- Default Value:
-
- {}
- Source: src/sound/BaseSound.js (Line 149)
-
<readonly> totalDuration :number
-
The total duration of the sound in seconds.
Type:
- number
- Since: 3.0.0
- Source: src/sound/BaseSound.js (Line 104)
-
<readonly> totalRate :number
-
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.
Type:
- number
- Since: 3.0.0
- Default Value:
-
- 1
- Source: src/sound/BaseSound.js (Line 80)
Methods
-
addListener(event, fn [, context])
-
Add a listener for a given event.
Parameters:
Name Type Argument Default Description event
string | symbol The event name.
fn
function The listener function.
context
* <optional>
this The context to invoke the listener with.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 111)
Returns:
this
. -
addMarker(marker)
-
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:
Name Type Description marker
Phaser.Types.Sound.SoundMarker Marker object.
- Since: 3.0.0
- Source: src/sound/BaseSound.js (Line 184)
Returns:
Whether the marker was added successfully.
- Type
- boolean
-
<protected> applyConfig()
-
Method used internally for applying config values to some of the sound properties.
- Since: 3.0.0
- Source: src/sound/BaseSound.js (Line 409)
-
<protected> calculateRate()
-
Method used internally to calculate total playback rate of the sound.
- Since: 3.0.0
- Source: src/sound/BaseSound.js (Line 452)
-
destroy()
-
Destroys this sound and all associated events and marks it for removal from the sound manager.
- Since: 3.0.0
- Overrides:
- Source: src/sound/BaseSound.js (Line 468)
Fires:
-
emit(event [, args])
-
Calls each of the listeners registered for a given event.
Parameters:
Name Type Argument Description event
string | symbol The event name.
args
* <optional>
<repeatable>
Additional arguments that will be passed to the event handler.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 86)
Returns:
true
if the event had listeners, elsefalse
.- Type
- boolean
-
eventNames()
-
Return an array listing the events for which the emitter has registered listeners.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 55)
Returns:
- Type
- Array.<(string|symbol)>
-
listenerCount(event)
-
Return the number of listeners listening to a given event.
Parameters:
Name Type Description event
string | symbol The event name.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 75)
Returns:
The number of listeners.
- Type
- number
-
listeners(event)
-
Return the listeners registered for a given event.
Parameters:
Name Type Description event
string | symbol The event name.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 64)
Returns:
The registered listeners.
- Type
- Array.<function()>
-
off(event [, fn] [, context] [, once])
-
Remove the listeners of a given event.
Parameters:
Name Type Argument 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.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 151)
Returns:
this
. -
on(event, fn [, context])
-
Add a listener for a given event.
Parameters:
Name Type Argument Default Description event
string | symbol The event name.
fn
function The listener function.
context
* <optional>
this The context to invoke the listener with.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 98)
Returns:
this
. -
once(event, fn [, context])
-
Add a one-time listener for a given event.
Parameters:
Name Type Argument Default Description event
string | symbol The event name.
fn
function The listener function.
context
* <optional>
this The context to invoke the listener with.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 124)
Returns:
this
. -
pause()
-
Pauses the sound.
- Since: 3.0.0
- Source: src/sound/BaseSound.js (Line 344)
Returns:
Whether the sound was paused successfully.
- Type
- boolean
-
play( [markerName] [, config])
-
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:
Name Type Argument 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.
- Since: 3.0.0
- Source: src/sound/BaseSound.js (Line 285)
Returns:
Whether the sound started playing successfully.
- Type
- boolean
-
removeAllListeners( [event])
-
Remove all listeners, or those of the specified event.
Parameters:
Name Type Argument Description event
string | symbol <optional>
The event name.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 165)
Returns:
this
. -
removeListener(event [, fn] [, context] [, once])
-
Remove the listeners of a given event.
Parameters:
Name Type Argument 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.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 137)
Returns:
this
. -
removeMarker(markerName)
-
Removes a marker from the sound.
Parameters:
Name Type Description markerName
string The name of the marker to remove.
- Since: 3.0.0
- Source: src/sound/BaseSound.js (Line 261)
Returns:
Removed marker object or 'null' if there was no marker with provided name.
-
<protected> resetConfig()
-
Method used internally for resetting values of some of the config properties.
- Since: 3.0.0
- Source: src/sound/BaseSound.js (Line 426)
-
resume()
-
Resumes the sound.
- Since: 3.0.0
- Source: src/sound/BaseSound.js (Line 365)
Returns:
Whether the sound was resumed successfully.
- Type
- boolean
-
shutdown()
-
Removes all listeners.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 31)
-
stop()
-
Stop playing this sound.
- Since: 3.0.0
- Source: src/sound/BaseSound.js (Line 386)
Returns:
Whether the sound was stopped successfully.
- Type
- boolean
-
<protected> update(time, delta)
-
Update method called automatically by sound manager on every game step.
Parameters:
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.
- Since: 3.0.0
- Source: src/sound/BaseSound.js (Line 439)
-
updateMarker(marker)
-
Updates previously added marker.
Parameters:
Name Type Description marker
Phaser.Types.Sound.SoundMarker Marker object with updated values.
- Since: 3.0.0
- Source: src/sound/BaseSound.js (Line 231)
Returns:
Whether the marker was updated successfully.
- Type
- boolean