Building a sound engine
This is a bit different to how we have previously handled the sound but still should seem very familiar. We will be writing code that prepares a SoundPool
and plays some sound. It will be nearly identical to the sound code we have written in the other projects with the exception that there will be a method that plays each sound effect.
This means that any part of our code that has an instance of SoundEngine
will be able to play whatever sound effect it needs yet at the same time all the sound code will be encapsulated.
Note
We have already seen in the GameState
class that the loseLife
method receives an instance of SoundEngine
and calls the playPlayerExplode
method.
To prepare to code SoundEngine
create a new class called SoundEngine
in the usual way.
Adding the sound files to the project
Before we get to the code let's add the actual sound files to the project. You can find all the files in the assets
folder of the Chapter 18
folder of the download bundle. Copy...