sad news Shake effect tutorial
Apr 09

Hello! This is a tutorial that has the previous, deleted tutorials info in it too, and some more. I’m going to show how to make a simple jetpack man application engine. So, now Ill start :P

Part 2 here!

ActionScript 2!

First off, draw a jetpack man or anything that you’re going to control. Select it and press f8. A window pops up. Name it whatever you want, and remember to put the registration point into the center of the movieclip. Make the instance name of it to “fly” without quotes. Now you got everything there done. Now, click on the main timeline, which looks like a thin box that has a circle in it. Press f9 to bring up the actionscript-panel. Now type in the following code in it:

?View Code ACTIONSCRIPT
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
yspeed = 0;
xspeed = 0;
gravity = 0.2;
rotationspeed = 0;
power = 1;
friction = 0.9;
fly.onEnterFrame = function() {
yspeed += gravity;
xspeed *= friction;
this._x += xspeed;
rotationspeed *= friction;
this._rotation = 0+rotationspeed;
if (this._y<=400-this._height/2) {
this._y += yspeed;
if (Key.isDown(37)) {
xspeed -= power;
rotationspeed += power*xspeed/2;
} else if (Key.isDown(39)) {
xspeed += power;
rotationspeed += power*xspeed/2;
}
} else {
xspeed *= friction;
yspeed = 0;
this._y = 400-this._height/2;
}
if (Key.isDown(38)) {
yspeed -= power;
}
if (yspeed<0) {
yspeed *= friction;
}
};

When you’ve done that, press ctrl+enter to see how it looks like. If you followed these easy steps right, the result should look a bit like this:



Your Ad Here

Now to the explanation:

Rows 1 - 6 are just the variables that makes it possible to make everything run. You could try to change the value of gravity, power and friction to see what happens. The three others are just variables that control the movement of the character.
Row 7 adds an function that runs every frame and does the actions that are written into it.
Rows 8 - 12 adds things to the variables and are then added to the jetpack characters _x, _y and _rotation values, that then makes it controlable.
Row 13 checks if the jetpack man is not touching the “ground”. In next tutorial I will show how to make platforms for it.
Rows 14 - 20. The first thing thats on row 14 makes so it can fly vertically.
Then it checks if a key is pressed, which in this case are key 37 on row 15, and key 39 on row 18. So, what are the numbers? They are the keycodes for the keys. All keys on the keyboard has one. This picture will show you the keys that are usually used in games:

The keys that is watched if theyre pressed is the left and right arrow key. They make the jetpack square go to left and right.
And that means that it changes the rotationspeed and xspeed variables.
Rows 23 - 25 is what happens when the jetpack square hits the “ground”. xspeed var is decreased, _y is set to the right place and yspeed is set to 0.
Rows 27 - 29 is the thrust button action. The keycode thats 38 is for the up arrowkey. And if thats pressed, the character flies up.
Rows 30 - 32 looks if its flying upwards, and if it is, yspeed is decreased some extra. Else it would fly to mars in 3 seconds.



Your Ad Here

Thats all! If you couldnt get it to work, download the source from here.
If you liked this tutorial, you could play my, *cough* really good games here.

Share this:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • BarraPunto
  • co.mments
  • Fleck
  • Furl
  • feedmelinks
  • Live
  • Spurl
  • StumbleUpon

written by torskmunken \\ tags: , , ,

64 Responses to “Jetpack game - part 1”

  1. EagleVision Says:

    Very nice! :D

    I like it.

  2. Jerry Says:

    Great. Loved it thanks! Very helpful 4 stars!

  3. How To Make A JetPack Game « Says:

    [...] *COUGH* [...]

  4. hi Says:

    i followed every step in the bottom

    First off, draw a jetpack man or anything that you’re going to control. Select it and press f8. A window pops up. Name it whatever you want, and remember to put the registration point into the center of the movieclip. Make the instance name of it to “Fly” without quotes. Now you got everything there done. Now, click on the main timeline, which looks like a thin box that has a circle in it. Press f9 to bring up the actionscript-panel. Now type in the following code in it:
    [Copy to clipboard][-]
    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

    yspeed = 0;
    xspeed = 0;
    gravity = 0.2;
    rotationspeed = 0;
    power = 1;
    friction = 0.9;
    fly.onEnterFrame = function() {
    yspeed += gravity;
    xspeed *= friction;
    this._x += xspeed;
    rotationspeed *= friction;
    this._rotation = 0+rotationspeed;
    if (this._y<=400-this._height/2) {
    this._y += yspeed;
    if (Key.isDown(37)) {
    xspeed -= power;
    rotationspeed += power*xspeed/2;
    } else if (Key.isDown(39)) {
    xspeed += power;
    rotationspeed += power*xspeed/2;
    }
    } else {
    xspeed *= friction;
    yspeed = 0;
    this._y = 400-this._height/2;
    }
    if (Key.isDown(38)) {
    yspeed -= power;
    }
    if (yspeed<0) {
    yspeed *= friction;
    }
    };

    When you’ve done that, press ctrl+enter to see how it looks like. If you followed these easy steps right, the result should look a bit like this:

    but it still does not work

  5. tom Says:

    you fuker it dosent work evrey tut i go to it never works WHY

  6. Vince Says:

    add the actionscript code to the same frame as the jetpack or whatever you are wanting to move.

  7. lorik Says:

    it doesn’t work

  8. hanjy Says:

    “Make the instance name of it to “Fly”

    correction : it’s “fly”, not “Fly”

  9. billy Says:

    AAAAAAAAAAAAAAHHHHHHHHHHHHHHHHH!!!!!!!!!!!!!!!!!!!!!!!!!!!
    WHY DO YOU POST THINGS THAT DON’T WORK!?
    TEST YOUR STUFF BEFORE YOU PUT IT ON THE WEB!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  10. moff Says:

    It works just you are a noob and you can’t programming

  11. lola Says:

    of course its not going to work if you capitalized the F in fly. If you dont capitalize it…IT WILL WORK!

  12. lola Says:

    and u can also change the speed by changing the frame rate on the properties bar.

  13. a Says:

    What is this instances he talks abou…name the instances to Fly? wtf is he on about!

  14. hi Says:

    on the code do u have to put the numbers which is in front of the code?

  15. MystorySolver Says:

    If ur thinking sumthin like this:
    “What is this instances he talks abou…name the instances to Fly? wtf is he on about!”

    then you shouldnt be trying to do this tutorial…..or anything in action script…..except: stop(); but thats about the only thing u can use without making anything an instance.

  16. Steveo Says:

    Very nice, works like a charm even on older versions. On older versions *where function keys serve no purpose* when he refers to “F8″ he means the properties window, where not only the instance needs to be called “fly” but the specific one you place on the scene needs to have its name put to “fly” (took me a min to realise that) ;)

  17. MoffLol Says:

    Lol Moff u r such a fag. . .can u not type?????? Newb

  18. Stupid Saint Says:

    Amazing tutorial mate, thanks a billion

    and to all those fags that says it don’t work… SHUT THE HELL UP!!!!

    best of luck in the future

    Stupid Saint

  19. onlineflash Says:

    Nope at first i thought this is another not working tutorial that i have come across but i downloaded the source file and realised that i didnt set the instance name to fly, simple mistake of reading it, if it didnt work for you before ytou post read this, the instance name needs to be called “fly” no quotes and the actionscript needs to be in the frame itself, the tut does work

  20. Alex Says:

    Im new at this, whats an “instance name” u were refering to? if its the “Name” why make it confusing?

  21. torskmunken Says:

    If you dont understand how it should be, just download the source from here and see how it works

  22. Alex Says:

    nvm, the instance name is on the “properties” when F9 bring it up. You know, people that asks stupid questions only means that they are starting to learn this

  23. Alex Says:

    I learned where the instance name was located through another website btw..

  24. Alex Says:

    not through this source, a lot of source I had downloaded doesnt open with the program I use, so…

  25. uhhh Says:

    hey um what does it mean by instance name fly, wtf is a instance name i don’t get it.

  26. uhhh Says:

    where do i find the instance name the source didn’t help me at all

  27. uhhh Says:

    never mind i figured it, out you have to click your drawing and go to properties right under the action script bar then bam instance name and it does work !!

  28. Toastkage Says:

    Wow man this worked, and it was easy. Thanks a whole lot. At first it wasnt working because I was using actionscript 3 (hint hint) but i switched to 2, and it works! =)

  29. steve Says:

    hey tom it doesnt work cuz u suck at programing

  30. Chris Says:

    great tutorial…

    is there a way to make it move side to side instead of rotating when LEFT/RIGHT are pressed?…

  31. me Says:

    how do i change the instance name?

  32. torskmunken Says:

    You can see how to change the instance name in part 2 of these tutorials

  33. Jetpack game - part 2 | Aksel Kornesjö Says:

    [...] Jetpack game - part 1 [...]

  34. Gavin Says:

    Thanks …. awesome tutorial just what i was looking for. Easy to follow

  35. Great thin Says:

    Excelent!!!!!!!!!!!!!!!!!1

  36. Jet Says:

    Thanks a lot!
    It works. I didn’t name the instance properly… but then I clicked my “jetpack” and looked at its properties. I noticed, that the instance name is empty.

  37. Steven Says:

    I figured out the problem for everyone here…..

    WHEN CONVERTING INTO A MOVIE CLIP…….

    It gives you the option of converting into a movie clip, button, and graphics, and of course you would press movie clip in this situation but….

    A little to the right of those options is a thingy that says “registration” and to the right it shows 9 little circles (the upper left one is already darkened)

    MAKE SURE YOU PRESS THE CENTER DOT BEFORE MAKING IT A MOVIE CLIP!!

    Haha it took me like 15 minutes to figure out what the hell a registration point was (like said above in the tutorial) but I found once i centered the registration point while making it a movie clip, made the whole different and now I have a little jetpack man game :)

  38. Smit Says:

    Worked for me Thank u

  39. charlie Says:

    i am new aswell but i figured out the instance name out by my self very quickly so just have a look for it if you dont understand where it is and it does work. great tutorial

  40. Spyder Says:

    For all stupid man who post such thing that blah blah blah…the action script doesn’t work.

    First follow all the steps, it works!!! Only you are such foulish man.

    Thanks for the man who posted this tutorial.

  41. Cybershead Says:

    Just what i was looking for, And the code dose work and is very flexible to change. Thanks for posting it..

  42. gamedude Says:

    its gr8 it works for me….. I think som1s copied even the numbers wich is in the left… nyway its gr8, thnx for posting

  43. CombatCrayola Says:

    Hey, to all those who can’t make it work. When you click on the object, look in the properties menu and ensure the space in the top left corner, under , that says says . It will work.

    OOrah.

  44. homeless guy Says:

    great job works perfectly to my needs =)

  45. oran Says:

    this script is better
    -no instance name needed
    -goes in the in the movie clip
    -as 1.0 as well as 2.0
    -more simple

    onClipEvent (load) {
    yspeed = 0;
    xspeed = 0;
    gravity = 0.2;
    rotationspeed = 0;
    power = 1.1;
    friction = 0.9;
    }
    onClipEvent (enterFrame) {
    if (this._y<=400-this._height/2) {
    this._y += yspeed;
    if (Key.isDown(Key.LEFT)) {
    xspeed -= power;
    rotationspeed += power*xspeed/2;
    } else if (Key.isDown(Key.RIGHT)) {
    xspeed += power;
    rotationspeed += power*xspeed/2;
    }
    } else {
    xspeed *= friction;
    yspeed = 0;
    this._y = 400-this._height/2;
    }
    if (Key.isDown(Key.UP)) {
    yspeed -= power;
    }
    if (yspeed<0) {
    yspeed *= friction;
    }
    yspeed += gravity;
    xspeed *= friction;
    this._x += xspeed;
    rotationspeed *= friction;
    this._rotation = 0+rotationspeed;
    }

  46. bob Says:

    thank ypu Oran, since the guy who posted this tuturial did not work

  47. newflashuser Says:

    i use the first code but get these errors!

    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 7: Operator ‘=’ must be followed by an operand
    fly.onEnterFrame = function() {

    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 1: Statement must appear within on/onClipEvent handler
    yspeed = 5;

    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 2: Statement must appear within on/onClipEvent handler
    xspeed = 5;

    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 3: Statement must appear within on/onClipEvent handler
    gravity = 0.2;

    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 4: Statement must appear within on/onClipEvent handler
    rotationspeed = 0.5;

    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 5: Statement must appear within on/onClipEvent handler
    power = 1;

    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 6: Statement must appear within on/onClipEvent handler
    friction = 0.9;

    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 7: Statement must appear within on/onClipEvent handler
    fly.onEnterFrame = function() {
    What does it mean???

  48. Martti010 Says:

    You need Adobe Flash 8 Professional to do it! At least i did it and it worked for me:D

  49. Shaka M Says:

    First of all:
    No one here should be complaining about any of Aksel’s code unless they have actually learned the basics of Actionscript. ‘instance’ is just fancy talk for ‘object’

    2nd:
    “fly.onEnterFrame = function {}” does not work in ActionScript 2.0. this only works in ActionSCript 1.0. For those of you that say it doesnt work, this is the reason. Flash 8, by default, uses Actionscript 2.0 unless you change it.

    instead of calling a onClipEvent thru a new function. you can call it itself. :
    onClipEvent(enterFrame){}

    I hope this clears up all the commotion. Best of luck to all; Beginners and Advanced!

  50. Shaka M Says:

    Also. If you are using Flash CS3. Change your ActionScript library that you are using to AS 2.0. Make sure the check it is changed during your documents export/publish stage. If you dont know how to do this. Read the Adobe Flash Live Docs. Everything isn’t going to be spoon fed. You find the Live Doc by clicking Help in the Menu at top of screen.

  51. Shaka M Says:

    and Very nice tutorial Aksel. May not work for some but, it is very well explained. Use comments (a suggestion). Might make it simpiler.

  52. David- Says:

    onClipEvent (load) {
    yspeed = 0;
    xspeed = 0;
    gravity = 0.2;
    rotationspeed = 0;
    power = 1.1;
    friction = 0.9;
    }
    onClipEvent (enterFrame) {
    if (this._y<=400-this._height/2) {
    this._y += yspeed;
    if (Key.isDown(Key.LEFT)) {
    xspeed -= power;
    rotationspeed += power*xspeed/2;
    } else if (Key.isDown(Key.RIGHT)) {
    xspeed += power;
    rotationspeed += power*xspeed/2;
    }
    } else {
    xspeed *= friction;
    yspeed = 0;
    this._y = 400-this._height/2;
    }
    if (Key.isDown(Key.UP)) {
    yspeed -= power;
    }
    if (yspeed<0) {
    yspeed *= friction;
    }
    yspeed += gravity;
    xspeed *= friction;
    this._x += xspeed;
    rotationspeed *= friction;
    this._rotation = 0+rotationspeed;
    }

    this code found!

  53. Reid M Says:

    Great tut. I am still trying to figure part 2 though.

  54. Jetpack game - Part 3 | Aksel Kornesjö Says:

    [...] Jetpack game - Part 3 [...]

  55. Garry Says:

    great works fine, :D thanx

  56. kenny Says:

    i’m kind of a noob at this ation script stuff and i have the trail for cs4 it uses ation script 3.0 but it will let u use 2.0 it tells me the first 7 lines have errors and they say “satement must appear within on/onClipEvent handler” thats what it says for the first seven lines and how do you name an instance ty

  57. kenny Says:

    wait i did’t type it right i got it

  58. Rory Says:

    I have the instance name as fly and I have the registration point in the middle. I copied the script into the action script box and it is set to movie clip and i hit ctrl and enter but it still doesnt work. Any help?

  59. fahad Says:

    i like this tutorial..can some one post..how we can impliment collision and other physics in flash…

  60. supportfth Says:

    for the idiots which can’t make this code work

    im 12 years old, and i figured out my first day rpgramming at flash this:

    “the ones which can’t think, can’t program”

    so, you shall all go to another website and learn it there, becuase, if you didn’t undestand this tut, is because you have a serious mind problem. maybe ‘down’.

    or you could just try follow the tutoril again and paste dthe code on the ‘main timeine’ as he says. or put the instance of ‘lfly’ as he also says or download the source as he says!

  61. lars Says:

    It doesnt work at me to but i think for the people where it doesnt works we maybe have a other flas player;) i got so many messages that its wrong on my flash thati think i have an other version;)

  62. Joe Says:

    Try pasting the script in the first keyframe

  63. dob Says:

    great tutorial worked on the old flash on the pc`s at school but didnt work on the new version i have at home

  64. Xinga Says:

    Hey guys!

    Be sure to put the code in the KEYFRAME - not the object :) I made that misstake at first ;)

    Or if you follow David’s Code - That one is applied to the object

    have fun

Leave a Reply