Playing short sound effects

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.

Getting ready

Make sure the sample projects are in your Eclipse workspace to follow this recipe.

How to do it…

The code for this recipe will be found in the SoundEffectSample ...

Get Libgdx Cross-platform Game Development Cookbook 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.