Lillypad: Sound

Posted in: Articles, Lilly Pad by preitz on

This update is the first on this project that is, shall we say, a bit disappointing. I was distracted yesterday, and, to be honest, spent most of the day goofing off (on a non-scheduled goof off day). I’m sure this won’t be the last time, and the only thing to do is get back on track and carry on.

That said, here’s what I did get done yesterday. The main class for handling sound is the SFX class. This is a static class that stores all sounds used by the game. It’s also used to play sounds and background music, and to keep track of whether sounds should be played or not. the SFX class provides the following functions and properties:

addSound(name:String, sound:Class)

The name is a unique identifier for the sound. This will store the sound to be used later.

play(name:String, loops:int = 1)

Plays the sound referenced by the name. If the second parameter is omitted, the sound will be played once. You can include the second parameter to indicate how many times the sound should be played. Entering ‘0’ for the second parameter will loop the sound forever.


playBackground(name:String)

This plays a sound as background music. The sound will loop indefinitely. Also, the sound referenced by the name parameter will be flagged as the background and treated a bit differently.

pause(name:String), stop(name:String)

I’m including these two functions together because they do almost the same thing. They stop the music from playing. The difference is what happens to the sound the next time you play it. If the sound was paused, then playing it again will start the sound at the point where it was stopped. If the sound was stopped, it starts again at the beginning.

stopBackground()

If a sound has been flagged as the background, and is currently playing, this function will pause (not stop) the background sound.

stopAll(background:Boolean = true)

This stops all sounds that are currently playing. The optional can be set to false to tell the function not to stop the background music.

playSounds:Boolean

This property sets whether or not sounds should be played.

playMusic:Boolean

This sets whether or not the background music should be played.

I have no demo today, but I did want to take the time to give a little background on some of the decisions that went into this class. I believe that sound is very important to games. Most casual games give an option to disable sounds, but I like to have the sound on. However, I also like to have iTunes or Pandora playing in the background while I play. So many games only provide an “all or nothing” option when it comes to sound. This is why I decided a long time ago to differentiate between sounds and background music. And this philosophy made it into this SFX class.

So that’s what I have for sounds. There won’t be an update tomorrow, as I’m heading up a mountain again, but I’ll be back on Friday.

 

Next: Lillypad: Project Lag

  • No Comments Yet