Class: Core::Sample
Overview
cache system borks inheritance, so we need to wrap a Gosu::Sample instance
Constant Summary collapse
- @@cache =
{}
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
-
#initialize(file) ⇒ Sample
constructor
A new instance of Sample.
- #play(vol = 1.0, speed = 1, looping = false) ⇒ Object
- #sample ⇒ Object
Constructor Details
#initialize(file) ⇒ Sample
Returns a new instance of Sample.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/sample.rb', line 7 def initialize(file) @file = file if @@cache[file] @sample = @@cache[file] return end begin @sample = Gosu::Sample.new("#{Core::LIBRARY_PATH}/sounds/#{file}.wav") @@cache.store(file, @sample) rescue RuntimeError puts("ERROR: Failed to open sound #{file}") return end end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
5 6 7 |
# File 'lib/sample.rb', line 5 def file @file end |
Instance Method Details
#play(vol = 1.0, speed = 1, looping = false) ⇒ Object
24 25 26 27 |
# File 'lib/sample.rb', line 24 def play(vol=1.0, speed=1, looping=false) vol *= Core.config[:volume] @sample.play(vol, speed, looping) end |
#sample ⇒ Object
21 22 23 |
# File 'lib/sample.rb', line 21 def sample return @sample end |