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