First tutorial – simple gravity continued.-cord

First tutorial – simple gravity continued.

This is the second part for the flash tutorial where we make simple gravity. The first tutorial can be found here. Well, in this tutorial I was thinking about to add some movement to the character.


<
Now we have an guy that falls down, which you can jump with. What to do
now? Because we probably want horizontal speed too, and want to make
the steering. We could make a simple steering technique, replace the
code in your flash application from the last tutorial with this code:

View CodeACTIONSCRIPT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//The following 2 lines puts the man mc into the coordinates x:275, y:70.
man._x = 275;
man._y = 70;
//Variables:
gravity = 0.5;
jumpPower = 10;
yspeed = 0;
//Adds an function that runs every frame.
onEnterFrame = function () {
//If man is not touching "ground"
if (man._y<400) {
yspeed += gravity;
} else {
//if it touches ground:
man._y = 400;
yspeed = 0;
//Jump
if (Key.isDown(32)) {
//if space(32) is down.
yspeed -= jumpPower;
}
}
//Movement:
if (Key.isDown(Key.LEFT)) {
man._x -= 5;
} else if (Key.isDown(Key.RIGHT)) {
man._x += 5;
}
if (man._x<40) {
man._x = 40;
} else if (man._x>510) {
man._x = 510;
}
//Adds the yspeed to mans _y coordinate.
man._y += yspeed;
};

The result should look a little bit like this:

ข้อความนี้ถูกเขียนใน Micromedie Flash คั่นหน้า ลิงก์ถาวร

ใส่ความเห็น

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / เปลี่ยนแปลง )

Twitter picture

You are commenting using your Twitter account. Log Out / เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out / เปลี่ยนแปลง )

Google+ photo

You are commenting using your Google+ account. Log Out / เปลี่ยนแปลง )

Connecting to %s