My problem here is that when i press the spacebar, it plays the attack animation but as soon as i release it it stops the animation process. I want it where i can simply press and release the button and then it completes the animation by itself.
function keyPressed(e:KeyboardEvent):void
{
if(e.keyCode == Keyboard.RIGHT)
{
rDown = true;
}
if(e.keyCode == Keyboard.LEFT)
{
lDown = true;
}
if(e.keyCode == Keyboard.UP && onGround)
{
jumped = true;
}
if(e.keyCode == Keyboard.DOWN && onGround)
{
crouchMode = true;
}
if(e.keyCode == Keyboard.SPACE && onGround)
{
attackMode = true;
}
}
function keyReleased(e:KeyboardEvent):void
{
if(e.keyCode == Keyboard.RIGHT)
{
rDown = false;
}
if(e.keyCode == Keyboard.LEFT)
{
lDown = false;
}
if(e.keyCode == Keyboard.UP)
{
jumped = true;
}
if(e.keyCode == Keyboard.DOWN)
{
crouchMode = false;
}
if(e.keyCode == Keyboard.SPACE)
{
attackMode = false;
}
}
function gameLoop(e:Event):void
{
playerStart();
}
}
}
function playerStart():void
{
warMage.y += grav;//Apply gravity to player
collisionStageCheck();
if(crouchMode)
{
warMage.gotoAndStop("CrouchWarmage");
rDown = false;
lDown = false;
}
if(attackMode)
{
if(warMage.scaleX == 1)//If we face right
{
warMage.x += 5;//Lunge right
}
if(warMage.scaleX == -1)//If we face left
{
warMage.x -= 5;//Lunge left
}
warMage.gotoAndPlay("AttackWarmage");
}
if(rDown)//If we move right
{
warMage.x += 12;
warMage.gotoAndStop("RunWarmage");
warMage.scaleX = 1;
}
if(lDown)//If we move left
{
warMage.x -= 12;
warMage.gotoAndStop("RunWarmage");
warMage.scaleX = -1;
}
if(jumped)//If we jumped
{
warMage.y -= 30;
warMage.gotoAndStop("JumpWarmage");
}
if(!rDown && !lDown && !jumped && !crouchMode && !attackMode)//If we are in neither states
{
warMage.gotoAndStop("idleWarmage");
}
}
if(!rDown && !lDown && !jumped && !crouchMode && !attackMode)switches animation to idle), you may keepattackModeon when spacebar if released, it should help. - www0z0kgotoAndStop("idleWarmage")at the last frame ofAttackWarmage- www0z0k