Class: Ruby2D::Music
- Inherits:
-
Object
- Object
- Ruby2D::Music
- Defined in:
- lib/ruby2d/music.rb
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
-
.volume ⇒ Object
Returns the volume, in percentage.
-
.volume=(v) ⇒ Object
Set music volume, 0 to 100%.
Instance Method Summary collapse
-
#fadeout(ms) ⇒ Object
Fade out music over provided milliseconds.
-
#initialize(path, opts = {}) ⇒ Music
constructor
A new instance of Music.
-
#pause ⇒ Object
Pause the music.
-
#play ⇒ Object
Play the music.
-
#resume ⇒ Object
Resume paused music.
-
#stop ⇒ Object
Stop playing the music, start at beginning.
-
#volume ⇒ Object
Alias instance methods to class methods.
- #volume=(v) ⇒ Object
Constructor Details
#initialize(path, opts = {}) ⇒ Music
Returns a new instance of Music.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ruby2d/music.rb', line 9 def initialize(path, opts = {}) unless File.exist? path raise Error, "Cannot find audio file `#{path}`" end @path = path @loop = opts[:loop] || false unless ext_init(@path) raise Error, "Music `#{@path}` cannot be created" end end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
7 8 9 |
# File 'lib/ruby2d/music.rb', line 7 def data @data end |
#loop ⇒ Object
Returns the value of attribute loop.
7 8 9 |
# File 'lib/ruby2d/music.rb', line 7 def loop @loop end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/ruby2d/music.rb', line 6 def path @path end |
Class Method Details
.volume ⇒ Object
Returns the volume, in percentage
41 42 43 |
# File 'lib/ruby2d/music.rb', line 41 def self.volume self.ext_get_volume end |
.volume=(v) ⇒ Object
Set music volume, 0 to 100%
46 47 48 49 50 |
# File 'lib/ruby2d/music.rb', line 46 def self.volume=(v) # If a negative value, volume will be 0 if v < 0 then v = 0 end self.ext_set_volume(v) end |
Instance Method Details
#fadeout(ms) ⇒ Object
Fade out music over provided milliseconds
57 58 59 |
# File 'lib/ruby2d/music.rb', line 57 def fadeout(ms) ext_fadeout(ms) end |
#pause ⇒ Object
Pause the music
26 27 28 |
# File 'lib/ruby2d/music.rb', line 26 def pause ext_pause end |
#play ⇒ Object
Play the music
21 22 23 |
# File 'lib/ruby2d/music.rb', line 21 def play ext_play end |
#resume ⇒ Object
Resume paused music
31 32 33 |
# File 'lib/ruby2d/music.rb', line 31 def resume ext_resume end |
#stop ⇒ Object
Stop playing the music, start at beginning
36 37 38 |
# File 'lib/ruby2d/music.rb', line 36 def stop ext_stop end |