Game Development Reference
In-Depth Information
The Private var soundMute:Boolean variable will be turned from true to false and vice versa
when the muteSound function is called.
The private var muteSoundTransform:SoundTransform = new SoundTransform(); variable is an
instance of the SoundTransform class. It will be used to set the volume between 0
( soundMute=true ) and 100 ( soundMute=false ).
Now, let's take a look at the muteSound public function:
public function muteSound():void {
//trace("sound manager got mute event");
if (soundMute) {
soundMute=false;
muteSoundTransform.volume=1;
SoundMixer.soundTransform=muteSoundTransform;
}else{
muteSoundTransform.volume=0;
SoundMixer.soundTransform=muteSoundTransform;
soundMute=true;
}
}
Notice that we are setting the global SoundMixer 's volume by setting its soundTransform attribute
to the value of our own muteSoundTransform variable. We must import the SoundMixer class to do
this. Add this line to the class import section of the class:
import flash.media.SoundMixer;
Before we start to look at the details of the new gameplay-related classes that we are going to
add to the game framework and the Blaster Mines package, let's take a look at some more
optimization theory that we will implement for our game.
Optimizing with object pooling
Object pooling is an optimization technique that helps conserve both system memory and
processor execution time. The method we will use to pool objects will be to create an Array of our
objects types in a so called “pool.” When we need to use an object, we will take it from the pool. If
no objects are left in the pool, we will not be able to display an object. This is perfect for effects
like particles that don't affect gameplay.
Conserving processor execution time
Creating new objects is a very processor-intensive activity. By reducing the need for objects to be
reinstantiated each time they are needed, we reduce the overall execution time for the game.
Conserving memory
It is not obvious up front why object pooling would save memory, because we are going to create
a pool of global objects that will be around, using up system memory and won't be garbage
collected until we dispose of them. More memory is used up when the game begins, because the
Search WWH ::




Custom Search