From 830d99fde4555263967dfee94b4095ee300c12e1 Mon Sep 17 00:00:00 2001 From: Heitor Carvalho Date: Wed, 24 Oct 2018 18:10:17 -0300 Subject: Implements volume control to Music (#123) --- lib/ruby2d/music.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib') diff --git a/lib/ruby2d/music.rb b/lib/ruby2d/music.rb index 41b8901..5974a8a 100644 --- a/lib/ruby2d/music.rb +++ b/lib/ruby2d/music.rb @@ -39,6 +39,22 @@ module Ruby2D ext_stop end + # Returns the previous volume setting, in percentage + def self.volume + self.ext_volume(-1) + end + + # Set music volume, 0 to 100% + def self.volume=(v) + # If a negative value, volume will be 0 + if v < 0 then v = 0 end + self.ext_volume(v) + end + + # Alias instance methods to class methods + def volume; Music.volume end + def volume=(v); Music.volume=(v) end + # Fade out music over provided milliseconds def fadeout(ms) ext_fadeout(ms) -- cgit v1.2.3