|
TUTORIAL: Building games in Flash 5
Part 1: Player movement and fire.
Author:
David Doull
Date: 23/02/01
Download source files: tut1.zip
Lastly the moveSpeed bit. Remember
we set moveSpeed equal to a fixed value of 10 earlier. So
if the left arrow was pressed the x-position would be set
to the previous x-position -10 (ie: ten is subtracted from
the previous x-position).
If the right arrow key is being pressed
then the new x-position is the previous x-position plus 10.
so the code:
if (Key.isDown(Key.RIGHT)) {
this._x+=moveSpeed;
}
else if (Key.isDown(Key.LEFT)) {
this._x-=moveSpeed;
}
means: " if the right arrow key
is being pressed down then increase the x-position of the
current movie clip (the spaceship) by the value of MoveSpeed
(which is 10),
Otherwise if the left arrow key is beign pressed down then
decreasse the x-position of the current movie clip (the spaceship)
by the value of MoveSpeed (which is 10) "
Finally, the code:
if (Key.isDown(Key.DOWN)) {
this._y+=moveSpeed;
} else if (Key.isDown(Key.UP)) {
this._y-=moveSpeed;
}
does the same thing only it increases
or decreases the y-position of the spaceship based on the
UP or DOWN arrow keys.
If you want to skip all the above typing
you can download the following fla: tutorial1_part1b.fla
Next >>
|