Class: Gosu::Sample

Inherits:
Object
  • Object
show all
Includes:
Chingu::NamedResource
Defined in:
lib/chingu/assets.rb,
lib/chingu/gosu_ext/sample.rb

Constant Summary

DEFAULT_VOLUME =

Default volume of new samples.

1.0

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Chingu::NamedResource

included, #name, #name=

Constructor Details

#initialize(filename, options = {}) ⇒ Sample

Accepts :volume (0.0..1.0) option, defaulting to 1.0.



39
40
41
42
43
44
45
46
47
# File 'lib/chingu/gosu_ext/sample.rb', line 39

def initialize(filename, options = {})
  options = {
      volume: DEFAULT_VOLUME,
  }.merge! options

  @volume = options[:volume]

  old_initialize(filename)
end

Class Attribute Details

.volumeObject

Volume of all Samples.



7
8
9
# File 'lib/chingu/gosu_ext/sample.rb', line 7

def volume
  @volume
end

Instance Attribute Details

#volumeObject

Volume of this Sample. This is multiplied by the volume in #play.



33
34
35
# File 'lib/chingu/gosu_ext/sample.rb', line 33

def volume
  @volume
end

Class Method Details

.autoload(name) ⇒ Object



111
112
113
# File 'lib/chingu/assets.rb', line 111

def self.autoload(name)
  (path = find_file(name)) ? Gosu::Sample.new(path) : nil
end

.effective_volumeObject

Volume of Samples, affected by Sample.volume and Window#volume and muting.



11
12
13
# File 'lib/chingu/gosu_ext/sample.rb', line 11

def effective_volume
  @volume * $window.effective_volume
end

.init_soundObject



24
25
26
27
# File 'lib/chingu/gosu_ext/sample.rb', line 24

def init_sound
  @volume = DEFAULT_VOLUME
  nil
end

Instance Method Details

#effective_volumeObject

Volume the Sample will actually be played at, affected by Sample.volume and Window#volume.



59
60
61
# File 'lib/chingu/gosu_ext/sample.rb', line 59

def effective_volume
  @volume * self.class.effective_volume
end

#play(volume = 1, speed = 1, looping = false) ⇒ Object



66
67
68
69
# File 'lib/chingu/gosu_ext/sample.rb', line 66

def play(volume = 1, speed = 1, looping = false)
  volume *= effective_volume
  old_play(volume, speed, looping) if volume > 0.0
end

#play_pan(pan = 0, volume = 1, speed = 1, looping = false) ⇒ Object



74
75
76
77
# File 'lib/chingu/gosu_ext/sample.rb', line 74

def play_pan(pan = 0, volume = 1, speed = 1, looping = false)
  volume *= effective_volume
  old_play_pan(pan, volume, speed, looping) if volume > 0.0
end