Class: Ruby2D::Music

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby2d/music.rb,
ext/ruby2d/ruby2d-opal.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject

Returns the value of attribute data.



6
7
8
# File 'lib/ruby2d/music.rb', line 6

def data
  @data
end

#loopObject

Returns the value of attribute loop.



6
7
8
# File 'lib/ruby2d/music.rb', line 6

def loop
  @loop
end

#pathObject (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_pauseObject



245
246
247
# File 'ext/ruby2d/ruby2d-opal.rb', line 245

def ext_pause
  `S2D.PauseMusic();`
end

#ext_playObject



241
242
243
# File 'ext/ruby2d/ruby2d-opal.rb', line 241

def ext_play
  `S2D.PlayMusic(#{self}.data, #{self}.loop);`
end

#ext_resumeObject



249
250
251
# File 'ext/ruby2d/ruby2d-opal.rb', line 249

def ext_resume
  `S2D.ResumeMusic();`
end

#ext_stopObject



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

#pauseObject



26
27
28
# File 'lib/ruby2d/music.rb', line 26

def pause
  ext_pause
end

#playObject



22
23
24
# File 'lib/ruby2d/music.rb', line 22

def play
  ext_play
end

#resumeObject



30
31
32
# File 'lib/ruby2d/music.rb', line 30

def resume
  ext_resume
end

#stopObject



34
35
36
# File 'lib/ruby2d/music.rb', line 34

def stop
  ext_stop
end