Class: Core::Song
Overview
cache system borks inheritance, so we need to wrap a Gosu::Song instance
Constant Summary collapse
- @@cache =
{}
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
-
#initialize(file) ⇒ Song
constructor
A new instance of Song.
- #pause ⇒ Object
- #play(loop = true) ⇒ Object
- #song ⇒ Object
- #stop ⇒ Object
- #volume ⇒ Object
- #volume=(vol) ⇒ Object
Constructor Details
#initialize(file) ⇒ Song
Returns a new instance of Song.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/song.rb', line 7 def initialize(file) @file = file if @@cache[file] @song = @@cache[file] return end begin @song = Gosu::Song.new(Core.window, "#{Core::LIBRARY_PATH}/music/#{file}.mp3") @@cache.store(file, @song) rescue RuntimeError puts("ERROR: Failed to open music #{file}") return end end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
5 6 7 |
# File 'lib/song.rb', line 5 def file @file end |
Instance Method Details
#pause ⇒ Object
27 28 29 |
# File 'lib/song.rb', line 27 def pause @song.pause end |
#play(loop = true) ⇒ Object
36 37 38 39 |
# File 'lib/song.rb', line 36 def play(loop=true) @song.volume = Core.config[:volume]+1.0 # FIXME no effect? @song.play(loop) end |
#song ⇒ Object
21 22 23 |
# File 'lib/song.rb', line 21 def song return @song end |
#stop ⇒ Object
24 25 26 |
# File 'lib/song.rb', line 24 def stop @song.stop end |
#volume ⇒ Object
30 31 32 |
# File 'lib/song.rb', line 30 def volume return @song.volume end |
#volume=(vol) ⇒ Object
33 34 35 |
# File 'lib/song.rb', line 33 def volume=(vol) @song.volume = vol end |