A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: Running help.

Hybrid View

  1. #1
    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

  2. #2
    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!!!!!!!!!!

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