Saturday, July 18, 2015

Sound!

I've finally thrown in sound. So far just sound effects, no music. I'm not sure if I'll even add music as I don't see much of a necessity for it in a simple puzzle game. Also, I don't like working with audio because I have very little experience with it.

I created a Sounds class and put it in the src folder so that it's easily accessible to any class, no import needed. All sounds are mp3 files that are embedded and passed to a Sfx instance. To play the sound, you just call play() with the Sfx instance. You can pass a Number value in the play() call to adjust volume.

BlockPusher has three save files and each has its own SFX volume level. The volume setting is saved for each save file so when a user selects a different save file it knows the last volume setting for that file. So instead of calling play() on a Sfx instance whenever a sound needed, I created a function for each sound that calls play() for it's Sfx instance. In that play() call, it calls a function that gets, calculates, and returns the volume level for the particular save file in use.