Phaser API Documentation

  Version: 
Filter

Class containing all the shared state and behavior of a sound object, independent of the implementation.

Constructor:

new BaseSound(manager, key, [config])

Parameters:

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.

Since: 3.0.0
Source: src/sound/BaseSound.js (Line 14)

Extends


Members

<private> config: Phaser.Types.Sound.SoundConfig
Focus
Focus

Description:

A config object used to store default sound settings' values. Default values will be set by properties' setters.

Type:
Since: 3.0.0
Source: src/sound/BaseSound.js (Line 113)
Focus
Focus
<private> currentConfig: Phaser.Types.Sound.SoundConfig
Focus
Focus

Description:

Reference to the currently used config. It could be default config or marker config.

Type:
Since: 3.0.0
Source: src/sound/BaseSound.js (Line 135)
Focus
Focus
<readonly> currentMarker: Phaser.Types.Sound.SoundMarker
Focus
Focus

Description:

Currently playing marker. 'null' if whole sound is playing.

Type:
Default: null
Since: 3.0.0
Source: src/sound/BaseSound.js (Line 159)
Focus
Focus
<readonly> duration: number
Focus
Focus

Description:

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 92)
Focus
Focus
<readonly> isPaused: boolean
Focus
Focus

Description:

Flag indicating if sound is currently paused.

Type:
boolean
Default: false
Since: 3.0.0
Source: src/sound/BaseSound.js (Line 68)
Focus
Focus
<readonly> isPlaying: boolean
Focus
Focus

Description:

Flag indicating if sound is currently playing.

Type:
boolean
Default: false
Since: 3.0.0
Source: src/sound/BaseSound.js (Line 57)
Focus
Focus
<readonly> key: string
Focus
Focus

Description:

Asset key for the sound.

Type:
string
Since: 3.0.0
Source: src/sound/BaseSound.js (Line 47)
Focus
Focus

Description:

Local reference to the sound manager.

Type:
Since: 3.0.0
Source: src/sound/BaseSound.js (Line 38)
Focus
Focus
<readonly> markers: Object.<string, Phaser.Types.Sound.SoundMarker>
Focus
Focus

Description:

Object containing markers definitions.

Type:
Default: {}
Since: 3.0.0
Source: src/sound/BaseSound.js (Line 148)
Focus
Focus
pendingRemove: boolean
Focus
Focus

Description:

Flag indicating if destroy method was called on this sound.

Type:
boolean
Default: false
Since: 3.0.0
Source: src/sound/BaseSound.js (Line 171)
Focus
Focus
<readonly> totalDuration: number
Focus
Focus

Description:

The total duration of the sound in seconds.

Type:
number
Since: 3.0.0
Source: src/sound/BaseSound.js (Line 103)
Focus
Focus
<readonly> totalRate: number
Focus
Focus

Description:

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
Default: 1
Since: 3.0.0
Source: src/sound/BaseSound.js (Line 79)
Focus
Focus

Methods

addListener(event, fn, [context])
Focus
Focus

Description:

Add a listener for a given event.

Parameters:

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.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#addListener
Since: 3.0.0
Focus
Focus
addMarker(marker)
Focus
Focus

Description:

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.

Returns:
Description:

Whether the marker was added successfully.

Type:
  • boolean
Since: 3.0.0
Source: src/sound/BaseSound.js (Line 182)
Focus
Focus
applyConfig()
Focus
Focus

Description:

Method used internally for applying config values to some of the sound properties.

Since: 3.0.0
Source: src/sound/BaseSound.js (Line 412)
Focus
Focus
calculateRate()
Focus
Focus

Description:

Method used internally to calculate total playback rate of the sound.

Since: 3.0.0
Source: src/sound/BaseSound.js (Line 451)
Focus
Focus
destroy()
Focus
Focus

Description:

Destroys this sound and all associated events and marks it for removal from the sound manager.

Overrides: Phaser.Events.EventEmitter#destroy
Since: 3.0.0
Source: src/sound/BaseSound.js (Line 466)
Focus
Focus
emit(event, [args])
Focus
Focus

Description:

Calls each of the listeners registered for a given event.

Parameters:

name type arguments description
event string | symbol

The event name.

args * <optional>

Additional arguments that will be passed to the event handler.

Returns:
Description:

true if the event had listeners, else false.

Type:
  • boolean
Inherited from: Phaser.Events.EventEmitter#emit
Since: 3.0.0
Focus
Focus
eventNames()
Focus
Focus

Description:

Return an array listing the events for which the emitter has registered listeners.

Type:
  • Array.<(string
  • symbol)>
Inherited from: Phaser.Events.EventEmitter#eventNames
Since: 3.0.0
Focus
Focus
listenerCount(event)
Focus
Focus

Description:

Return the number of listeners listening to a given event.

Parameters:

name type description
event string | symbol

The event name.

Returns:
Description:

The number of listeners.

Type:
  • number
Inherited from: Phaser.Events.EventEmitter#listenerCount
Since: 3.0.0
Focus
Focus
listeners(event)
Focus
Focus

Description:

Return the listeners registered for a given event.

Parameters:

name type description
event string | symbol

The event name.

Returns:
Description:

The registered listeners.

Type:
  • Array.<function()>
Inherited from: Phaser.Events.EventEmitter#listeners
Since: 3.0.0
Focus
Focus
off(event, [fn], [context], [once])
Focus
Focus

Description:

Remove the listeners of a given event.

Parameters:

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.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#off
Since: 3.0.0
Focus
Focus
on(event, fn, [context])
Focus
Focus

Description:

Add a listener for a given event.

Parameters:

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.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#on
Since: 3.0.0
Focus
Focus
once(event, fn, [context])
Focus
Focus

Description:

Add a one-time listener for a given event.

Parameters:

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.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#once
Since: 3.0.0
Focus
Focus
pause()
Focus
Focus

Description:

Pauses the sound. This only works if the sound is currently playing.

You can inspect the isPlaying and isPaused properties to check the state.

Returns:
Description:

Whether the sound was paused successfully.

Type:
  • boolean
Since: 3.0.0
Source: src/sound/BaseSound.js (Line 343)
Focus
Focus
play([markerName], [config])
Focus
Focus

Description:

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 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.

Returns:
Description:

Whether the sound started playing successfully.

Type:
  • boolean
Since: 3.0.0
Source: src/sound/BaseSound.js (Line 283)
Focus
Focus
removeAllListeners([event])
Focus
Focus

Description:

Remove all listeners, or those of the specified event.

Parameters:

name type arguments description
event string | symbol <optional>

The event name.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#removeAllListeners
Since: 3.0.0
Focus
Focus
removeListener(event, [fn], [context], [once])
Focus
Focus

Description:

Remove the listeners of a given event.

Parameters:

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.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#removeListener
Since: 3.0.0
Focus
Focus
removeMarker(markerName)
Focus
Focus

Description:

Removes a marker from the sound.

Parameters:

name type description
markerName string

The name of the marker to remove.

Returns:
Description:

Removed marker object or 'null' if there was no marker with provided name.

Since: 3.0.0
Source: src/sound/BaseSound.js (Line 259)
Focus
Focus
resetConfig()
Focus
Focus

Description:

Method used internally for resetting values of some of the config properties.

Since: 3.0.0
Source: src/sound/BaseSound.js (Line 428)
Focus
Focus
resume()
Focus
Focus

Description:

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.

Returns:
Description:

Whether the sound was resumed successfully.

Type:
  • boolean
Since: 3.0.0
Source: src/sound/BaseSound.js (Line 366)
Focus
Focus
shutdown()
Focus
Focus

Description:

Removes all listeners.

Inherited from: Phaser.Events.EventEmitter#shutdown
Since: 3.0.0
Focus
Focus
stop()
Focus
Focus

Description:

Stop playing this sound.

Returns:
Description:

Whether the sound was stopped successfully.

Type:
  • boolean
Since: 3.0.0
Source: src/sound/BaseSound.js (Line 389)
Focus
Focus
update(time, delta)
Focus
Focus

Description:

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 440)
Focus
Focus
updateMarker(marker)
Focus
Focus

Description:

Updates previously added marker.

Parameters:

name type description
marker Phaser.Types.Sound.SoundMarker

Marker object with updated values.

Returns:
Description:

Whether the marker was updated successfully.

Type:
  • boolean
Since: 3.0.0
Source: src/sound/BaseSound.js (Line 229)
Focus
Focus