Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
OpenGL Game Development By Example

You're reading from   OpenGL Game Development By Example Design and code your own 2D and 3D games efficiently using OpenGL and C++

Arrow left icon
Product type Paperback
Published in Mar 2016
Publisher
ISBN-13 9781783288199
Length 340 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Robert Madsen Robert Madsen
Author Profile Icon Robert Madsen
Robert Madsen
Stephen Madsen Stephen Madsen
Author Profile Icon Stephen Madsen
Stephen Madsen
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

The sound of music


We now turn to the audio soundtrack for our game. Just like a movie soundtrack, the music that is played during a game sets the tone for the game. Many games have huge, orchestrated productions, while others have synthesized or 8-bit music.

As we have already discussed, music files are handled in a different manner from sound effects. This is because sound effects are usually very short sounds that can be best stored as wav files. Music files tend to be much longer, and are stored as MP3 files because the data can be compressed, taking less storage and less memory.

We are going to add a single music track to our game. To keep things simple, we will tell the track to loop so that it runs continuously throughout the game.

We will start by adding a sound pointer. Open RoboRacer2D.cpp and add the following line of code to the variable declarations:

FMOD::Sound* musBackground;

Next, go to the LoadAudio function and add the following line:

result = audiomgr->createSound("resources...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image