Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Last night I added music and sounds to the game. I've found that adding polish to a game as you go along really helps to keep you motivated. I found some nice free music online, and I created the sound effects using sfxr: http://www.drpetter.se/project_sfxr.html My process for creating the sound effects is pretty much randomly creating new sound effects and then twiddling with the bars, moving them small amounts until it starts to sound like something acceptable.

In the past when dealing with sound, it was always the last thing added to a project and this resulted in some bad spaghetti code. This time I approached it from an object oriented angle, and created some sound classes that seem to work really well.

The first thing I did was create an enum that has a type for each of the sounds:


I always load all of the assets for the game in the top level Game class, including sounds and textures. So in that class I created a Map<SoundType, Sound>, and I created a Sound object for every SoundType and added it to the Map.

At this point. you could call a sound just by grabbing it from that Map and doing sound.play(), but instead I created a SoundPlayer class to make things a little easier:


Now I play sounds by calling libGDXGame.soundPlayer.playSound(SoundType.soundTypeToPlay). This way, I can enable or disable sound effects all in one place, and I could easily extend this to have a user adjustable volume level.