Flash dodge ball game part 2 character key moving


Now we got our little cartoon man from last session, this time we will make him move with the arrow keys on your keyboard.


1.
Select our cartoon man, then open up the actions panel, (as default its located at the bottom of the screen).

Photoshop Tutorial thumb picture


2.
Type in the following

onClipEvent (enterFrame) {

}

This tells flash to update frequencley and do whatever we put in the empty content field.

3.
Now inbetween { and } we want to type in our content so now the code should look like this.

onClipEvent (enterFrame) {

if (Key.isDown(Key.UP)) {
this._y -=9;

} }

Now first we have an if statement, this tells flash that if a key is held down then do something, and the key we put in the if statement is the up key, this as a reference as Key.UP

4.
Then what will happen when the key is down is that our cartoon man shall move up, our man is refered to as this._y, y is the y axis, (up and down, the x axis is left and right).

5.
-=9;

This subtract the coordinats for y axis, and why I use 9, thats the speed, set it to 2 and it will walk slower, set it to 30 and it will be very fast.

6.
Now we have to make the same code again with just a few minor changes, instead of Key.UP we need Key.Down and then left and right. (x axis) so here is all the code.

Photoshop Tutorial thumb picture


7.
Try your flash game, and you will see that our guy can move smooth around, even angled.
Next we will give some detail to our characters movement, so when he moves then the feet and body moves.

Part 1 Part 2 Part 3 Part 4 Part 5 Part 6 Part 7

0tutor.com rss feed