At 4/12/07 11:27 PM, Jereminion wrote:
hi im trying to do a combo attack for 3 different attacks all in 1 button.. like if i press the button repeatingly then it does the full combo
right now it does the combo if you tap or if you hold down the button
remember that im trying to do it with 1 button(or key)
Aight, check this out. There are probably better ways to do this, but this works:
//make a MC with instance name "dude" with 3 frames: the last 2 named "atk0" and "atk1" respectively (for the 2 diff types of attacks). Then paste the following code onto the first frame of the main timeline:
this.dwn=false;
this.punches=0;
this.timeout=5;
this.onEnterFrame=function()
{
if (!Key.isDown(Key.UP))
{
this.dwn=false;
}
else
{
if (!this.dwn)
{
if (this.punches==0)
{
this.timecv=0;
//trace("set int");
this.myint=setInterval(chkMulti,75,this);
}
this.punches+=1;
this.dwn=true;
}
}
}
function chkMulti(who)
{
who.timecv+=1;
if (who.punches<=1)
{
who.dude.gotoAndStop("atk0");
}
else
{
who.dude.gotoAndStop("atk1");
}
//trace(who.timecv);
if (who.timecv>=who.timeout)
{
who.timecv=0;
who.punches=0;
who.dude.gotoAndStop(1);
clearInterval(who.myint);
}
}
//
What it does is uses on enterframe to check keypresses but makes sure you let the key up before recognizing another press. Then it uses a setInterval timer to check to see how many times the key is pressed in a certain period before resetting itself to wait for the next punch to trigger it. In effect, pressing "up" once plays the "atk1" anim, but pressing "up" twice really fast transitions the "atk1" into "atk2"