Game Development Reference
In-Depth Information
public function render():void {
x = nextLocation.x;
y = nextLocation.y;
}
public function dispose():void {
removeChild(image);
imageBitmapData.dispose();
image = null;
}
}
}
Creating animated sprites
In Flak Cannon, two game objects require multiple frames of animation: Flak and Explosion . Both
are nearly identical, but they have some major differences from the moving (and in the case of
Ship , not moving) static sprites.
Flash gives programmers some very easy ways to create animation using the built-in timeline and
MovieClip s. In Chapter 1, we created an explosion using this method. However, since this
chapter begins our journey into the world of using bitmaps to make games, we are not going to
cut corners. Creating MovieClip s for animation is easy, but you pay a price in overheard for using
them. Bitmaps can be fast and efficient, and we will make use of them throughout this topic to
create games.
For an animated sprite, we need multiple images that we can display over time to achieve the
desired effect. Luckily, we already imported seven graphics that we can use for our Flak
explosion. All we need now is a way to display them, one after another, controlling their order and
how long they are displayed before the image is changed.
Flak
Recall that the flak explosion contains seven frames of animation that we added to the library
(see Figure 4-3). These are the frames we need to run through to display the Flak explosion. To
start off, the import statements for Flak are identical to the ones for Shot , as is the class
definition.
package com.efg.games.flakcannon
{
// Import necessary classes from the flash libraries
import flash.display.Shape;
import flash.display.Sprite
import flash.events.MouseEvent;
import flash.display.Bitmap;
import flash.display.BitmapData;
public class Flak extends Sprite
{
However, the similarities end when we start to define the instance variables. First of all, instead of
a single image, we have an array named images . This will hold the frames of animation that Flak
will run through. We do still need a single image variable to hold the current frame of animation,
Search WWH ::




Custom Search