AS3 Flash - 在 KeyPress 上切换动画

AS3 Flash - toggle animation on KeyPress

当我的游戏角色击中计算机并按下空格键时,动画变为 gotoAndStop(2)。到目前为止这是有效的。

我想要的是,当我再次按下空格键时,它会回到 gotoAndStop(1)

我该怎么做?

这是我的代码:

public function turnOn(event:KeyboardEvent)
    {
        if(jon.hitTestObject(computers) && event.keyCode == 32)
        {
            computers.gotoAndStop(2);
        }

    }

检查当前计算机的框架:computers.currentFrame

您的代码将如下所示:

if(jon.hitTestObject(computers) && event.keyCode == 32)
{
    if (computers.currentFrame == 1)
        computers.gotoAndStop(2);
    else if (computers.currentFrame == 2)
        computers.gotoAndStop(1);
}