A Flash Developer Resource Site

+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Member
    Join Date
    Jun 2003
    Location
    England
    Posts
    62

    Movement By Frames

    Ok people im making a fighting game. My character has several sprites in one MC (so its servarl move clips put in one main mc) First frame of the mc is my dude standing still secont frame is of his legs moving like hes walking. thrid frame is of him punching fourn frame is of hims kicking. i want to know how to make him. i now hot to assign actions to the up down left righ buttion but i want to be able to make it so if you press forward (right) then it play frame to of the main movie clip and moves x amoun of forward. can any one help ?
    the key controles are
    right= forward (frame 2)
    left = back (frame 5)
    Ctrl =punch (frame 3)
    space =kick (frame 4)

    Thanks for any help
    Lifes a Lesson. You learn it when your through.

  2. #2
    Didn't do it. japangreg's Avatar
    Join Date
    Mar 2001
    Location
    \o/ |o| |o_ /o\
    Posts
    784
    Hey, Traineetoy.

    Several of my last posts in this forum have delt with the same issue, so I'll suggest you run a search on my user name in the Games forum to see the other threads for more background on what I'm about to say. If I have more time later today, I'll edit this post and link directly to the threads.

    I use a technique I call control frames. Basically, you have your movie set up perfectly for this system at the moment so I won’t explain how to construct the character MC. For this example, let’s assume you have named your MCs (and the frames they are in) in the following manner:
    Code:
    _root.player // the MC on root containing all the other movement MCs
    _root.player.stand // the standing MC
    _root.player.walk // the walk cycle MC
    _root.player.punch // the punch MC
    _root.player.kick // the kick MC
    Now here’s where the control frames idea comes in: what actions your character can perform is determined by what frame he is currently in. So, if he is standing, he can walk, punch or kick. If he’s in the punch frame, he can’t do anything else (until he’s returned to the stand frame)

    Since you have MCs in each frame, you have a perfect place to separate the controls by frame. So you open the actions panel for _root.player.stand and add all of the code you need to call the other frames; in the _root.player.walk MC’s action panel, use a if/else statement to test which arrow key is down and add movement code as appropriate. You don’t need to add anything to the punch/kick MCs as they have no control over other frames or the _root.player MC (as the walk clip does) but you will need to put a _parent.gotoAndStop(“stand”) action in the last keyframe of each animation.

    So the code in the _root.player.stand MC coulde look something like this:
    Code:
    onClipEvent(enterFrame){
    if (key.isDown(key.RIGHT) || key.isDown(key.LEFT)){
    _parent.gotoAndStop(“walk”);
    // if either arrow key is pressed, send the player to the walk frame
    }
    if (key.isDown(key.SPACE)){
    _parent.gotoAndStop(“kick”);
    }
    if(key.isDown(key.CTRL)){ // or the hex, I can’t remember it ATM
    _parent.gotoAndStop(“punch);
    }
    }
    and the code in the _root.player.walk MC could look like this:
    Code:
    onClipEvent(enterFrame){
    if (key.isDown(key.LEFT)){
    _parent._x -= 5;
    _parent._xscale = -100; // turns character around
    }else if (key.isDown(key.RIGHT)){
    _parent._x += 5;
    _parent._xscale = 100;
    }else{
    _parent.gotoAndStop(“stand”);
    // if neither arrow key is pressed, go back to stand
    }
    }
    That should do it. Remember to pay attention to the targeting of your MCs.

    hth
    japangreg
    Hush child. japangreg can do what he wants. - PAlexC
    That was Zen - this is Tao.

  3. #3
    Member
    Join Date
    Jun 2003
    Location
    England
    Posts
    62
    i don't suppose someones got an example fla of this ?
    Lifes a Lesson. You learn it when your through.

  4. #4
    Didn't do it. japangreg's Avatar
    Join Date
    Mar 2001
    Location
    \o/ |o| |o_ /o\
    Posts
    784
    Nope.

    Just try to add the code as I described above and let us know what happens.
    Hush child. japangreg can do what he wants. - PAlexC
    That was Zen - this is Tao.

  5. #5
    Illuminatus! fospher.com's Avatar
    Join Date
    Jan 2002
    Location
    5th Dimension
    Posts
    2,185
    Originally posted by japangreg
    Nope.
    Actually - Yes, courtesy of Marmotte. here.
    But! I suggest reading over japangreg's post anyways - it will help you grasp the concept (even though its a different technique) much better.

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