First off I'd like to thank Rystic for this great jump engine! This has helped me improve my AS skills and understand platformers better. Great job!
The following is a Combination of the Jump code as well as a few others from this thread about making the "Hero" animatel left and right movement. This is only the code for the character
For the sake of arguement I'll recap some of what's already been said.
1) Make a Movie Clip (MC). If you don't know how to do this, read a less advanced tutorial.
2) Edit the clip. Make 4 KeyFrames and add stop(); to each frame. Do the Following
FRAME 1: Facing Right
FRAME 2: Moving Right
FRAME 3: Facing Left
FRAME 4: Facing Left
FRAME 5: Attacking Right
FRAME 6: Attacking Left
FRAME 7: Jumping (flip)
3) Double click untill you're in Scene 1 again (main window).
4) Now Click on your charecter. In the ActionsPanel, paste the following...
onClipEvent (load) {
fall = false;
_name = "circle";
jump = 0;
speed = 20;
jumpheight = 20;
maxfall = -20;
}
onClipEvent (enterFrame) {
xmin = getBounds(_root).xMin;
xmax = getBounds(_root).xMax;
ymin = getBounds(_root).yMin;
ymax = getBounds(_root).yMax;
if (Key.isDown(Key.SPACE) && fall == false && jump == undefined) {
fall = true;
jump = jumpheight;
}
if (jump<>undefined) {
if (jump>maxfall) {
jump--;
}
_y -= jump;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x -= speed;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
}
}onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
if (Key.isDown(17)) {
_root.moving_2="left"
} else {
_root.moving_2=""
}
_root.moving="left"
if(fall == true) {
if(_root.moving_2=="left") {
_root.circle.gotoAndStop(1)
} else {
_root.circle.gotoAndStop(7)
}
} else {
if (Key.isDown(90)) {
if(_root.moving=="right") {
if(_root.moving_2=="left") {
_root.circle.gotoAndStop(5)
} else {
_root.circle.gotoAndStop(6)
}
}
if(_root.moving=="left") {
_root.circle.gotoAndStop(6)
}
}
if(_root.moving_2 == "left") {
_root.circle.gotoAndStop(2)
} else {
_root.circle.gotoAndStop(4)
}
}
} else {
if(_root.moving=="left") {
if (Key.isDown(90)) {
if(_root.moving_2=="left") {
_root.circle.gotoAndStop(5)
} else {
_root.circle.gotoAndStop(6)
}
} else {
if(_root.moving_2=="left") {
_root.circle.gotoAndStop(1)
} else {
_root.circle.gotoAndStop(3)
}}
}
if (Key.isDown(Key.RIGHT)) {
if (Key.isDown(17)) {
_root.moving_2="right"
} else {
_root.moving_2=""
}
_root.moving="right"
if(fall == true) {
if(_root.moving_2=="right") {
_root.circle.gotoAndStop(3)
} else {
_root.circle.gotoAndStop(7)
}} else {
if(_root.moving_2=="right") {
_root.circle.gotoAndStop(4)
} else {
_root.circle.gotoAndStop(2)
}}} else {
if(_root.moving=="right") {
if (Key.isDown(90)) {
if(_root.moving_2=="right") {
_root.circle.gotoAndStop(6)
} else {
_root.circle.gotoAndStop(5)
}} else {
if(_root.moving_2=="right") {
_root.circle.gotoAndStop(3)
} else {
_root.circle.gotoAndStop(1)
}}}}}}
This is basically just a couple different people's suggestions in this thread. I also added a backflip animation to the jump. Although it may not be the best, it does the trick. I tried to clean it up, but this is all I could do to keep it from getting errors. I lack advanced AS skills hehe.
Also, if you're having problems with "not jumping" do what Rystic said and make sure you align your charecter in the CENTER of the crosshairs (while editing). Also, you may have to adjust >> maxfall = -84; << since my MC was smaller , I had to tweak mine a little, but it works perfect!
Thanks again Rystic!