I noticed every site was saying this.x and this.y, but I found out that this._x and this._y worked better for me. (For some odd unknown reason because I never took ActionScript classes, but I'm taking an Adobe Flash CS3 class and it included a few things like stop(); and gotoAndPlay();)
So anyways, here's the code:
onClipEvent(load) {
var jumping = false;
var jumpwait=0;
var fallwait=0;
var yPos = this._y;
}
onClipEvent(enterFrame) {
if(jumpwait >= 5)
jumping=true;
if(jumpwait < 5&&jumpwait!=0)
jumpwait+=1;
if(fallwait >=5)
jumping=false;
this._y=366;
if(fallwait < 5&&fallwait!=0)
fallwait+=1;
if(jumping == true){
jumpwait=0
this._y += jumprate;
jumprate --;
fallwait=1
jumping = false;
this.gotoAndPlay("stand");
}
// if (_root.jumping == false) {
if (this.jumping == false) {
if (Key.isDown(Key.UP)) {
this.gotoAndPlay("jump");
// jumping = true;
jumprate = 40;
jumpwait=1
this._y -= jumprate;
}
}
}
I'm basically trying to make it to where they jump smoothly instead of just flying up 40 pixels and down under the stage (Under where the Movie Clip Symbol originally was) then back to the original place it was in about the same time as sleep(3) in DM (Without changing the FPS var)
Is there any way I can do this? If you just paste in code, please try to explain it using the // note on each line or break the code down for me so I can understand it.
I am not very skilled in ActionScript and as I said, all I've learned in the class is mostly Movie Control (stop();, play();, gotoAndPlay();, gotoAndStop();, etc) although I have learned things like this from simply googling it. (Which was what I originally did for this code.)
Basically, when they press UP it marks them as jumping and gives them a y-velocity. Then while jumping, it alters that velocity by the amount of gravity, until it actually starts moving in the opposite direction. Then it falls back to the "ground" (passes its initial y-position) and we reset them. Keep in mind that _y=0 is at the top of the screen, and you have to increase _y to move "down" (that always screws me up).
I assume you already have stop(); codes in your movieclip timeline for the end of the jump sequence/standing sequence. If they're just one frame, you might want to use gotoAndStop(); instead of gotoAndPlay();
Also, it's _x in AS2 and just x in AS3, so you might have been reading an AS3 tutorial.
I tried to comment it as clearly as possible, but let me know if you want further explanation.