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