Constructor
new Sound(zzfxSound, rangeopt, taperopt)
Create a sound object and cache the zzfx samples for later use
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
zzfxSound | Array | Array of zzfx parameters, ex. [.5,.5] | ||
range | Number | <optional> | soundDefaultRange | World space max range of sound, will not play if camera is farther away |
taper | Number | <optional> | soundDefaultTaper | At what percentage of range should it start tapering |
- Source
// create a sound
const sound_example = new Sound([.5,.5]);
// play the sound
sound_example.play();
Members
randomness
PropertiesType | Description |
---|---|
Number | How much to randomize frequency each time sound plays |
- Source
range
PropertiesType | Description |
---|---|
Number | World space max range of sound, will not play if camera is farther away |
- Source
taper
PropertiesType | Description |
---|---|
Number | At what percentage of range should it start tapering off |
- Source
Methods
getDuration() → {Number}
Get how long this sound is in seconds
- Source
- How long the sound is in seconds (undefined if loading)
- Type:
- Number
getSource() → {AudioBufferSourceNode}
Get source of most recent instance of this sound that was played
- Source
- Type:
- AudioBufferSourceNode
isLoading() → {Boolean}
Check if sound is loading, for sounds fetched from a url
- Source
- True if sound is loading and not ready to play
- Type:
- Boolean
play(posopt, volumeopt, pitchopt, randomnessScaleopt, loopopt) → {AudioBufferSourceNode}
Play the sound
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pos | Vector2 | <optional> | World space position to play the sound, sound is not attenuated if null | |
volume | Number | <optional> | 1 | How much to scale volume by (in addition to range fade) |
pitch | Number | <optional> | 1 | How much to scale pitch by (also adjusted by this.randomness) |
randomnessScale | Number | <optional> | 1 | How much to scale randomness |
loop | Boolean | <optional> | false | Should the sound loop |
- Source
- The audio source node
- Type:
- AudioBufferSourceNode
playNote(semitoneOffset, posopt, volumeopt) → {AudioBufferSourceNode}
Play the sound as a note with a semitone offset
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
semitoneOffset | Number | How many semitones to offset pitch | ||
pos | Vector2 | <optional> | World space position to play the sound, sound is not attenuated if null | |
volume | Number | <optional> | 1 | How much to scale volume by (in addition to range fade) |
- Source
- The audio source node
- Type:
- AudioBufferSourceNode
setVolume(volumeopt)
Set the sound volume of the most recently played instance of this sound
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
volume | Number | <optional> | 1 | How much to scale volume by |
- Source
stop()
Stop the last instance of this sound that was played
- Source