我有 2 个事件监听器:
1)关键监听器(A,S,D,W);- 用于移动对象
2) key listener(WhiteSpace) - 用于跳转对象
因此,当我按下 A OR S OR D OR W 键时,我按下空格键,在此之前一切正常,对象同时移动和跳跃,但如果我在移动时释放空格键,对象停...
那么当我释放键空白时,我怎么能做到这一点,对象仍然会移动?不注意其他键的释放或按下?
private function onKeyDown(e:KeyboardEvent):void {
//trace(e.keyCode);
switch(e.keyCode)
{
case 68:
direction = 'left';
stage.addEventListener(Event.ENTER_FRAME, moveRight);
break;
case 65:
direction = 'right';
stage.addEventListener(Event.ENTER_FRAME, moveLeft);
break;
case 32:
jump() // the whitespace key
break;
}
private function moveRight(e:Event):void {
shape.x += 5;
}
private function moveLeft(e:Event):void {
shape.x += 5;
}
private function jump():void {
stage.addEventListener(Event.ENTER_FRAME, jumpAnimation);
}
private function jumpAnimation(e:Event):void {
//here code for jumping increasing the y and decreasing....
}
private function onKeyUp(e:Event):void {
stage.removeEventListener(Event.ENTER_FRAME, moveRight);
stage.removeEventListener(Event.ENTER_FRAME, moveLeft);
}