Godot Tutorials is not sponsored by or affiliated with the Godot Game Engine.
I want to go
over a quick overview of this
episode. First, I'm going to go
over what we need to know and have in order to perform this episode's task
of adding
music and then go straight into live coding
examples. This episode
will be the last time we look at a coding
example. I do not want to
go overboard in this episode with adding music. Therefore, let's keep it simple. One background music and the few sound
effects after this,
a few more episodes that go over friendly advice, theory,
comments in your code
and adding the project to each that I
owe.
And don't forget that you can download the project over at GitHub if you want to see the code instead of watching this episode.
Now, finally, this is the
episode where everything comes
together. And for that
we are going to need music and
sound
effects. Two types of things to consider when adding music and sound effects into your game is are you making a prototype or are you just
practicing with lower level code or practicing in general? If it's the
former, then just remember to take into consideration what type of game you want to make when picking up music and some
defects. If it's the latter, which this
episode resides around, just let loose and have some fun. Pick something that
resonates with you. Up until
this point, we focus on the nitty gritty details of coding since we are adding the frosting to our game
cake when adding
music and sound effects. Let's just have some fun with the music.
I want to mention
something really quick. Nothing beats making your own music and sound effects from
scratch, but that
topic is
out of scope for this series. For now,
let's just pick a free open source music and sound effects that are royalty free. I'm going to add a link in the description down below for a website called Open Game Mart dot org.
It's an amazing
website. Lots of music and sound effects to choose from. You just have to find one that resonates with you and or what you're trying to accomplish with your game. On top of that, I recommend that you check
out my Godot basic
series, more specifically episode fifty four through fifty nine as I won't be going over how everything works in interconnects with one another, as I have already explained this in thorough
detail, this episode
expects basic understanding of the following nodes audio stream player, animation player, animation, audio file types and audio buses. Since this is the last episode where I go over code, I want to keep things simple
or
as simple as I can get with what I taught so far in the Godot Basics series. And for this reason of easing out of
coding, I do not want
to add audio
buses to manage
the sound levels of music and sound effects, but you are highly encouraged to do so in your own practice project. Just keep in mind that it is your audio stream player that manages which audio books the signal goes to and by default, all audio stream player notes and their signal to the bus named Master. Regardless, let me show you what we will be creating. So the music and sound effects we will be adding to our game will be very simple. We will have one main background music that will loop itself for as long as the game plays.
And then we will
find sound effects for when the ball collides with the paddle or walls, when the player wins or loses
a point
and sound effects for when the player wins or loses around.
First we
will work on background
music and once that
is done, we will then work on adding sound effects to our games, no matter whether we are creating background music or sound effects. Because we are working with audio stream player and animation player, we do need a way to create animations for our animation players, which passes itself into an audio stream player. We will be coding things in the following order. The order of coding will start off with our animation data container, followed by the animation player that will need our animation data container. Then we will create the audio stream player which will control the playing of our sounds.
Lastly, we will need to add the code to the appropriate locations in our game for this sounds to take effect. Now, keep in mind we will be creating two audio stream players. One audio stream player will handle the background music. The other audio stream player will handle playing our sound effects.
OK, so let's
get into the code.