π Sound
Class for playing in-game 2D and 3D sounds.
You can also load raw .ogg
files from disk! Please check SpecialPath.
π Examplesβ
local my_sound = Sound(
Vector(-510, 145, 63), -- Location (if a 3D sound)
"nanos-world::A_VR_Confirm", -- Asset Path
false, -- Is 2D Sound
true, -- Auto Destroy (if to destroy after finished playing)
SoundType.SFX,
1, -- Volume
1 -- Pitch
)
-- Spawning a ogg sound located in a Package
local ogg_sound = Sound(Vector(), "package://my-package/Client/awesome_beep.ogg", true)
π Constructorsβ
Default Constructor
No description provided
local my_sound = Sound(location, asset, is_2D_sound?, auto_destroy?, sound_type?, volume?, pitch?, inner_radius?, falloff_distance?, attenuation_function?, keep_playig_when_silent?, loop_mode?)
Type | Name | Default | Description |
---|---|---|---|
Vector | location | Required parameter | Only used if 3D sound |
Sound Reference | asset | Required parameter | The Sound Asset to load |
boolean | is_2D_sound | false | Whether to spawn it as 2D or 3D |
boolean | auto_destroy | true | Whether to destroy after finished playing |
SoundType | sound_type | SoundType.SFX | Used to apply user's volume settings |
float | volume | 1 | No description provided |
float | pitch | 1 | No description provided |
float | inner_radius | 400 | Only used if 3D sound |
float | falloff_distance | 3600 | Only used if 3D sound |
AttenuationFunction | attenuation_function | Linear | Only used if 3D sound |
boolean | keep_playig_when_silent | false | Only used if 3D sound - Use with caution, it may cause performance issues! |
SoundLoopMode | loop_mode | Default | Whether should force sound to loop |
auto_destroy
means the Entity will be immediately destroyed after spawned, losing references to the Sound spawned in-game. So if the Sound itself loops indefinitely, it will keep playing until the Player reconnects.
πΏ Static Functionsβ
Inherited Entity Static Functions
This class doesn't have own static functions.
π¦ Functionsβ
Inherited Entity Functions
Inherited Actor Functions
Returns | Name | Description | |
---|---|---|---|
FadeIn | Plays the sound with a fade effect | ||
FadeOut | Stops the sound with a fade effect | ||
float | GetDuration | Gets the duration of the Sound | |
float | GetFalloffDistance | No description provided | |
float | GetInnerRadius | No description provided | |
float | GetLowPassFilter | No description provided | |
string | GetPath | No description provided | |
float | GetPitch | No description provided | |
float | GetSoundType | No description provided | |
float | GetVolume | No description provided | |
boolean | Is2D | Gets if the sound is 2D | |
boolean | IsPlaying | Gets if the sound is playing | |
Play | Starts the sound | ||
SetFalloffDistance | If a 3D Sound, sets the distance which the sound is inaudible | ||
SetInnerRadius | If a 3D Sound, sets the distance within the volume is 100% | ||
SetLowPassFilter | Sets lowpass filter frequency. Sets 0 to disable it. | ||
SetPaused | Pauses the sound | ||
SetPitch | Sets the Sound's pitch | ||
SetVolume | Sets the Sound's volume | ||
Stop | Stops the sound | ||
StopDelayed | Stops the sound after the provided delay |

FadeIn
Plays the sound with a fade effect
my_sound:FadeIn(fade_in_duration, fade_volume_level?, start_time?)
Type | Parameter | Default | Description |
---|---|---|---|
float | fade_in_duration | Required parameter | No description provided |
float | fade_volume_level? | 1.0 | No description provided |
float | start_time? | 0.0 | No description provided |

FadeOut
Stops the sound with a fade effect
my_sound:FadeOut(fade_out_duration, fade_volume_level?, destroy_after_fadeout?)
Type | Parameter | Default | Description |
---|---|---|---|
float | fade_out_duration | Required parameter | No description provided |
float | fade_volume_level? | 0.0 | No description provided |
boolean | destroy_after_fadeout? | false | No description provided |

GetDuration
Gets the duration of the Sound
β Returns float.
local ret = my_sound:GetDuration()

GetFalloffDistance
β Returns float.
local ret = my_sound:GetFalloffDistance()
See also SetFalloffDistance.

GetInnerRadius
β Returns float.
local ret = my_sound:GetInnerRadius()
See also SetInnerRadius.

GetLowPassFilter
β Returns float.
local ret = my_sound:GetLowPassFilter()
See also SetLowPassFilter.

GetPath
β Returns string.
local ret = my_sound:GetPath()

GetPitch
β Returns float.
local ret = my_sound:GetPitch()
See also SetPitch.

GetSoundType
β Returns float.
local ret = my_sound:GetSoundType()

GetVolume
β Returns float.
local ret = my_sound:GetVolume()
See also SetVolume.

Is2D
Gets if the sound is 2D
β Returns boolean.
local ret = my_sound:Is2D()

IsPlaying
Gets if the sound is playing
β Returns boolean.
local ret = my_sound:IsPlaying()

Play
Starts the sound
my_sound:Play(start_time?)
Type | Parameter | Default | Description |
---|---|---|---|
float | start_time? | 0.0 | No description provided |

SetFalloffDistance
If a 3D Sound, sets the distance which the sound is inaudible
my_sound:SetFalloffDistance(falloff_distance)
Type | Parameter | Default | Description |
---|---|---|---|
float | falloff_distance | Required parameter | No description provided |
See also GetFalloffDistance.

SetInnerRadius
If a 3D Sound, sets the distance within the volume is 100%
my_sound:SetInnerRadius(inner_radius)
Type | Parameter | Default | Description |
---|---|---|---|
float | inner_radius | Required parameter | No description provided |
See also GetInnerRadius.

SetLowPassFilter
Sets lowpass filter frequency. Sets 0 to disable it.
my_sound:SetLowPassFilter(frequency)
Type | Parameter | Default | Description |
---|---|---|---|
float | frequency | Required parameter | No description provided |
See also GetLowPassFilter.

SetPaused
Pauses the sound
my_sound:SetPaused(pause?)
Type | Parameter | Default | Description |
---|---|---|---|
boolean | pause? | true | No description provided |

SetPitch
Sets the Sound's pitch
my_sound:SetPitch(new_pitch)
Type | Parameter | Default | Description |
---|---|---|---|
float | new_pitch | Required parameter | No description provided |
See also GetPitch.

SetVolume
Sets the Sound's volume
my_sound:SetVolume(new_volume)
Type | Parameter | Default | Description |
---|---|---|---|
float | new_volume | Required parameter | from 0.0 to 1.0 |
See also GetVolume.

Stop
Stops the sound
my_sound:Stop()

StopDelayed
Stops the sound after the provided delay
my_sound:StopDelayed(delay)
Type | Parameter | Default | Description |
---|---|---|---|
float | delay | Required parameter | No description provided |
π Eventsβ
Inherited Entity Events
Inherited Actor Events
This class doesn't have own events.
π Sound Attenuationβ
This property defines the function that determines the rate of attenuation over distance. There are a number of different functions to choose from:
π Linearβ
This is the default function. When using this function the volume will attenuate linearly and so the changes in volume are constant as the listener moves towards and away from the source. This function is good for crossfading between large background-type sounds that don't need tightly focussed 3D spatial falloff settings.
π Logarithmicβ
When using this function the volume attenuates such that the changes in volume are greater at close distances, and lesser at far distances. This function is good for spot sounds that need good 3D positioning, while still being audible at reasonable distances.
π Inverseβ
When using this function, the changes in volume are similar to that of the logarithmic curve, but are more exaggerated. This function is good for sounds that only need to be just audible at far distances, but that gets significantly louder as the listener gets quite close to the source.
π Log Reverseβ
When using this function, the changes in volume are lesser at close distances, with more dramatic differences at far distances. This function is good for sounds that need to be loud across larger distances.
π Natural Soundβ
This function attempts to model a more 'naturalistic' falloff behavior to produce behaviors that closer match reality. This function is a kind of 'middle ground' between the Logarithmic and Inverse functions.