今天我尝试将我的游戏加载到xperia mini pro上并意识到,无论何时按下硬件按钮,我都按预期收到onKeyDown
回调,但是当我立即获得onKeyUp
同一个密钥时实际上释放了密钥,没有调用回调方法。
输入代码如下所示:
public final boolean buttons(int keyCode, KeyEvent event, boolean state) {
boolean handled = true;
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_UP:
case KeyEvent.KEYCODE_W:
this.input.KEY_UP = state;
Logger.print("UP: " + state);
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
Logger.print("RIGHT: " + state);
this.input.KEY_RIGHT = state;
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
case KeyEvent.KEYCODE_S:
this.input.KEY_DOWN = state;
Logger.print("DOWN: " + state);
break;
case KeyEvent.KEYCODE_DPAD_LEFT:
this.input.KEY_LEFT = state;
break;
case KEYCODE_BUTTON_SQUARE:
case KeyEvent.KEYCODE_L:
this.input.KEY_FORWARD = state;
break;
case KEYCODE_BUTTON_TRIANGLE:
case KeyEvent.KEYCODE_K:
this.input.KEY_BACKWARD = state;
break;
case KeyEvent.KEYCODE_DPAD_CENTER:
this.input.KEY_ACTION = state;
break;
default:
handled = false;
break;
}
return handled;
}
有没有办法解决这个问题?
编辑:抱歉onKeyPressed
和released
。实际上意味着onKeyDown
和onKeyUp
:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return features.inputManager.inputButtons.press(keyCode, event) ?
true : super.onKeyDown(keyCode, event);
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
return features.inputManager.inputButtons.release(keyCode, event) ?
true : super.onKeyUp(keyCode, event);
}
使用true或false参数按下并释放方法调用按钮方法。
答案 0 :(得分:0)
尝试使用:
@Override
public boolean onKeyUp(inr keyCode,KeyEvent event) {
//your stuffs
}