Game Development Reference
In-Depth Information
The play and stop methods start and stop the sound object,
respectively, and store the information about how the sound is to be
played. They also set up a listener for the SOUND_COMPLETE event,
which is dispatched when the sound finishes. You
ll probably notice
I used a lot of the same syntax Sound and SoundChannel objects so
as to stay consistent with ActionScript
'
s conventions. If the same
sound is called multiple times before it is able to finish, as might well
be the case in a game in which a player fires some type of projectile,
any currently playing channel should be allowed to finish and then
remove itself. Also, we allow the option for sound to loop endlessly by
passing in a negative number (preferably
'
1) and then setting the
number of loops to the largest possible integer. In the original version
of the engine, I used the SOUND_COMPLETE event to check and
start the sound looping again. However, this led to a
every
time the sound looped because of the delay between the event and
the sound actually restarting. The only way to get a smooth, seamless
loop is to pass in a loop count to the play method. There is also one
public
hiccup
which will return whether or not the sound is cur-
rently playing; this functionality does not exist in the basic Sound
classes in ActionScript and is very helpful information to have in a
game. If background music is already playing, for example, then you
don
getter,
'
t want to accidentally start it a second time.
public function get volume():Number {
if (_canPlaySound && channel != null) {
return channel.soundTransform.volume;
} else {
return 0;
}
}
public function set volume(value:Number):void {
if (_canPlaySound && channel != null) {
var tf:SoundTransform = _transform;
tf.volume = value;
_transform = tf;
if (!_muted) channel.soundTransform = _transform;
}
}
public function get pan():Number {
if (_canPlaySound && channel != null) {
return channel.soundTransform.pan;
} else {
return 0;
}
}
Search Nedrilad ::




Custom Search