Game Development Reference
In-Depth Information
offset : This Number defines the offset, in milliseconds, into the song to start. It can be
useful for skipping an MP3 leader if you have loaded .mp3 sounds.
volume : This Number sets the volume level to play the sound; it's value can be between 0
and 1 .
When the soundEventListener() function is called, we look at the type parameter to see if we
should play or stop the sound. Other than that, all the parameters are passed into
soundManager.playSound() as is.
public function soundEventListener(e:CustomEventSound):void {
if (e.type == CustomEventSound.PLAY_SOUND) {
soundManager.playSound(e.name, e.isSoundTrack, e.loops, e.offset, e.volume );
}else {
soundManager.stopSound(e.name, e.isSoundTrack);
}
}
Defining Main.as
Now, we start the specific code for Flak Cannon by defining the Main.as class. Recall that we
have abstracted most of the game framework from Main . We did this so customizing the game
would be easier, while leaving the framework itself untouched for a specific game (except for
when we enhance the game framework itself with new features for all games).
The import statements are standard for Main.as classes for our games. Notice that we need to
add the new SoundManager we created so we can use it for this game.
package com.efg.games.flakcannon
{
import com.efg.framework.FrameWorkStates;
import com.efg.framework.GameFrameWork;
import com.efg.framework.BasicScreen;
import com.efg.framework.ScoreBoard;
import com.efg.framework.Game;
import com.efg.framework.SideBySideScoreElement;
import com.efg.framework.SoundManager;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.text.TextFormat;
Recall that our Main.as class extends com.efg.framework.GameFrameWork . This means that we
only need to override the functions that we will need to change; for Flak Cannon, that will only be
the init() function.
public class Main extends GameFrameWork {
//custom sccore board elements
Search WWH ::




Custom Search