Class: Gosu::Song

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

Constant Summary

DEFAULT_VOLUME =
1.0

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Chingu::NamedResource

included, #name, #name=

Constructor Details

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

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



60
61
62
63
64
65
66
67
68
69
# File 'lib/chingu/gosu_ext/song.rb', line 60

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

  old_initialize(filename)

  @muted = false
  self.volume = options[:volume]
end

Class Attribute Details

.volumeObject

Volume of Songs, not allowing for global volume settings.



10
11
12
# File 'lib/chingu/gosu_ext/song.rb', line 10

def volume
  @volume
end

Class Method Details

.autoload(name) ⇒ Object



103
104
105
# File 'lib/chingu/assets.rb', line 103

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

.effective_volumeObject

Volume the song is played at, affected by Song.volume and Window#volume/muting.



13
14
15
# File 'lib/chingu/gosu_ext/song.rb', line 13

def effective_volume
  @volume * $window.effective_volume
end

.init_soundObject



29
30
31
32
# File 'lib/chingu/gosu_ext/song.rb', line 29

def init_sound
  @volume = DEFAULT_VOLUME
  nil
end

Instance Method Details

#effective_volumeObject

Volume, as played.



53
# File 'lib/chingu/gosu_ext/song.rb', line 53

alias_method :effective_volume, :volume

#volumeObject

Volume, not affected by Song volume or the Window volume/muted.



72
73
74
# File 'lib/chingu/gosu_ext/song.rb', line 72

def volume
  @true_volume
end

#volume=(value) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/chingu/gosu_ext/song.rb', line 76

def volume=(value)
  @true_volume = [[value, 0.0].max, 1.0].min

  self.effective_volume = @true_volume * self.class.effective_volume unless @muted

  volume
end