Game Development Reference
In-Depth Information
For Flex, BitmapData is an attribute of the BitmapAsset embedded in the library, so we just need
to modify the call slightly. There is no need to pass in the width and height, we simply need to
reference the bitmapData attribute of the ship_gif embedded asset when you create the
imageBitmapData .
//***** Flex *****
imageBitmapData = new ShipGif().bitmapData;
Using sound
Sounds can be made to be compatible with both the IDE and Flex with a couple simple tips.
First, create new Sound instances with the Class types of Sound() rather than the linkage name in
the library. This allows both IDE and Flex projects to use the same sound assets, even though
the embedded types are slightly different.
For example, use the following
public var soundBonus:Sound=new SoundBonus();
instead of this
public var soundBonus:sound_bonus =new SoundBonus();
Second, for Flex, you must embed the sound of the SWF that contains the library.
[Embed(source = "assets/flackassets.swf", symbol="SoundBonus")]
private var SoundBonus:Class;
Don't worry if these tips do not make complete sense right now. We will cover all of this code in
detail when we discuss the various classes that will make up the Flak Cannon game.
Creating a sound manager
SoundManager.as is a new support class that we will add to the game framework. This class is
fairly self-explanatory, as it will help us play sounds in our game. Why do we need this class?
Because, while AS3 has a simple API to access sounds, there is no simple way to access sounds
and work with them in a single place. Embedding sounds in Flash is different to doing so in Flex,
so for Flex we will be using the Embed code style we described in the previous section.
The first thing we need to do is create a new class file named SoundManager.as with the in the
default requisite package for the framework ( com.efg.framework ) with a constructor. There are
several instance variables below that should be explained:
sounds : This Array holds the sound objects that the SoundManager will play.
soundChannels : This is an Array of SoundChannel objects. We keep sound channel
objects, so we stop sounds and change soundtracks when we receive an event to do so.
soundTrackChannel : This is a SoundChannel that we will use specifically for playing a
soundtrack song. We will explain why we discuss soundtracks later in this chapter.
soundMute : This Boolean a variable that will let us know if the sounds are currently muted
or not.
tempSoundTransform : This is a reusable SoundTransform object.
Search WWH ::




Custom Search