In part 8 of this challenge, physics simulation was added so that Scarfy could walk on the terrain. Today, I'm going to add atmosphere with background music. That might sound simple, and the RayLib part certainly is. Getting the music, though, is another matter...

Choosing Music

Music can create the right atmosphere for a game (or movie). It can make you feel like you're in heaven, or like the devil is breathing down your back (and everything in-between). The music style can also add to your game's overall character.

So, where can we get music? The simplest option would be to go to a royalty-free music library, find music you love, and pay for the rights to use it. However, there's a problem...

ContentID Troubles

Let's say you pay for some music, use it in your game, and upload a video to YouTube. Seconds later, your video gets a copyright strike/claim. YouTube's ContentID recognized that you used copyrighted music, but doesn't know you paid for the rights to use it and flags your video. So, you have to submit a counter-claim, and wait. I still have a copyright claim from years ago, for music for which I had paid the rights to use. They ignored my counter-claim.

Things have gotten better. Many royalty-free music libraries now allow you to enter your YouTube channel ID, so they can filter you out. Unfortunately, there's still a problem: game streamers.

You really want game streamers to play your game because it helps people discover your game (and hopefully buy it). Game streamers don't use your channel ID (they have their own), so their live-streams/videos of your game will get flagged and possibly demonetized. Game streamers earn money off their channel, so getting flagged for copyright violation is going to upset them.

I'm not saying that you should never use royalty free music. Just be aware of this problem. Try to find music that's ContentID free (it exists, but is rare). If you can, commission a composer/musician to create music for your game. Or, if you have the musical talent, create your own.

I'm on a tight budget, so I chose to record my own music (watch the video for more).

Playing Music with Raylib

This is the easy part, and can be done with just a handful of functions. See the Raylib cheat-sheet's music section. In brief:

  • Load the music file with LoadMusicStream()
  • Set the volume using SetMusicVolume()
  • Start playing by calling PlayMusicStream()
  • Call UpdateMusicStream() every game loop cycle to keep the stream going

That's all there is too it. Oh, you may also want to call StopMusicStream() and UnloadMusicStream() once you're done with the music. It really is that simple.

What's Next?

Click here for Part 10.

Download the Code

Click here to download the source code.