Game Development Reference
In-Depth Information
ll need to establish to create this
engine. The first is the engine itself, SoundEngine.as. The second
class is an internal
Therearethreeclassfileswe
'
class called SoundEngineObject. This
object will store information about each individual sound as it is
created in order to keep track of them. In the original version of
this engine, I kept this class inside of the SoundEngine.as file,
which, while tidy, left extensibility of the engine inflexible. It is still
marked internal, but by being in its own file, other classes in the
same package can access it. We
helper
ll discuss more about this class in
a moment. The other file is a special type of event, SoundEngine-
Event.as. This is the type of object the SoundEngine will dispatch
when certain events, such as a sound reaching its end or an error
in playing or loading a sound, occur within the engine.
Here
'
'
s a quick rundown of the functionality this class will contain:
￿
Start sounds, both internal and external
￿
Stop sounds
￿
Pause/resume sounds
￿
Mute/unmute sounds
￿
Set and retrieve the volume of sounds
￿
Set and retrieve the pan of sounds
￿
Set and retrieve the entire active SoundTransform of sounds
￿
Retrieve the SoundChannel object that an active sound is using
￿
Add listeners that will be notified of events within the
SoundEngine
￿
Retrieve the current status of a sound, such as whether it is
playing, paused, or muted
All of this information can currently be retrieved from sounds,
albeit with several lines of code. Our goal is to simplify this process
and not have to rewrite this code every time we want to play a sound.
We
ll begin in the SoundEngine.as file and set up the class
definitions we
'
'
ll be using.
package
{
import flash.events.EventDispatcher;
import flash.events.IOErrorEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
import flash.media.SoundTransform;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.utils.getDefinitionByName;
public class SoundEngine extends EventDispatcher {
}
}
Search Nedrilad ::




Custom Search