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 ...
Get Learning Java by Building Android Games - Second Edition 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.