implemented sfx slider in options menu with a audio sample on slider change

pull/1/head
Meik Schürmann 2026-04-13 13:26:01 +02:00
parent 5cc134ff7b
commit 682c22ca77
2 changed files with 44 additions and 0 deletions

View File

@ -1,6 +1,9 @@
extends CanvasLayer
var sfx_preview = preload("res://assets/music & sfx/sfx/hit2.wav")
func _ready():
# Music Slider
$VBoxContainer/HBoxContainer/HSlider.min_value = 0.0
$VBoxContainer/HBoxContainer/HSlider.max_value = 1.0
$VBoxContainer/HBoxContainer/HSlider.step = 0.01
@ -8,6 +11,14 @@ func _ready():
var bus_idx = AudioServer.get_bus_index("Music")
$VBoxContainer/HBoxContainer/HSlider.value = db_to_linear(AudioServer.get_bus_volume_db(bus_idx))
# SFX Slider
$VBoxContainer/HBoxContainer3/HSlider.min_value = 0.0
$VBoxContainer/HBoxContainer3/HSlider.max_value = 1.0
$VBoxContainer/HBoxContainer3/HSlider.step = 0.01
# Aktuellen Bus-Wert als Startwert setzen
var sfx_idx = AudioServer.get_bus_index("SFX")
$VBoxContainer/HBoxContainer3/HSlider.value = db_to_linear(AudioServer.get_bus_volume_db(sfx_idx))
func _on_back_button_pressed() -> void:
get_tree().change_scene_to_file("res://scenes/mainmenu.tscn")
@ -20,3 +31,17 @@ func _on_check_box_toggled(toggled_on: bool) -> void:
func _on_h_slider_value_changed(value: float) -> void:
var bus_idx = AudioServer.get_bus_index("Music")
AudioServer.set_bus_volume_db(bus_idx, linear_to_db(value))
func _on_h2_slider_value_changed(value: float) -> void:
var bus_idx = AudioServer.get_bus_index("SFX")
AudioServer.set_bus_volume_db(bus_idx, linear_to_db(value))
# Vorschau-Sound abspielen
var preview = AudioStreamPlayer.new()
add_child(preview)
preview.stream = sfx_preview
preview.bus = "SFX"
preview.play()
await preview.finished
preview.queue_free()

View File

@ -51,6 +51,7 @@ horizontal_alignment = 1
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer" unique_id=1082653827]
custom_minimum_size = Vector2(300, 0)
layout_mode = 2
alignment = 1
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer" unique_id=388379542]
custom_minimum_size = Vector2(150, 0)
@ -63,9 +64,26 @@ text = "Music Volume"
custom_minimum_size = Vector2(300, 30)
layout_mode = 2
[node name="HBoxContainer3" type="HBoxContainer" parent="VBoxContainer" unique_id=644962322]
custom_minimum_size = Vector2(300, 0)
layout_mode = 2
alignment = 1
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer3" unique_id=1188599982]
custom_minimum_size = Vector2(150, 0)
layout_mode = 2
theme_override_fonts/font = ExtResource("3_1sggn")
theme_override_font_sizes/font_size = 32
text = "SFX Volume"
[node name="HSlider" type="HSlider" parent="VBoxContainer/HBoxContainer3" unique_id=957752147]
custom_minimum_size = Vector2(300, 30)
layout_mode = 2
[node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer" unique_id=532391329]
custom_minimum_size = Vector2(300, 0)
layout_mode = 2
alignment = 1
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer2" unique_id=1484176872]
custom_minimum_size = Vector2(150, 0)
@ -85,5 +103,6 @@ theme_override_font_sizes/font_size = 32
text = "Back"
[connection signal="value_changed" from="VBoxContainer/HBoxContainer/HSlider" to="." method="_on_h_slider_value_changed"]
[connection signal="value_changed" from="VBoxContainer/HBoxContainer3/HSlider" to="." method="_on_h2_slider_value_changed"]
[connection signal="toggled" from="VBoxContainer/HBoxContainer2/CheckBox" to="." method="_on_check_box_toggled"]
[connection signal="pressed" from="VBoxContainer/BackButton" to="." method="_on_back_button_pressed"]