Class: Core::Sample

Inherits:
Object show all
Defined in:
lib/sample.rb

Overview

cache system borks inheritance, so we need to wrap a Gosu::Sample instance

Constant Summary collapse

@@cache =
{}

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#fileObject (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

#sampleObject



21
22
23
# File 'lib/sample.rb', line 21

def sample
  return @sample
end