Sound

Sound

Sound Object - Stores a zzfx sound for later use and can be played positionally

Constructor

# new Sound(zzfxSound, rangeopt, taperopt)

Create a sound object and cache the zzfx samples for later use
Parameters:
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 off
Example
// create a sound
const sound_example = new Sound([.5,.5]);

// play the sound
sound_example.play();

Members

# range

Properties
Type Description
Number World space max range of sound, will not play if camera is farther away

# taper

Properties
Type Description
Number At what percentage of range should it start tapering off

Methods

# play(posopt, volumeopt, pitchopt, randomnessScaleopt) → {AudioBufferSourceNode}

Play the sound
Parameters:
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
Returns:
- The audio, can be used to stop sound later
Type
AudioBufferSourceNode

# playNote(semitoneOffset, posopt, volumeopt) → {AudioBufferSourceNode}

Play the sound as a note with a semitone offset
Parameters:
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)
Returns:
- The audio, can be used to stop sound later
Type
AudioBufferSourceNode