A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Multiple Key.isDown issues on one MC animation

Threaded View

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    23

    Multiple Key.isDown issues on one MC animation

    I'm sure this has been asked a thousand times, but I can not find it in the search field (or I'm using the wrong verbage), so I thought I'd throw this, hopefully, simple question out there.

    I'm designing a simple platformer and everything works fine. Problem is, the actual MC animation. My jump and control functions are as follows:

    Actionscript Code:
    function jump () {
        if (hero.hitTest(ground)) {
            air = false;
        } else {
            air = true;
        }if (air == true) {
            hero._y += gravity;
            hero.gotoAndStop(3);
    //frame 3 is the jumping animation     
        } else {
            jumpcount = 0;
            jumpSpeed = 20;
        }if (jumpcount > maxjump) {
            jumpSpeed -= 1;
        }
    }
    ]function controls() {
        var KeyPressed = false;
        if (Key.isDown(Key.RIGHT)) {
            hero._x+=moveSpeed, hero._xscale = 100;
            hero.gotoAndStop(2);
    //frame 2 is the walking animation in hero MC
            KeyPressed = true
        } else if (Key.isDown(Key.LEFT)) {
            hero._x-=moveSpeed, hero._xscale = -100;
            hero.gotoAndStop(2);
    //frame 2 is the walking animation in hero MC
            KeyPressed = true;
        }  
        if (Key.isDown(Key.SPACE)) {
            hero._y -= jumpSpeed;
            jumpcount += 1;
            KeyPressed = true;
        }
       
       
       
        if (!KeyPressed) {
            hero.gotoAndStop(1);
        }

    Again everything works fine....except when TWO keys are used together. IE: When I walk left of right by itself, it plays the walking animation. Likewise, when I just jump, it plays the jumping animation. But if I press, say, right AND jump at the same time, my hero will jump up and to the right, but his animation stays locked on the 1st frame of the jump animation. You can really notice it when I jump straight up initially, then suddenly press a left or right mid-air...you watch the jump animation stop.

    I'm sure this is VERY simple, but I've tried several different things...even stuff like:
    Actionscript Code:
    if (Key.isDown(Key.SPACE) and Key.isDown(Key.LEFT)) {
            hero.gotoAndStop(3);

    in the controls function, but no luck.
    Last edited by bearsfan1978; 07-27-2011 at 09:36 PM.

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