We will get started with the Libgdx sound system by playing short sound effects, also known as SFX. Often, effects go unnoticed, and this is really unfair towards them! As an exercise, try turning the effects' volume down in an action shooter and see how much you enjoy it. It is not the same experience at all, is it?
The sample shown in this recipe will illustrate how to play, pause, resume, and stop sounds. We will map the number keys from 1 to 7 to different sounds. The P key will pause the sounds, R will resume playback, and S will stop playback.
The code for this recipe will be found in the SoundEffectSample
class. Follow these instructions to master how to play back sound effects:
Unsurprisingly, the class through which we will work is called
Sound
. AnIntMap
ofSound
instances will help us manage the sound collection of our sample. The effects will be...