The SoundManager class
Throughout the next few chapters, we will be adding sound effects for various events. Sometimes these sounds will be triggered directly in the main PlatformView
class, but other times, they will need to be triggered in more remote corners of your code like the InputController
class and even within the GameObject
class themselves. We will quickly make a simple SoundManager
class that can be passed around and used as needed when a beep is required.
Create a new Java class and call it SoundManager
. This class has three main parts. In the first part, we simply declare a SoundPool
object and a bunch of int
variables to hold a reference to each sound effect. Enter the first part of the code, the declaration, and members:
import android.content.Context; import android.content.res.AssetFileDescriptor; import android.content.res.AssetManager; import android.media.AudioManager; import android.media.SoundPool; import android.util.Log; import java.io.IOException; public class...