Game Development Reference
In-Depth Information
foreground. This will give the impression that the background is
much further away from the player.
protected function createProjectile(e:MouseEvent):void {
var projectile:Projectile = new Projectile
projectile.x = mouseX;
projectile.y = mouseY;
addChildAt(projectile, getChildIndex(player));
protected function removeProjectile(projectile:Projectile):
void {
if (projectile.parent == this) removeChild(projectile);
The last two functions in this class control are the creation and
removal of projectiles. The createProjectile method is called when
the mouse is pressed. It generates a new projectile object, moves it
to the mouse
s position, adds it to the vector list, and places it on
the stage underneath the player. In removeProjectile ,wesimply
pass any projectile instance as a parameter, and it is removed from
the stage and spliced from the list.
When you run this example, you can see that the animation
behind it is very basic, but effective. It conveys a continual sense of
motion and gives the impression that we
re traveling very quickly.
animating in the same direction as the foreground and background.
In the next example, we will look at a very different kind of game,
in which tweening is a more effective method of animation.
Memory: Tweening Animation
The following example is a simple memory game. There are six pairs
of matching cards that have a gray back and one of six different col-
ors on their front. The player clicks any two cards to flip over; if they
match, they stay face up. If they do not match, they are flipped back
over. In this instance, the game mechanic involves no motion by
default, so we
ll need to add animation to liven the experience up.
This is when a tweening library like TweenMax comes in. We
ll use
TweenMax, combined with the 3D DisplayObject properties, to
make the cards look like they
example, this game has two classes that control its functionality. The
files can be found in the Chapter 6 examples folder; the main file is
Search Nedrilad ::

Custom Search