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
Fade out music over provided milliseconds.
-
#initialize(path) ⇒ 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.
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.
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 |
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
Fade out music over provided milliseconds
43 44 45 |
# File 'lib/ruby2d/music.rb', line 43 def fadeout(ms) ext_fadeout(ms) end |
#pause ⇒ Object
Pause the music
28 29 30 |
# File 'lib/ruby2d/music.rb', line 28 def pause ext_pause end |
#play ⇒ Object
Play the music
23 24 25 |
# File 'lib/ruby2d/music.rb', line 23 def play ext_play end |
#resume ⇒ Object
Resume paused music
33 34 35 |
# File 'lib/ruby2d/music.rb', line 33 def resume ext_resume end |
#stop ⇒ Object
Stop playing the music, start at beginning
38 39 40 |
# File 'lib/ruby2d/music.rb', line 38 def stop ext_stop end |