🎧AudioManager
Several helper functions for managing the volume levels of various buses in your game.
Functional Example:
Let's demonstrate how these functions can assist us in audio management within our game:
extends Control
@onready var music: HSlider = $Parameters/VBoxContainer/HorizontalContainer/Sliders/Music
@onready var sfx: HSlider = $Parameters/VBoxContainer/HorizontalContainer/Sliders/SFX
func _ready():
music.value = GodotEssentialsAudio.get_actual_volume_db_from_bus("Music")
sfx.value = GodotEssentialsAudio.get_actual_volume_db_from_bus("SFX")
func _on_music_value_changed(value):
GodotEssentialsAudio.change_volume("Music", value)
func _on_sfx_value_changed(value):
change_volume("SFX", value)
The script above is a modification of the following script, incorporating our GodotEssentialAudio class. https://github.com/godotessentials/Veneno/blob/main/scenes/ui/options.gd
API reference
Accessible normal variables
Here is an array list of the available buses set up in your project, for example:
GodotEssentialsAudio.available_buses # returns ["Master", "Music", "SFX"]
change_volume(bus, value: float) -> void
Change the volume of selected bus_index if it exists. Can receive the bus parameter as name or index.
GodotEssentialsAudio.change_volume(1, 0.5)
GodotEssentialsAudio.change_volume("Music", 0.5)
get_actual_volume_db_from_bus_name(name: String) -> float
Retrieve the current volume value for the selected bus by its name. If the bus_name
does not exist in your project, it will raise an error and return a value of 0.0.
GodotEssentialsAudio.get_actual_volume_db_from_bus("Music")
get_actual_volume_db_from_bus_index(index: int) -> float
Retrieve the current volume value for the selected bus by its index.
GodotEssentialsAudio.get_actual_volume_db_from_index(1)
GodotEssentialsAudio.get_actual_volume_db_from_index(AudioServer.get_bus_index("Music"))
Last updated