dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Punch Problem

  1. #1
    Member
    Join Date
    Jun 2009
    Posts
    30

    Punch Problem

    hy

    i am trying to make a character punch and kick, i have got them to work e.g. when you press 1 the character punches and when 2 is pressed then the character kicks, but the problem i have is that when you are tapping both keys (which i presume most players will) the two frames skip between each other and dont actually finish playing the animation, so what i want help on is that when 1 is pressed, another keycombo can not be pressed while the animation is still rolling, i.e. pressing 2 is cancelled out. try button bashing between 1 and 2 and you shud know what i mean...heres my code so far

    PHP Code:
        up 38;
        
    down 40;
        
    backward 37;
        
    forward 39;
        
    punchcombo 49// keyboard 1 for punch combo
        
    kick50// keyboard 2 for kick 
        
    jumpkey 51;// keyboard 3 for jump


    function attacks() {
        

    if (
    Key.isDown(punchcombo)) {
            
    hero.gotoAndStop("punch");

    }

    if (
    Key.isDown(kick)) {
        
    hero.gotoAndStop("kick")
    }
    }


    //------------------------
    onEnterFrame = function () {
        
    //trace(Key.getCode());
        
    attacks();
    }; 
    http://www.sendspace.com/file/uxcvvy - .fla file
    http://www.swfupload.com/view/102287.htm - .swf file

    thank you

  2. #2
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    I know that putting code inside movieclips is a bad habit, but for the sake of simplicity, that's what I'll suggest you do. At the beginning of the punch animation, place some code to raise a flag:
    _root.inProgress = true;

    And at the end, set that flag to false. Do this for every animation you have.

    Then, before calling the hero.gotoAndStop("attack"); or whatever, just check to see if inProgress is true. If it is, then don't let the player do another attack. Otherwise, let him.
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  3. #3
    Zombie Coder EvilKris's Avatar
    Join Date
    Jun 2006
    Location
    Fukuoka, Japan.
    Posts
    796
    I think dropping one or two lines of code in movieclips isnt so bad if it saves you a ton of work trying to achieve the same effect on the main timeline.

    go into your hero movieclip and into every attacking animation. Click on the end frame of each and put in:

    hero.attack=false;

    Then revise your code as below-



    up = 38;
    down = 40;
    backward = 37;
    forward = 39;
    punchcombo = 49; // keyboard 1 for punch combo
    kick= 50; // keyboard 2 for kick
    jumpkey = 51;// keyboard 3 for jump


    function attacks() {
    if(hero.attack)
    return;

    if (Key.isDown(punchcombo)) {
    hero.gotoAndStop("punch");
    hero.attack=true;
    }

    if (Key.isDown(kick)) {
    hero.gotoAndStop("kick");
    hero.attack=true;
    }
    }


    //------------------------
    onEnterFrame = function () {
    //trace(Key.getCode());
    attacks();
    };


    p.s. check out the SplatterHouse beat-em up tutorials. The guy who wrote them is a genius, lol.

  4. #4
    Member
    Join Date
    Jun 2009
    Posts
    30
    i now have a new problem, ive tried to put a movement code in, but when i try to press 1 and 2, nothing happens, heres my new code now...

    PHP Code:
    walkspeed 5;
    walk true;

    up 38;
    down 40;
    backward 37;
    forward 39;
    punchcombo 49// keyboard 1 for punch combo
    kick50// keyboard 2 for kick 
    jumpkey 51;// keyboard 3 for jump


    function movement () {
        
    moving false;

        if(
    Key.isDown(Key.RIGHT)){
        
    hero._x += walkspeed;
        
    hero._xscale 100;
        
    hero.gotoAndStop("walk");
        
    moving true;
        }
            
        if(
    Key.isDown(Key.LEFT)){
        
    hero._x -= walkspeed;
        
    hero._xscale = -100;
        
    hero.gotoAndStop("walk");
        
    moving true;
        }

        if(
    Key.isDown(Key.UP)){
        
    hero._y -= walkspeed;
        
    hero.gotoAndStop("walk");
        
    moving true;
        }

        if(
    Key.isDown(Key.DOWN)){
        
    hero._y += walkspeed;
        
    hero.gotoAndStop("walk");
        
    moving true;
        }
        
        if(!
    moving && !attacks) {
            
    hero.gotoAndStop("stance")
        }
        
        function 
    attacks() {
            if(
    hero.attack)
            return;
            
            if (
    Key.isDown(punchcombo)) {
            
    _root.hero.gotoAndPlay("punch"); // if there's no combo, then the normal attack is played
            
    hero.attack true;
            }

            if (
    Key.isDown(kick)) {
            
    _root.hero.gotoAndPlay("kick");
            
    hero.attack true;
        }
        }
    };


    //------------------------
    onEnterFrame = function () {
        
    //trace(Key.getCode());
            
    movement();
        
    attacks();
    }; 
    thanks

  5. #5
    Zombie Coder EvilKris's Avatar
    Join Date
    Jun 2006
    Location
    Fukuoka, Japan.
    Posts
    796
    Well firstly I'd say the fact that you have the attack function within another function might have some effect. Also noticed you're using GotoAndPlay instead of GotoAndStop.

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