Class: Ruby2D::Music
- Inherits:
-
Object
- Object
- Ruby2D::Music
- Defined in:
- lib/ruby2d/music.rb,
ext/ruby2d/ruby2d-opal.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.
Instance Method Summary collapse
- #ext_init(path) ⇒ Object
- #ext_music_fadeout(ms) ⇒ Object
- #ext_pause ⇒ Object
- #ext_play ⇒ Object
- #ext_resume ⇒ Object
- #ext_stop ⇒ Object
- #fadeout(ms) ⇒ Object
-
#initialize(path) ⇒ Music
constructor
A new instance of Music.
- #pause ⇒ Object
- #play ⇒ Object
- #resume ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(path) ⇒ Music
Returns a new instance of Music.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ruby2d/music.rb', line 9 def initialize(path) unless RUBY_ENGINE == 'opal' unless File.exists? path raise Error, "Cannot find audio file `#{path}`" end end @path = path @loop = false ext_init(path) end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/ruby2d/music.rb', line 6 def data @data end |
#loop ⇒ Object
Returns the value of attribute loop.
6 7 8 |
# File 'lib/ruby2d/music.rb', line 6 def loop @loop end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/ruby2d/music.rb', line 7 def path @path end |
Instance Method Details
#ext_init(path) ⇒ Object
237 238 239 |
# File 'ext/ruby2d/ruby2d-opal.rb', line 237 def ext_init(path) `#{self}.data = S2D.CreateMusic(path);` end |
#ext_music_fadeout(ms) ⇒ Object
257 258 259 |
# File 'ext/ruby2d/ruby2d-opal.rb', line 257 def ext_music_fadeout(ms) `S2D.FadeOutMusic(ms);` end |
#ext_pause ⇒ Object
245 246 247 |
# File 'ext/ruby2d/ruby2d-opal.rb', line 245 def ext_pause `S2D.PauseMusic();` end |
#ext_play ⇒ Object
241 242 243 |
# File 'ext/ruby2d/ruby2d-opal.rb', line 241 def ext_play `S2D.PlayMusic(#{self}.data, #{self}.loop);` end |
#ext_resume ⇒ Object
249 250 251 |
# File 'ext/ruby2d/ruby2d-opal.rb', line 249 def ext_resume `S2D.ResumeMusic();` end |
#ext_stop ⇒ Object
253 254 255 |
# File 'ext/ruby2d/ruby2d-opal.rb', line 253 def ext_stop `S2D.StopMusic();` end |
#fadeout(ms) ⇒ Object
38 39 40 |
# File 'lib/ruby2d/music.rb', line 38 def fadeout(ms) ext_fadeout(ms) end |
#pause ⇒ Object
26 27 28 |
# File 'lib/ruby2d/music.rb', line 26 def pause ext_pause end |
#play ⇒ Object
22 23 24 |
# File 'lib/ruby2d/music.rb', line 22 def play ext_play end |
#resume ⇒ Object
30 31 32 |
# File 'lib/ruby2d/music.rb', line 30 def resume ext_resume end |
#stop ⇒ Object
34 35 36 |
# File 'lib/ruby2d/music.rb', line 34 def stop ext_stop end |