Game Development Reference
In-Depth Information
Creating the play field
The play field will be a very simple design consisting of a horizontal white line at the top and
bottom of the screen. There will be a roughly 20-pixel buffer between the top and bottom of the
screen and the play field lines. The playfieldSprite will be added to the display list and contain
the playfieldShape (the white horizontal lines).
private var playfieldSprite:Sprite = new Sprite();
private var playfieldShape:Shape = new Shape();
private var playfieldminX:int = 0;
private var playfieldmaxX:int = 599;
private var playfieldminY:int = 21;
private var playfieldmaxY:int = 378;
Adding the obstacles
A pool of 1
1-pixel BitmapData objects will be created. Each will be housed inside a Bitmap
object. The obstacles will start on the right-hand side of the screen and move to the left. This will
simulate scrolling. When an obstacle is pulled from the inactive pool, it will be colored and resized
before it is placed on the screen.
private var obstaclePool:Array = [];
private var obstacles:Array = [];
private var tempObstacle:Bitmap;
private var obstaclePoolLength:int = 200;
Animating the player ship's exhaust
The player's ship will emit exhaust from the rear. The effect has not game-play value and is just a
decoration. These exhaust particles will be created using the BlitArrayAsset class from Chapter
11 (and the framework package structure presented earlier). They will be instances of the
BasicBlitArrayParticle class, also from the package structure. These particles will be in a pool
and will be blitted to a separate canvas than the rest of the game objects. This canvas will employ
a new technique (for this topic) called a “dirt rectangle” or “dirty rect erase,” which is explained in
the next section.
These variables create the background and canvas for our exhaust particles:
private var backgroundBitmapData:BitmapData = new BitmapData(580, 400, false, 0x000000);
private var canvasBitmapData:BitmapData = new BitmapData(580, 400, false, 0x000000);
private var canvasBitmap:Bitmap = new Bitmap(canvasBitmapData);
private var blitPoint:Point = new Point(0, 0);
The following are used for the exhaust pool (active and inactive):
private var exhaustPool:Array = [];
private var exhaustParticles:Array = [];
private var tempExhaustParticle:BasicBiltArrayParticle;
private var exhaustPoolLength:int = 30;
private var exhaustLength:int;
The exhaustAnimationList array holds the 10-frame fade of the exhaust particles as an array of
BitmapData objects.
Search WWH ::




Custom Search