Skip navigation
xmasgame
Currently Being Moderated

[AS2] Character movement

Apr 21, 2012 12:55 PM

Okey my character got this script: (its lots more but yeah.. this is the trouble code).

 

Frame 1 = character stand still

Frame 2 = character (MC) - movement

Frame 3 = character (MC) - Jump movement

 

It works fine, when I press UP, he jumpes and play frame 3.

When i press left and right it plays frame 2.

When I press .. nothing, frame 1 is played.

That correct!

BUT when i press .. left + up, or right + up, it will play frame 1.

Any idea how i can make it play Frame 3 (jump) even if I press two buttons at the same time? Would be awesome if someone knew it.

 

onClipEvent (enterFrame) {

if (Key.isDown(Key.RIGHT)) {

_root.player.gotoAndStop(2);

}

if (Key.isDown(Key.LEFT)) {

_root.player.gotoAndStop(2);

}

if (Key.isDown(Key.UP)) {

_root.player.gotoAndStop(3);

}

if (!Key.isDown(Key.LEFT) and (!Key.isDown(Key.RIGHT) and (!Key.isDown(Key.UP)))) {

this.gotoAndStop(1);

}

}

 
Replies
  • Currently Being Moderated
    Apr 21, 2012 2:17 PM   in reply to xmasgame

    onClipEvent (enterFrame) {

              if (Key.isDown(Key.UP)) {

     

     

                        if (Key.isDown(Key.LEFT)) {

               do something

     

                        } else if (Key.isDown(Key.RIGHT)) {

                do something

     

                        }

                        _root.player.gotoAndStop(3);

              } else {

                        if (Key.isDown(Key.RIGHT)) {

                                  _root.player.gotoAndStop(2);

                        } else if (Key.isDown(Key.LEFT)) {

                                  _root.player.gotoAndStop(2);

                        } else {

                                  this.gotoAndStop(1);

                        }

              }

    }

     

    This should solve that. but I can't guarantee if it will cause any problem for your game.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 21, 2012 5:00 PM   in reply to xmasgame

    Just use the and opperator: &&

     

    so something like:

    if (Key.isDown(Key.LEFT) && Key.isDown(Key.UP) ) {

    _root.player.gotoAndStop(3);

    }

    if (Key.isDown(Key.RIGHT) && Key.isDown(Key.UP) ) {

    _root.player.gotoAndStop(3);

    }


     
    |
    Mark as:
  • Currently Being Moderated
    Apr 21, 2012 7:41 PM   in reply to xmasgame

    the do something is not surpose to be in the code, it means the place for you to add your actions inside. like setting a different movement speed where it's nested without having to assign the jumping again.  prodigal master's code will work as well. depending on what way you want to script it.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 22, 2012 4:57 AM   in reply to xmasgame

    Maybe that is because it is repeatedly goto and stopping on frame (3) due to the key's being down. Maybe use a boolean variable e.g. isJumping = false; and when the jump animationbegins make it isJumping = true; and finally when the animation ends make isJumping = false; and therefore in the code use && in the if statement with isJumping == false

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 22, 2012 8:59 AM   in reply to xmasgame

    A boolean is just the name for a variable with two states. In flash this is true and false.

    Just try what I said.

     

    You know how to make a variable right?

    var isJumping:Boolean = false;

    (on the main timeline).

     

    So, there are 3 frames in the player movieclip, and animation movieclips inside those frames of the player?

     

    Did you try WitchXHunters' code without the 'do something' bit?

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 24, 2012 7:33 AM   in reply to xmasgame

    you're welcome .^^

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points