A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: Running help.

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    24

    Running help.

    How do you make your character have a different animation when you hold shift? on what I currently have its okay... but when I hold shift it looks like he just walks faster, I want a running animation, can you give me a small tut on how you get your character to have a running animation instead of him just walking faster when I press shift?

    BTW this is my action script

    onClipEvent (load) {
    var speed:Number = 0;
    var walk:Number = 6;
    var run:Number = 11;
    var grav:Number = 0;
    var falling:Number = 0;
    var jumped:Boolean = false;
    var jumpHeight:Number = 21;
    var touchingGround:Boolean = false;
    var scale:Number = _xscale;
    var doorOpened:Boolean = false;
    var attacked:Boolean = false;
    }
    onClipEvent (enterFrame) {
    if (!touchingGround) {
    grav++;
    this._y += grav;
    } else {
    grav = 0;
    }
    if (_root.ground.hitTest(_x, _y, true)) {
    touchingGround = true;
    } else {
    touchingGround = false;
    }
    if (!attacked) {
    if (Key.isDown(Key.LEFT)) {
    _x -= speed;
    this.gotoAndStop(2);
    _xscale = -scale;
    }
    if (Key.isDown(Key.RIGHT)) {
    _x += speed;
    this.gotoAndStop(2);
    _xscale = +scale;
    }
    if (Key.isDown(Key.SHIFT)) {
    speed = run;
    } else {
    speed = walk;
    }
    }
    }
    onClipEvent (enterFrame) {
    if (!attacked) {
    if (jumped) {
    falling += 0.5;
    _y += falling;
    if (touchingGround) {
    jumped = false;
    }
    } else {
    if (Key.isDown(Key.UP)) {
    jumped = true;
    falling = -jumpHeight;
    this.gotoAndStop(3);
    }
    }
    }
    if ((Key.isDown(Key.UP)) and (Key.isDown(Key.LEFT))) {
    this.gotoAndStop(3);
    }
    if ((Key.isDown(Key.UP)) and (Key.isDown(Key.RIGHT))) {
    this.gotoAndStop(3);
    }
    if ((!Key.isDown(Key.UP)) and (!touchingGround)) {
    this.gotoAndStop(3);
    } else if ((Key.isDown(Key.UP)) and (!touchingGround)) {
    this.gotoAndStop(3);
    }
    if ((_currentframe == 3) and (touchingGround)) {
    gotoAndStop(1);
    }
    }
    onClipEvent (keyUp) {
    if (!attacked) {
    gotoAndStop(1);
    }
    }
    onClipEvent (enterFrame) {
    if ((this.hitTest(_root.door)) and (!doorOpened)) {
    this._x -= speed;
    }
    if ((this.hitTest(_root.door)) and (Key.isDown(Key.SPACE)) and (_root.keys>=1)) {
    _root.door.gotoAndStop(2);
    doorOpened = true;
    _root.keys -= 1;
    }
    if (this.hitTest(_root.wall)) {
    this._x -= speed;
    }
    if (this.hitTest(_root.key)) {
    _root.keys += 1;
    unloadMovie(_root.key);
    }
    if (_root.keys<0) {
    _root.keys = 0;
    }
    }
    onClipEvent (enterFrame) {
    if (Key.isDown(65)){
    attacked = true;
    this.gotoAndStop(4);
    if(this.hitTest(_root.enemy)) {
    _root.enemy.unloadMovie();
    }
    }
    }

  2. #2
    Junior Member
    Join Date
    Feb 2012
    Posts
    24
    oh btw, I am using flash 8

  3. #3
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    is that NOT your code above?

    doesnt it change the 'look' of the clip/character right now? (depending on the action?)

  4. #4
    Junior Member
    Join Date
    Feb 2012
    Posts
    24
    Quote Originally Posted by whispers View Post
    is that NOT your code above?

    doesnt it change the 'look' of the clip/character right now? (depending on the action?)
    Okay, listen I just want it when I hold shift for my Character to do a running animation, so help. and Yes that is the script I am using.

  5. #5
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    you didnt answer the question(s) unfortunately..

    if this IS your code.. then I can easily (or you should know) where to modify..

    and if it does change 'states' to something depending on the action tells me I am reading the code right or wrong.

  6. #6
    Junior Member
    Join Date
    Feb 2012
    Posts
    24
    Quote Originally Posted by whispers View Post
    you didnt answer the question(s) unfortunately..

    if this IS your code.. then I can easily (or you should know) where to modify..

    and if it does change 'states' to something depending on the action tells me I am reading the code right or wrong.
    Yes it is my code.
    Now show me where to modify

  7. #7
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    ...Character to do a running animation, so help
    Now show me where to modify
    just give me step by step instructions please
    are you forcing him to help you? You know, there are nicer ways to ask for help people, otherwise with your attitude, they'll just get pissed off and lose the desire to help you at all

    and when people help you and you only ask for step-by-step instructions, you're not going to learn anything from that. Read tutorials on the internet, there are tons, and if you don't understand something, kindly post your question here. No one just wants to give you codes if you're not interested in learning by yourself at all!
    Last edited by Nig 13; 02-02-2012 at 07:09 AM.
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  8. #8
    Junior Member
    Join Date
    Feb 2012
    Posts
    24
    Quote Originally Posted by Nig 13 View Post
    are you forcing him to help you? You know, there are nicer ways to ask for help people, otherwise with your attitude, they'll just get pissed off and lose the desire to help you at all

    and when people help you and you only ask for step-by-step instructions, you're not going to learn anything from that. Read tutorials on the internet, there are tons, and if you don't understand something, kindly post your question here. No one just wants to give you codes if you're not interested in learning by yourself at all!
    I have tried looking online, NO ONE IS HELPING ME, please help me, please!!!

  9. #9
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Be glad I actually took the courtesy of fixing this, 'cause somehow, I felt a bit bad for you:

    Actionscript Code:
    onClipEvent (load) {
        var speed:Number = 0;
        var walk:Number = 6;
        var run:Number = 11;
        var grav:Number = 0;
        var falling:Number = 0;
        var jumped:Boolean = false;
        var jumpHeight:Number = 21;
        var touchingGround:Boolean = false;
        var scale:Number = _xscale;
        var doorOpened:Boolean = false;
        var attacked:Boolean = false;
    }
    onClipEvent (enterFrame) {
        if (!touchingGround) {
            grav++;
            this._y += grav;
        } else {
            grav = 0;
        }
        if (_root.ground.hitTest(_x, _y, true)) {
            touchingGround = true;
        } else {
            touchingGround = false;
        }
        if (!attacked) {
            if (Key.isDown(Key.LEFT)) {
                _x -= speed;
                if(speed == walk){
                    this.gotoAndStop(2);
                } else {
                    this.gotoAndStop(5); // running animation
                }
                _xscale = -scale;
            }
            if (Key.isDown(Key.RIGHT)) {
                _x += speed;
                if(speed == walk){
                    this.gotoAndStop(2);
                } else {
                    this.gotoAndStop(5); // running animation
                }
                _xscale = +scale;
            }
            if (Key.isDown(Key.SHIFT)) {
                speed = run;
            } else {
                speed = walk;
            }
        }
    }
    onClipEvent (enterFrame) {
        if (!attacked) {
            if (jumped) {
                falling += 0.5;
                _y += falling;
                if (touchingGround) {
                    jumped = false;
                }
            } else {
                if (Key.isDown(Key.UP)) {
                    jumped = true;
                    falling = -jumpHeight;
                    this.gotoAndStop(3);
                }
            }
        }
        if ((Key.isDown(Key.UP)) and (Key.isDown(Key.LEFT))) {
            this.gotoAndStop(3);
        }
        if ((Key.isDown(Key.UP)) and (Key.isDown(Key.RIGHT))) {
            this.gotoAndStop(3);
        }
        if ((!Key.isDown(Key.UP)) and (!touchingGround)) {
            this.gotoAndStop(3);
        } else if ((Key.isDown(Key.UP)) and (!touchingGround)) {
            this.gotoAndStop(3);
        }
        if ((_currentframe == 3) and (touchingGround)) {
            gotoAndStop(1);
        }
    }
    onClipEvent (keyUp) {
        if (!attacked) {
            gotoAndStop(1);
        }
    }
    onClipEvent (enterFrame) {
        if ((this.hitTest(_root.door)) and (!doorOpened)) {
            this._x -= speed;
        }
        if ((this.hitTest(_root.door)) and (Key.isDown(Key.SPACE)) and (_root.keys>=1)) {
            _root.door.gotoAndStop(2);
            doorOpened = true;
            _root.keys -= 1;
        }
        if (this.hitTest(_root.wall)) {
            this._x -= speed;
        }
        if (this.hitTest(_root.key)) {
            _root.keys += 1;
            unloadMovie(_root.key);
        }
        if (_root.keys<0) {
            _root.keys = 0;
        }
    }
    onClipEvent (enterFrame) {
        if (Key.isDown(65)){
            attacked = true;
            this.gotoAndStop(4);
            if(this.hitTest(_root.enemy)) {
                _root.enemy.unloadMovie();
            }
        } else {
            attacked = false;
        }
    }

    Frame 5 is for the running animation, just add another frame inside your movieclip on Frame 5 with the running and hopefully it should work
    Last edited by Nig 13; 02-04-2012 at 08:39 AM.
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  10. #10
    Junior Member
    Join Date
    Feb 2012
    Posts
    24

    Thumbs up

    Quote Originally Posted by Nig 13 View Post
    Be glad I actually took the courtesy of fixing this, 'cause somehow, I felt a bit bad for you:

    Actionscript Code:
    onClipEvent (load) {
        var speed:Number = 0;
        var walk:Number = 6;
        var run:Number = 11;
        var grav:Number = 0;
        var falling:Number = 0;
        var jumped:Boolean = false;
        var jumpHeight:Number = 21;
        var touchingGround:Boolean = false;
        var scale:Number = _xscale;
        var doorOpened:Boolean = false;
        var attacked:Boolean = false;
    }
    onClipEvent (enterFrame) {
        if (!touchingGround) {
            grav++;
            this._y += grav;
        } else {
            grav = 0;
        }
        if (_root.ground.hitTest(_x, _y, true)) {
            touchingGround = true;
        } else {
            touchingGround = false;
        }
        if (!attacked) {
            if (Key.isDown(Key.LEFT)) {
                _x -= speed;
                if(speed == walk){
                    this.gotoAndStop(2);
                } else {
                    this.gotoAndStop(5); // running animation
                }
                _xscale = -scale;
            }
            if (Key.isDown(Key.RIGHT)) {
                _x += speed;
                if(speed == walk){
                    this.gotoAndStop(2);
                } else {
                    this.gotoAndStop(5); // running animation
                }
                _xscale = +scale;
            }
            if (Key.isDown(Key.SHIFT)) {
                speed = run;
            } else {
                speed = walk;
            }
        }
    }
    onClipEvent (enterFrame) {
        if (!attacked) {
            if (jumped) {
                falling += 0.5;
                _y += falling;
                if (touchingGround) {
                    jumped = false;
                }
            } else {
                if (Key.isDown(Key.UP)) {
                    jumped = true;
                    falling = -jumpHeight;
                    this.gotoAndStop(3);
                }
            }
        }
        if ((Key.isDown(Key.UP)) and (Key.isDown(Key.LEFT))) {
            this.gotoAndStop(3);
        }
        if ((Key.isDown(Key.UP)) and (Key.isDown(Key.RIGHT))) {
            this.gotoAndStop(3);
        }
        if ((!Key.isDown(Key.UP)) and (!touchingGround)) {
            this.gotoAndStop(3);
        } else if ((Key.isDown(Key.UP)) and (!touchingGround)) {
            this.gotoAndStop(3);
        }
        if ((_currentframe == 3) and (touchingGround)) {
            gotoAndStop(1);
        }
    }
    onClipEvent (keyUp) {
        if (!attacked) {
            gotoAndStop(1);
        }
    }
    onClipEvent (enterFrame) {
        if ((this.hitTest(_root.door)) and (!doorOpened)) {
            this._x -= speed;
        }
        if ((this.hitTest(_root.door)) and (Key.isDown(Key.SPACE)) and (_root.keys>=1)) {
            _root.door.gotoAndStop(2);
            doorOpened = true;
            _root.keys -= 1;
        }
        if (this.hitTest(_root.wall)) {
            this._x -= speed;
        }
        if (this.hitTest(_root.key)) {
            _root.keys += 1;
            unloadMovie(_root.key);
        }
        if (_root.keys<0) {
            _root.keys = 0;
        }
    }
    onClipEvent (enterFrame) {
        if (Key.isDown(65)){
            attacked = true;
            this.gotoAndStop(4);
            if(this.hitTest(_root.enemy)) {
                _root.enemy.unloadMovie();
            }
        } else {
            attacked = false;
        }
    }

    Frame 5 is for the running animation, just add another frame inside your movieclip on Frame 5 with the running and hopefully it should work
    THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU!!!!!!!!!!!! oh my god thank you so much! You are my best friend! you are so ****ing smart, everyone else was like "your an ******* I ain't helping you!" when it was just they were to stupid to help, but you are so smart and you MADE MY DAY THANK YOU!!!!!!!!!!

  11. #11
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Well, thanks a lot

    tips for you, you should ask nicely to people, like in your previous post when you were so desperate, and people will actually help you
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  12. #12
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    lol ^

  13. #13
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    w00t, Basses6 joined the convo :3
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  14. #14
    Junior Member
    Join Date
    Feb 2012
    Posts
    24
    Quote Originally Posted by Nig 13 View Post
    w00t, Basses6 joined the convo :3
    Nig maybe you can help me With sound when I pickup money in my platformer?

    I got the scoring and everything good, I just want a sound to play when I pick up my money in flash.

    Please help?

  15. #15
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    What's the code for picking up money? If it's something like this:

    Actionscript Code:
    onClipEvent(enterFrame){
         if(this.hitTest(_root.player)){
              unloadMovie(this);
         }
    }

    then import your sound file into Flash, in the Library, find it there (CTRL+L), right-click it, press Properties, show Advanced, in the Identifier field, type in, coinSound, and press OK. Use this code after, unloadMovie(this); :

    Actionscript Code:
    sound = new Sound();
    sound.attachSound("coinSound");
    sound.start(0, 1);

    making the whole code look something like this:


    Actionscript Code:
    onClipEvent(enterFrame){
         if(this.hitTest(_root.player)){
              unloadMovie(this);
              sound = new Sound();
              sound.attachSound("coinSound");
              sound.start(0, 1);
         }
    }
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

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