Class: Ruby2D::Sound
- Inherits:
-
Object
- Object
- Ruby2D::Sound
- Defined in:
- lib/ruby2d/sound.rb
Overview
Sounds are intended to be short samples, played without interruption, like an effect.
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#loop ⇒ Object
Returns the value of attribute loop.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
-
.mix_volume ⇒ Object
Get the volume of the sound mixer.
-
.mix_volume=(volume) ⇒ Object
Set the volume of the sound mixer.
Instance Method Summary collapse
-
#initialize(path, loop: false) ⇒ Sound
constructor
Load a sound from a file.
-
#length ⇒ Object
Returns the length in seconds.
-
#play ⇒ Object
Play the sound.
-
#stop ⇒ Object
Stop the sound.
-
#volume ⇒ Object
Get the volume of the sound.
-
#volume=(volume) ⇒ Object
Set the volume of the sound.
Constructor Details
#initialize(path, loop: false) ⇒ Sound
Load a sound from a file
16 17 18 19 20 21 22 |
# File 'lib/ruby2d/sound.rb', line 16 def initialize(path, loop: false) raise Error, "Cannot find audio file `#{path}`" unless File.exist? path @path = path @loop = loop raise Error, "Sound `#{@path}` cannot be created" unless ext_init(@path) end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
9 10 11 |
# File 'lib/ruby2d/sound.rb', line 9 def data @data end |
#loop ⇒ Object
Returns the value of attribute loop.
9 10 11 |
# File 'lib/ruby2d/sound.rb', line 9 def loop @loop end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/ruby2d/sound.rb', line 8 def path @path end |
Class Method Details
.mix_volume ⇒ Object
Get the volume of the sound mixer
51 52 53 |
# File 'lib/ruby2d/sound.rb', line 51 def self.mix_volume ext_get_mix_volume end |
.mix_volume=(volume) ⇒ Object
Set the volume of the sound mixer
56 57 58 59 |
# File 'lib/ruby2d/sound.rb', line 56 def self.mix_volume=(volume) # Clamp value to between 0-100 ext_set_mix_volume(volume.clamp(0, 100)) end |
Instance Method Details
#length ⇒ Object
Returns the length in seconds
35 36 37 |
# File 'lib/ruby2d/sound.rb', line 35 def length ext_length end |
#play ⇒ Object
Play the sound
25 26 27 |
# File 'lib/ruby2d/sound.rb', line 25 def play ext_play end |
#stop ⇒ Object
Stop the sound
30 31 32 |
# File 'lib/ruby2d/sound.rb', line 30 def stop ext_stop end |
#volume ⇒ Object
Get the volume of the sound
40 41 42 |
# File 'lib/ruby2d/sound.rb', line 40 def volume ext_get_volume end |
#volume=(volume) ⇒ Object
Set the volume of the sound
45 46 47 48 |
# File 'lib/ruby2d/sound.rb', line 45 def volume=(volume) # Clamp value to between 0-100 ext_set_volume(volume.clamp(0, 100)) end |