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.
- Default Value:
- null
- Source:
Properties:
Name Type Description contextAudioContext -
currentMarker
-
Description.
- Source:
Properties:
Name Type Description currentMarkerstring -
currentTime
-
Description.
- Default Value:
- 0
- Source:
Properties:
Name Type Description currentTimenumber -
duration
-
Description.
- Default Value:
- 0
- Source:
Properties:
Name Type Description durationnumber -
game
-
A reference to the currently running Game.
- Source:
Properties:
Name Type Description gamePhaser.Game -
<readonly> isDecoded
-
- Source:
Properties:
Name Type Description isDecodedboolean Returns true if the sound file has decoded.
-
<readonly> isDecoding
-
- Source:
Properties:
Name Type Description isDecodingboolean Returns true if the sound file is still decoding.
-
isPlaying
-
Description.
- Default Value:
- false
- Source:
Properties:
Name Type Description isPlayingboolean -
key
-
Asset key for the sound.
- Source:
Properties:
Name Type Description keystring -
loop
-
Whether or not the sound will loop.
- Source:
Properties:
Name Type Description loopboolean -
markers
-
The sound markers, empty by default.
- Source:
Properties:
Name Type Description markersobject -
mute
-
- Source:
Properties:
Name Type Description muteboolean Gets or sets the muted state of this sound.
-
name
-
Name of the sound.
- Default Value:
- key
- Source:
Properties:
Name Type Description namestring -
onDecoded
-
Description.
- Source:
Properties:
Name Type Description onDecodedPhaser.Signal -
onLoop
-
Description.
- Source:
Properties:
Name Type Description onLoopPhaser.Signal -
onMarkerComplete
-
Description.
- Source:
Properties:
Name Type Description onMarkerCompletePhaser.Signal -
onMute
-
Description.
- Source:
Properties:
Name Type Description onMutePhaser.Signal -
onPause
-
Description.
- Source:
Properties:
Name Type Description onPausePhaser.Signal -
onPlay
-
Description.
- Source:
Properties:
Name Type Description onPlayPhaser.Signal -
onResume
-
Description.
- Source:
Properties:
Name Type Description onResumePhaser.Signal -
onStop
-
Description.
- Source:
Properties:
Name Type Description onStopPhaser.Signal -
override
-
Description.
- Default Value:
- false
- Source:
Properties:
Name Type Description overrideboolean -
paused
-
Description.
- Default Value:
- false
- Source:
Properties:
Name Type Description pausedboolean -
pendingPlayback
-
Description.
- Default Value:
- false
- Source:
Properties:
Name Type Description pendingPlaybackboolean -
startTime
-
Description.
- Default Value:
- 0
- Source:
Properties:
Name Type Description startTimenumber -
stopTime
-
Description.
- Default Value:
- 0
- Source:
Properties:
Name Type Description autoplaynumber -
totalDuration
-
The total duration of the sound, in milliseconds
- Default Value:
- 0
- Source:
Properties:
Name Type Description totalDurationnumber -
usingAudioTag
-
Description.
- Source:
Properties:
Name Type Description usingAudioTagDescription -
usingWebAudio
-
Description.
- Source:
Properties:
Name Type Description usingWebAudioboolean -
<readonly> volume
-
- Source:
Properties:
Name Type Description volumenumber Gets or sets the volume of this sound, a value between 0 and 1.
Methods
-
addMarker(name, start, stop, volume, loop)
-
Description.
Parameters:
Name Type Description namestring Description.
startDescription Description.
stopDescription Description.
volumeDescription Description.
loopDescription 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 namestring A unique name for this marker, i.e. 'explosion', 'gunshot', etc.
startnumber The start point of this marker in the audio file, given in seconds. 2.5 = 2500ms, 0.5 = 500ms, etc.
durationnumber The duration of the marker in seconds. 2.5 = 2500ms, 0.5 = 500ms, etc.
volumenumber <optional>
1 The volume the sound will play back at, between 0 (silent) and 1 (full volume).
loopboolean <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 markerstring <optional>
'' If you want to play a marker then give the key here, otherwise leave blank to play the full sound.
positionnumber <optional>
0 The starting position to play the sound from - this is ignored if you provide a marker.
volumenumber <optional>
1 Volume of the sound you want to play.
loopboolean <optional>
false Loop when it finished playing?
forceRestartboolean <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 namestring 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 markerstring <optional>
'' If you want to play a marker then give the key here, otherwise leave blank to play the full sound.
positionnumber <optional>
0 The starting position to play the sound from - this is ignored if you provide a marker.
volumenumber <optional>
1 Volume of the sound you want to play.
loopboolean <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 keystring Description.
- Source:
-
stop()
-
Stop playing this sound.
- Source:
-
<protected> update()
-
Called automatically by Phaser.SoundManager.
- Source: