Class: Ruby2D::Audio
- Inherits:
-
Object
- Object
- Ruby2D::Audio
- Defined in:
- lib/ruby2d/audio.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
-
.volume ⇒ Object
Get the mixer volume, 0.0 to 1.0.
-
.volume=(volume) ⇒ Object
Set the mixer volume, 0.0 to 1.0.
Instance Method Summary collapse
-
#initialize(path, loop: false) ⇒ Audio
constructor
Create an audio object from a file.
-
#length ⇒ Object
Returns the length in seconds.
-
#loop=(value) ⇒ Object
Set looping.
-
#looping? ⇒ Boolean
Whether the audio loops on play.
-
#pause ⇒ Object
Pause the music.
-
#play ⇒ Object
Play the sound.
-
#resume ⇒ Object
Resume paused music.
-
#stop(ms_fade = 0) ⇒ Object
Stop the sound.
-
#volume ⇒ Object
Get the volume of the sound, 0.0 to 1.0.
-
#volume=(volume) ⇒ Object
Set the volume of the sound, 0.0 to 1.0.
Constructor Details
#initialize(path, loop: false) ⇒ Audio
Create an audio object from a file
6 7 8 9 10 11 12 |
# File 'lib/ruby2d/audio.rb', line 6 def initialize(path, loop: false) @path = path.to_s raise Error, "Cannot find audio file `#{@path}`" unless File.exist? @path @loop = loop ? true : false @ext_audio = Ext.audio_load(@path) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/ruby2d/audio.rb', line 3 def path @path end |
Class Method Details
.volume ⇒ Object
Get the mixer volume, 0.0 to 1.0
62 63 64 |
# File 'lib/ruby2d/audio.rb', line 62 def volume Ext.audio_get_mixer_volume end |
.volume=(volume) ⇒ Object
Set the mixer volume, 0.0 to 1.0
67 68 69 |
# File 'lib/ruby2d/audio.rb', line 67 def volume=(volume) Ext.audio_set_mixer_volume(volume.clamp(0.0, 1.0)) end |
Instance Method Details
#length ⇒ Object
Returns the length in seconds
46 47 48 |
# File 'lib/ruby2d/audio.rb', line 46 def length Ext.audio_length(@ext_audio) end |
#loop=(value) ⇒ Object
Set looping
40 41 42 43 |
# File 'lib/ruby2d/audio.rb', line 40 def loop=(value) @loop = value ? true : false Ext.audio_set_loop(@ext_audio, @loop) end |
#looping? ⇒ Boolean
Whether the audio loops on play
35 36 37 |
# File 'lib/ruby2d/audio.rb', line 35 def looping? @loop end |
#pause ⇒ Object
Pause the music
20 21 22 |
# File 'lib/ruby2d/audio.rb', line 20 def pause Ext.audio_pause(@ext_audio) end |
#play ⇒ Object
Play the sound
15 16 17 |
# File 'lib/ruby2d/audio.rb', line 15 def play Ext.audio_play(@ext_audio, @loop) end |
#resume ⇒ Object
Resume paused music
25 26 27 |
# File 'lib/ruby2d/audio.rb', line 25 def resume Ext.audio_resume(@ext_audio) end |
#stop(ms_fade = 0) ⇒ Object
Stop the sound
30 31 32 |
# File 'lib/ruby2d/audio.rb', line 30 def stop(ms_fade = 0) Ext.audio_stop(@ext_audio, ms_fade) end |
#volume ⇒ Object
Get the volume of the sound, 0.0 to 1.0
51 52 53 |
# File 'lib/ruby2d/audio.rb', line 51 def volume Ext.audio_get_volume(@ext_audio) end |
#volume=(volume) ⇒ Object
Set the volume of the sound, 0.0 to 1.0
56 57 58 |
# File 'lib/ruby2d/audio.rb', line 56 def volume=(volume) Ext.audio_set_volume(@ext_audio, volume.clamp(0.0, 1.0)) end |