A Flash Developer Resource Site

+ Reply to Thread
Results 1 to 1 of 1
  1. #1
    Member
    Join Date
    Dec 2003
    Posts
    36

    [F8] Hero stuck in walking animation after jumping.

    I didn't really do any animating. It's just a ball and a square (ball is hero, square is enemy) and the ball changing colors is the walking animation. But whenever I hold left or right and jump at the same time when the ball lands on the ground it stays in the walking animation instead of the standing animation. So the ball doesn't move but its "walking". I've tried changing the code around but nothing seems to change it. I appreciate any help in advance.

    //sets all variables at the beggining of the game
    onClipEvent (load) {
    vel_y = 0;
    jumping = true;
    speed = 5;
    }
    //tells Hero to move left, right, and jump when the appropriate key is pressed.
    onClipEvent (enterFrame) {
    if (Key.isDown(Key.LEFT)) {
    _x -= speed;
    }
    if (Key.isDown(Key.RIGHT)) {
    _x += speed;
    }
    if (Key.isDown(Key.SPACE) && !jumping) {
    vel_y = 35;
    jumping = true;
    }
    // checks if the Hero is jumping, if it is the vel_y should continually be subracted by 2.5.
    // if it's being subtracted by more than 10, to keep it at 10. That way it doesn't fall too fast.
    if (this.jumping) {
    vel_y -= 2.5;
    if (vel_y<=-10) {
    vel_y = -10;
    }
    //states that the hero's y position should be affected by the vel_y
    this._y -= vel_y;
    }
    //if the hero touches the floor, then it's not jumping anymore
    if (this.hitTest(_root.floor)) {
    vel_y = 0;
    jumping = false;
    _y = _root.floor._y
    }
    }
    // says that hero is starting out falling. But if he hits the floor, he's not falling anymore.
    onClipEvent (enterFrame) {
    fall = true;
    if (this.hitTest(_root.floor)) {
    fall = false;
    vel_y = 0;
    grav = 0;
    }
    if (fall) {
    grav += vel;
    vel += 1;
    if (grav>=10) {
    grav = 10;
    }
    this._y += grav;
    }
    }
    //animation for jumping up
    onClipEvent (enterFrame) {
    if (jumping == true)
    _root.hero.gotoAndStop("jump");
    }
    //tells hero to go back to standing if it's not jumping
    onClipEvent (enterFrame) {
    if (jumping == false)
    _root.hero.gotoAndStop("stand");
    }
    // if it's in the air and it's starting to fall, go to the animation
    onClipEvent (enterFrame) {
    if (fall == true && vel_y<=5)
    _root.hero.gotoAndStop("fall");
    }
    onClipEvent (enterFrame) {
    if (fall == false)
    _root.hero.gotoAndStop("stand");
    }
    //says on pressing the arrow keys it flips the hero to face the right way
    onClipEvent (enterFrame) {
    if (Key.isDown (Key.RIGHT)) {this._xscale = 100
    }
    }
    onClipEvent (enterFrame) {
    if (Key.isDown (Key.LEFT)) {this._xscale = -100;
    }
    }
    Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts




Click Here to Expand Forum to Full Width


HTML5 Development Center