我一直在寻找使用 Adobe Flash Professional 中的 ActionScript 3.0 制作动画,其中角色 (John) 可以由查看器使用箭头键移动。我制作了两个精灵,John(默认站立角色)和 JohnLeg(抬起腿的角色),当按下向上键时,我会在它们之间切换,使其看起来像是在走路。我已经尝试过让一个不可见而另一个可见。
但是,目前它只显示 JohnLeg 0 秒,所以我相信我需要在他移动显示 JohnLeg 半秒时设置一个时间延迟,然后再切换回来。
我的代码目前只考虑向上键,大部分是使用 Adobe Flash 中的代码片段拍摄的:
var upPressed:Boolean = false;
John.addEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey_4);
stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed_4);
stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed_4);
function fl_MoveInDirectionOfKey_4(event:Event)
{
JohnLeg.visible = false;
JohnLeg.x = John.x
JohnLeg.y = John.y
if (upPressed)
{
JohnLeg.visible = true;
John.visible = false;
John.y -= 5;
//set time delay here
JohnLeg.visible = false;
John.visible = true;
}
}
function fl_SetKeyPressed_4(event:KeyboardEvent):void
{
switch (event.keyCode)
{
case Keyboard.UP:
{
upPressed = true;
break;
}
}
function fl_UnsetKeyPressed_4(event:KeyboardEvent):void
{
switch (event.keyCode)
{
case Keyboard.UP:
{
upPressed = false;
break;
}