追踪" moveState"显示变量始终位于开关的默认选项中,即使我按下A或D键也是如此。
var keys:Array = [];
private function onKeyUp(e:KeyboardEvent):void
{
keys[e.keyCode] = false;
}
private function onKeyDown(e:KeyboardEvent):void
{
keys[e.keyCode] = true;
}
在更新功能中我有这个,
switch (keys)
{
case Keyboard.A:
moveState = "LEFT";
break;
case Keyboard.D:
moveState = "RIGHT";
break;
default:
moveState = "STOP";
break;
}
答案 0 :(得分:0)
它始终显示默认值,因为变量键是一个数组,因此它不具有Keyboard.A的值。
我的建议:更新keyUp和keyDown函数中的moveState变量,并使用update函数内的moveState向左或向右移动。
private function onKeyUp(e:KeyboardEvent):void
{
switch(e.keyCode){
case Keyboard.A:
moveState = "LEFT";
break;
case Keyboard.D:
moveState = "RIGHT";
break;
}
}
private function onKeyDown(e:KeyboardEvent):void
{
moveState = "STOP";
}