我正在尝试创建一个节拍游戏,现在我的角色正在攻击。到目前为止,我有 3 个攻击动画并且几乎可以工作。如果你继续捣碎攻击按钮,它会攻击,但问题是一旦攻击按钮按下,它就会进入下一个攻击动画,我不希望那样。当前攻击动画完成后,如何使其转到下一个攻击动画,而不是在当前动画的中途跳到下一帧。所以我希望角色完成它的攻击,如果玩家仍然键入攻击键,它将进入下一个攻击帧。
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
public class Player extends MovieClip
{
//Attack variables
var Attacking:Boolean = false;
var Punches:int = 0;
var Punching:Boolean = false;
var Kicks:int = 0;
var Kicking:Boolean = false;
public function Player()
{
stage.addEventListener(KeyboardEvent.KEY_DOWN,KeyPressed);
addEventListener(Event.ENTER_FRAME,Update);
}
function KeyPressed(event:KeyboardEvent):void
{
stage.removeEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, KeyUp);
//If A key is down
if (event.keyCode == 65)
{
Attacking = true;
Punching = true;
Punches++;
}
}
function Update(event:Event)
{
//If player is not attacking
if (Attacking == false)
{
Punching = false;
Punches = 0;
Kicking = false;
Kicks = 0;
}
else if (Attacking == true)
{
if (Punching == true)
{
gotoAndStop('Jab' + Punches);
}
}
}
function KeyUp(event:KeyboardEvent)
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);
}
}
}
同样在我放下的每个攻击动画的最后一帧内
import flash.display.MovieClip;
import flash.events.Event;
stop();
MovieClip(parent).Attacking = false;
MovieClip(parent).Punches = 0;