Game Development Reference
In-Depth Information
limitation but with the added headache of trying to avoid the space of silence at the beginning of
the
.mp3
file. We will use the offset setting when we play sounds to bypass this silent space. We
went over this limitation in more detail in Chapter 10 when we also added the Drive She Said
sounds to the library as MP3 files.
Note that if you are using the Flash IDE, you will need to import all of the
.mp3
sounds and create
linkage names that match the class names listed in the
Library
class.
Let's create this class as the next new file for the Blaster Mines game package. Here is the class
file name and location.
And this is for the Flex SDK (using Flash Develop):
/source/projects/blastermines/flexSDK/src/com/efg/games/blastermines/Library.as
Here is the entire
Library.as
class; we'll look at the changes after you have taken a look at all of
the code for this class:
package com.efg.games.blastermines
{
public class Library {
[Embed(source='../../../../../assets/mineExplode.mp3')]
public static const SoundMineExplode:Class;
[Embed(source = '../../../../../assets/musicIngame.mp3')]
public static const SoundMusicInGame:Class;
[Embed(source='../../../../../assets/musicTitle.mp3')]
public static const SoundMusicTitle:Class;
[Embed(source='../../../../../assets/playerEnter.mp3')]
public static const SoundPlayerEnter:Class;
[Embed(source='../../../../../assets/playerExplode.mp3')]
public static const SoundPlayerExplode:Class;
[Embed(source='../../../../../assets/playerHit.mp3')]
public static const SoundPlayerHit:Class;
[Embed(source='../../../../../assets/playerShoot.mp3')]
public static const SoundPlayerShoot:Class;
}
}
Notice that, just like all of the library class constructions so far, we need to ensure that the class
names for the sounds match those in the
Main.as
and that we have used the correct path to the
assets folder.
Modifying the SoundManager class
The
SoundManger
class in the game framework needs to be modified to allow the mute
functionality to work properly. Remember, this class is in the
com.efg.framework
package. We
need to add two new private variables:
Private var soundMute:Boolean
and
private var
muteSoundTransform:SoundTransform = new SoundTransform();
.