PDA

View Full Version : Key Crashes: Problem with animations



Grake
February 25th, 2005, 06:40 AM
Erm lately I'm working on a game, and i encountered a problem . My main character has an idling animation and an attacking animation. I am suppose to slash my enemy once only and immediately shift back to my idling animation. But my movement controls are something like this:

if(Key.isDown(Key.Left))
{
this.gotoAndStop("MoveLeft");
}
else if(Key.isDown(Key.Right))
{
this.gotoAndStop("MoveRight");
}
else if(Key.isDown(Key.Space))
{
this.gotoAndStop("Attack");
}
else
{
this.gotoAndStop("Idle");
}

//------------------------------

But if I press down the spacebar it will continue to attack non-stop, which i didn't want it to, I only want it to attack once. If I change to onKeyUp for the attack button. My main character will crashes as it can't decide whether to play the idle animations or attack animations. My main character is a movieClip and all the codes are inside it. Please help me... thanks...

JoMan
February 25th, 2005, 10:08 AM
Try this:



if (Key.isDown(Key.SPACE) and (!attacking)) {
this.gotoAndStop("attack");
attacking = true;
}

Then have an onKeyUp code:



onClipEvent(keyUp) {
if (Key.getCode() == Key.SPACE) {
attacking = false;
}
}

that should do it.

kanpai

Grake
February 27th, 2005, 05:26 AM
Erm joman I tried the way you asked me to do. But it seem that my main character only manage to play the first frame of my attacking animations and immediately skip back to the idling animations. All my animations are in frames and not motion tweening...
Maybe u shld take a look at my .swf so probably u will get a better understanding of it...
Btw thanks for your help.