吃光
private var keys:Array = [];
addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
private function onKeyDown(event:KeyboardEvent):void
{
keys[event.keyCode] = true;
}
private function onKeyUp(event:KeyboardEvent):void
{
keys[event.keyCode] = false;
}
private function onEnterFrame(event:Event):void
{
if (keys[Keyboard.LEFT]) player.x -= SPEED;
if (keys[Keyboard.RIGHT]) player.x += SPEED;
}
试看看
专治按键打架