Game Development Reference
In-Depth Information
We very well could scroll the screen using the
scrollRect
property of the
Sprite
holder instance.
However, we would lose the reusability of the
canvasBitmapData
world
BitmapData
canvas. With
the scrollable
Sprite
canvas and individual
Sprite
objects attached to its display list we would
have had to
draw
the
Sprite
holder's contents into a
radarBD BitmapData
on every frame we
wanted to update the radar. Alternatively, we could have created a miniature version of the
Sprite
holder with a second
Sprite
object to represent each
Sprite
canvas object. Both of these
ideas would be OK implementations, but they would be much slower than just reusing the
canvasBitmapData
as the
BitmapData
reference for out
radarBitmap
.
Obviously, the method of using a second Bitmap object to display the entire game world as a
radar only works if you want the radar screen to be a miniature version of the actual game
screen. If you want the radar to be an abstract representation of the game screen, you will have
to employ a different method.
When we create our
radarBitmap
, we set the reference to the
canvasBitmapData
:
private var radarBitmap:Bitmap = new Bitmap(canvasBitmapData);
As long as the
canvasBitmapData
has already been created, this line of code will work fine.
In the
init
function, we simply resize and place the
radarBitmap
on the screen. We then never
have to worry about it again. It will always be updated when the
canvasBitmapData
is updated.
radarBitmap.x = 420;
radarBitmap.y = 230;
radarBitmap.scaleX = .2;
radarBitmap.scaleY = .2;
addChild(radarBitmap);
Creating the new game classes
The following classes, although created for this specific game's needs, are engineered to be
generic pieces that can be reused by any game that needs them. Some will be added to the
framework, and some will be in the Blaster Mines package.
Designing the BlitArrayAsset class
The
BlitArrayAsset
class is located in
com.efg.famework
and is the equivalent of a
TileSheet
for
assets created in code. This helper class is used only to create arrays of assets. Instances of this
class will always be temporary and only local to the functions that we create them in. The class
doesn't even need a constructor; it is used like a library.
BlitArrayAsset
will be added to the
framework package and will have two public functions. The first is
public function createRotationBlitArrayFromBD(sourceBitmapData:BitmapData, inc:int,
offset:int = 0):Array {
This function requires a
BitmapData
(
sourceBitmapData
) instance to be passed in along with an
increment value and an angle
offset
for creating the rotation. The
BitmapData
represents a static
graphic that will be turned into an array of rotated
BitmapData
values. The
inc
(or increment value)
represents the degrees to skip on each object rotation. For example, an
inc
value of
1
would create
an array of 360 rotations (offset by 1 degree each), while an
inc
value of
10
would only create an
array of 36 rotations (offset by 10 degrees each).