Game Development Reference
In-Depth Information
We only added couple of things over previous example.
72 @music = Gosu :: Song . new(
73 self , media_path( 'menu_music.mp3' ))
74 @music . volume = 0.5
75 @music . play( true )
GameWindow creates Gosu::Song with menu_music.mp3 , adjusts the volume so it's
a little more quiet and starts playing in a loop.
16 def self . load_sound (window)
17
Gosu :: Sample . new(
window, media_path( 'explosion.mp3' ))
18
19 end
Explosion has now got load_sound method that loads explosion.mp3 sound
effect Gosu::Sample . This sound effect is loaded once in GameWindow constructor,
and passed into every new Explosion , where it simply starts playing.
Handling audio with Gosu is very straightforward. Use Gosu::Song to play background
music, and Gosu::Sample to play effects and sounds that can overlap.
Search WWH ::




Custom Search