class Audio
def initialize(source)
@source = source # The game window
@bgm = {}
@se = {}
loadBGM
loadSE
end
def playBGM(file)
@bgm[file].play
end
def playSE(file)
@se[file].play
end
def loadBGM
Dir.glob(File.join(File.dirname(__FILE__), 'Audio/BGM/') + '*.wav') do |wav_file|
@bgm[File.basename(wav_file)] = Gosu::Song.new(@source,wav_file)
end
end
def loadSE
Dir.glob(File.join(File.dirname(__FILE__), 'Audio/SE/') + '*.wav') do |wav_file|
@se[File.basename(wav_file)] = Gosu::Sample.new(@source,wav_file)
end
end
end
class Audio
AUDIO_PATH = File.join(File.dirname(__FILE__), 'Audio')
BGM_PATH = File.join(AUDIO_PATH, 'BGM')
SE_PATH = File.join(AUDIO_PATH, 'SE')
def initialize(source)
@source = source # The game window
@bgm = {}
@se = {}
end
# Clear preloaded audio resources.
def clear
@bgm.clear
@se.clear
end
# Preload the BGM +file+.
def preloadBGM(file)
@bgm[file] ||= File.join(BGM_PATH, "#{file}.wav")
end
# Preload the sound effect +name+.
def preloadSE(file)
@se[file] ||= File.join(SE_PATH, "#{file}.wav")
end
# Play the BGM +file+. If +file+ hasn't been preloaded, it will be loaded
# on demand the first time it's played.
def playBGM(file)
preloadBGM(file).play
end
# Play the sound effect +file+. If +file+ hasn't been preloaded, it will be
# loaded on demand the first time it's played.
def playSE(file)
preloadSE(file).play
end
end
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill