-
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
kick= 50; // 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
-
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.
-
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.
-
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
kick= 50; // 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
-
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.