Class: Sound

Phaser. Sound

The Sound class

new Sound(game, key, volume, loop)

The Sound class constructor.

Parameters:
Name Type Argument Default Description
game Phaser.Game

Reference to the current game instance.

key string

Asset key for the sound.

volume number <optional>
1

Default value for the volume, between 0 and 1.

loop boolean <optional>
false

Whether or not the sound will loop.

Source:

Members

context

Reference to AudioContext instance.

Properties:
Name Type Description
context AudioContext
Default Value:
  • null
Source:

currentMarker

Description.

Properties:
Name Type Description
currentMarker string
Source:

currentTime

Description.

Properties:
Name Type Description
currentTime number
Default Value:
  • 0
Source:

duration

Description.

Properties:
Name Type Description
duration number
Default Value:
  • 0
Source:

game

A reference to the currently running Game.

Properties:
Name Type Description
game Phaser.Game
Source:

<readonly> isDecoded

Properties:
Name Type Description
isDecoded boolean

Returns true if the sound file has decoded.

Source:

<readonly> isDecoding

Properties:
Name Type Description
isDecoding boolean

Returns true if the sound file is still decoding.

Source:

isPlaying

Description.

Properties:
Name Type Description
isPlaying boolean
Default Value:
  • false
Source:

key

Asset key for the sound.

Properties:
Name Type Description
key string
Source:

loop

Whether or not the sound will loop.

Properties:
Name Type Description
loop boolean
Source:

markers

The sound markers, empty by default.

Properties:
Name Type Description
markers object
Source:

mute

Properties:
Name Type Description
mute boolean

Gets or sets the muted state of this sound.

Source:

name

Name of the sound.

Properties:
Name Type Description
name string
Default Value:
  • key
Source:

onDecoded

Description.

Properties:
Name Type Description
onDecoded Phaser.Signal
Source:

onLoop

Description.

Properties:
Name Type Description
onLoop Phaser.Signal
Source:

onMarkerComplete

Description.

Properties:
Name Type Description
onMarkerComplete Phaser.Signal
Source:

onMute

Description.

Properties:
Name Type Description
onMute Phaser.Signal
Source:

onPause

Description.

Properties:
Name Type Description
onPause Phaser.Signal
Source:

onPlay

Description.

Properties:
Name Type Description
onPlay Phaser.Signal
Source:

onResume

Description.

Properties:
Name Type Description
onResume Phaser.Signal
Source:

onStop

Description.

Properties:
Name Type Description
onStop Phaser.Signal
Source:

override

Description.

Properties:
Name Type Description
override boolean
Default Value:
  • false
Source:

paused

Description.

Properties:
Name Type Description
paused boolean
Default Value:
  • false
Source:

pendingPlayback

Description.

Properties:
Name Type Description
pendingPlayback boolean
Default Value:
  • false
Source:

startTime

Description.

Properties:
Name Type Description
startTime number
Default Value:
  • 0
Source:

stopTime

Description.

Properties:
Name Type Description
autoplay number
Default Value:
  • 0
Source:

totalDuration

The total duration of the sound, in milliseconds

Properties:
Name Type Description
totalDuration number
Default Value:
  • 0
Source:

usingAudioTag

Description.

Properties:
Name Type Description
usingAudioTag Description
Source:

usingWebAudio

Description.

Properties:
Name Type Description
usingWebAudio boolean
Source:

<readonly> volume

Properties:
Name Type Description
volume number

Gets or sets the volume of this sound, a value between 0 and 1.

Source:

Methods

addMarker(name, start, stop, volume, loop)

Description.

Parameters:
Name Type Description
name string

Description.

start Description

Description.

stop Description

Description.

volume Description

Description.

loop Description

Description. addMarker: function (name, start, stop, volume, loop) {

    volume = volume || 1;
    if (typeof loop == 'undefined') { loop = false; }

    this.markers[name] = {
        name: name,
        start: start,
        stop: stop,
        volume: volume,
        duration: stop - start,
        loop: loop
    };

},
Source:

addMarker(name, start, duration, volume, loop)

Adds a marker into the current Sound. A marker is represented by a unique key and a start time and duration. 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 Argument Default Description
name string

A unique name for this marker, i.e. 'explosion', 'gunshot', etc.

start number

The start point of this marker in the audio file, given in seconds. 2.5 = 2500ms, 0.5 = 500ms, etc.

duration number

The duration of the marker in seconds. 2.5 = 2500ms, 0.5 = 500ms, etc.

volume number <optional>
1

The volume the sound will play back at, between 0 (silent) and 1 (full volume).

loop boolean <optional>
false

Sets if the sound will loop or not.

Source:

pause()

Pauses the sound

Source:

play(marker, position, volume, loop, forceRestart) → {Sound}

Play this sound, or a marked section of it.

Parameters:
Name Type Argument Default Description
marker string <optional>
''

If you want to play a marker then give the key here, otherwise leave blank to play the full sound.

position number <optional>
0

The starting position to play the sound from - this is ignored if you provide a marker.

volume number <optional>
1

Volume of the sound you want to play.

loop boolean <optional>
false

Loop when it finished playing?

forceRestart boolean <optional>
true

If the sound is already playing you can set forceRestart to restart it from the beginning.

Source:
Returns:

The playing sound object.

Type
Sound

removeMarker(name)

Removes a marker from the sound.

Parameters:
Name Type Description
name string

The key of the marker to remove.

Source:

restart(marker, position, volume, loop)

Restart the sound, or a marked section of it.

Parameters:
Name Type Argument Default Description
marker string <optional>
''

If you want to play a marker then give the key here, otherwise leave blank to play the full sound.

position number <optional>
0

The starting position to play the sound from - this is ignored if you provide a marker.

volume number <optional>
1

Volume of the sound you want to play.

loop boolean <optional>
false

Loop when it finished playing?

Source:

resume()

Resumes the sound

Source:

<protected> soundHasUnlocked(key)

Called automatically when this sound is unlocked.

Parameters:
Name Type Description
key string

Description.

Source:

stop()

Stop playing this sound.

Source:

<protected> update()

Called automatically by Phaser.SoundManager.

Source:
Phaser Copyright © 2012-2013 Photon Storm Ltd.
Documentation generated by JSDoc 3.2.0-dev on Wed Oct 23 2013 13:52:03 GMT+0100 (BST) using the DocStrap template.