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 |
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
loadedPercent
PropertiesType | Description |
---|---|
number | Percentage of this sound currently loaded |
- Source
randomness
PropertiesType | Description |
---|---|
number | How much to randomize frequency each time sound plays |
- Source
range
PropertiesType | Description |
---|---|
number | World space max range of sound |
- Source
sampleRate
PropertiesType | Description |
---|---|
number | Sample rate for this sound |
- Source
taper
PropertiesType | Description |
---|---|
number | At what percentage of range should it start tapering |
- 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
isLoaded() → {boolean}
Check if sound is loaded, for sounds fetched from a url
- Source
- True if sound is loaded and ready to play
- Type:
- boolean
play(posopt, volumeopt, pitchopt, randomnessScaleopt, loopopt, pausedopt) → {SoundInstance}
Play the sound Sounds may not play until a user interaction occurs
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pos | Vector2 | <optional> | World space position to play the sound if any | |
volume | number | <optional> | 1 | How much to scale volume by |
pitch | number | <optional> | 1 | How much to scale pitch by |
randomnessScale | number | <optional> | 1 | How much to scale pitch randomness |
loop | boolean | <optional> | false | Should the sound loop? |
paused | boolean | <optional> | false | Should the sound start paused |
- Source
- The audio source node
- Type:
- SoundInstance
playMusic(volumeopt, loopopt, pausedopt) → {SoundInstance}
Play a music track that loops by default
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
volume | number | <optional> | 1 | Volume to play the music at |
loop | boolean | <optional> | true | Should the music loop? |
paused | boolean | <optional> | false | Should the music start paused |
- Source
- The audio source node
- Type:
- SoundInstance
playNote(semitoneOffset, posopt, volumeopt) → {SoundInstance}
Play the sound as a musical note with a semitone offset This can be used to play music with chromatic scales
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
semitoneOffset | number | How many semitones to offset pitch | ||
pos | Vector2 | <optional> | World space position to play the sound if any | |
volume | number | <optional> | 1 | How much to scale volume by |
- Source
- The audio source node
- Type:
- SoundInstance