class SK::AudioManager
Attributes
music_volume[R]
sfx_volume[R]
Public Class Methods
new(context, content_root)
click to toggle source
# File lib/shirokuro/audio/audio_manager.rb, line 6 def initialize context, content_root @sfx_volume = 1.0 @music_volume = 1.0 @context = context @content_root = content_root.end_with?("/") ? content_root : "#{content_root}/" @song_names = [] @sound_names = [] @songs = {} @sound_instances = [] @sounds = {} @file_extension = ".ogg" end
Public Instance Methods
get_song(song_name)
click to toggle source
# File lib/shirokuro/audio/audio_manager.rb, line 72 def get_song song_name @songs[song_name] end
load()
click to toggle source
# File lib/shirokuro/audio/audio_manager.rb, line 36 def load @song_names.each do |song| @songs[song] = Gosu::Song.new(@context, "#{@content_root}#{song}#{@file_extension}") end @sound_names.each do |sound| @sounds[sound] = Gosu::Sample.new(@context, "#{@content_root}#{sound}#{@file_extension}") end end
pause_song(song_name)
click to toggle source
# File lib/shirokuro/audio/audio_manager.rb, line 62 def pause_song song_name @songs[song_name].pause end
play(sound_name, pitch = 1.0, looping = false)
click to toggle source
# File lib/shirokuro/audio/audio_manager.rb, line 46 def play sound_name, pitch = 1.0, looping = false @sound_instances << @sounds[sound_name].play(@sfx_volume, pitch, looping) end
play_pan(sound_name, pan = 0, pitch = 1, looping = false)
click to toggle source
# File lib/shirokuro/audio/audio_manager.rb, line 50 def play_pan sound_name, pan = 0, pitch = 1, looping = false @sound_instances << @sounds[sound_name].play(pan, @sfx_volume, pitch, looping) end
play_song(song_name, looping = true)
click to toggle source
# File lib/shirokuro/audio/audio_manager.rb, line 54 def play_song song_name, looping = true @songs[song_name].play(looping) end
register_song(name)
click to toggle source
# File lib/shirokuro/audio/audio_manager.rb, line 23 def register_song name @song_names << name end
register_sound(name)
click to toggle source
# File lib/shirokuro/audio/audio_manager.rb, line 19 def register_sound name @sound_names << name end
resume_song(song_name)
click to toggle source
# File lib/shirokuro/audio/audio_manager.rb, line 66 def resume_song song_name if @songs[song_name].paused? @songs[song_name].play end end
set_music_volume(volume)
click to toggle source
# File lib/shirokuro/audio/audio_manager.rb, line 27 def set_music_volume volume @music_volume = volume # TODO: set on playing song instances end
set_sfx_volume(volume)
click to toggle source
# File lib/shirokuro/audio/audio_manager.rb, line 32 def set_sfx_volume volume @sfx_volume = volume end
stop_song(song_name)
click to toggle source
# File lib/shirokuro/audio/audio_manager.rb, line 58 def stop_song song_name @songs[song_name].stop end
update(dt)
click to toggle source
# File lib/shirokuro/audio/audio_manager.rb, line 76 def update dt @sound_instances.delete_if{|s| !s.playing? } end