dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Need help with fighting game

  1. #1
    Junior Member
    Join Date
    Mar 2009
    Posts
    12

    Need help with fighting game

    Let's say I make a guy that is able to punch.
    I give the guy 5 different animations of him punching.
    How do I make it so when I press the punch button, the guy randomly chooses one of those punch animations?

    Thanks in advance

  2. #2
    Junior Member
    Join Date
    Mar 2009
    Posts
    12
    AS2
    by the way

  3. #3
    Junior Member
    Join Date
    Mar 2009
    Posts
    12
    buuuuump

  4. #4
    Member
    Join Date
    Mar 2009
    Location
    Brooklyn, NY
    Posts
    77
    It's late so I'm not going to test, but something like this might work:

    Code:
    var punchFrameLabel:Array = new Array("punch1", "punch2", "punch3", "punch4", "punch5");
    var keyListener:Object = new Object();
    Key.addListener(keyListener);
    
    keyListener.onKeyDown = function() 
    {   
        if(Key.isDown(Key.ENTER))
        {
            yourPuncher_mc.gotoAndPlay(punchFrameLabel[Math.floor(Math.random()*punchFrameLabel.length)]);
        }
    };
    So what you would need to do is put all 5 animations of the punches in one movie clip and label the frames they start on punch1 - punch5. In the above example, if the enter key is pressed (change that for whatever key you want to make the character punch) then it randomly selects one of the frame labels from the array and tells the movie clip that they are in (in this case yourPuncher_mc) which one to play.

  5. #5
    |-'|-'|
    Join Date
    Jan 2006
    Posts
    273
    or you could just have 5 different frames and 5 different animated mc within and have stop at the very end of each animation then
    Code:
     // .. see cessnajumpin's code above
    if(Key.isDown(Key.ENTER){
      yourPuncher_mc.gotoAndStop(random(5));
    }

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