From d679edfa7f194710985fe35ff63be318038a8497 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Thu, 27 Feb 2020 22:49:46 +0100 Subject: [PATCH] Add a practical example for `@GDScript.linear2db()` One of its most common applications in games is for volume sliders. See https://www.dr-lex.be/info-stuff/volumecontrols.html for more information. (cherry picked from commit a6fd6b78dd267d21ea30cc644d8aad10bc0f66ce) --- modules/gdscript/doc_classes/@GDScript.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/gdscript/doc_classes/@GDScript.xml b/modules/gdscript/doc_classes/@GDScript.xml index 759aba9453d..304c72f086c 100644 --- a/modules/gdscript/doc_classes/@GDScript.xml +++ b/modules/gdscript/doc_classes/@GDScript.xml @@ -609,7 +609,13 @@ - Converts from linear energy to decibels (audio). + Converts from linear energy to decibels (audio). This can be used to implement volume sliders that behave as expected (since volume isn't linear). Example: + [codeblock] + # "Slider" refers to a node that inherits Range such as HSlider or VSlider. + # Its range must be configured to go from 0 to 1. + # Change the bus name if you'd like to change the volume of a specific bus only. + AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), linear2db($Slider.value)) + [/codeblock]