Add Music and Sounds

Music and sounds help set a mood, add another dimension to your game, and make your game more polished. Let’s add a different background track to each scene and add sound effects for shooting and explosions. Gosu makes a distinction between background music, which plays for a long time, and sound effects, which are short. Background music is streamed, so the entire file does not need to be loaded into memory and is not synchronized with the game. Sound effects, or samples, are loaded into memory so that they can play at exactly the right moment in your game. It wouldn’t do to have a lag between the enemy exploding and the explosion sound.

Finding Sounds

What you need are electronic files of sounds in WAV or OGG format. If ...

Get Learn Game Programming with Ruby now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.