- Java code
//键盘事件 public boolean onKeyDown(int keyCode, KeyEvent event) { int a=keyCode; Log.i("GameView", ((Integer)a).toString()); //处理键盘事件 switch(keyCode){ case KeyEvent.KEYCODE_DPAD_UP: player.move(Player.UP); break; case KeyEvent.KEYCODE_DPAD_DOWN: player.move(Player.DOWN); break; case KeyEvent.KEYCODE_DPAD_LEFT: player.move(Player.LEFT); break; case KeyEvent.KEYCODE_DPAD_RIGHT: player.move(Player.RIGHT); break; case KeyEvent.KEYCODE_DPAD_CENTER: for (int i = 0; i < bullets.length; i++) { if(bullets[i].getAlive()==false){ bullets[i].setAlive(true,player.getRefPixelX()-bullets[i].getWidth()/2,player.getRefPixelY()-player.getHeight()); break; } } break; } return super.onKeyDown(keyCode, event); }
------解决方案--------------------
http://www.iteye.com/topic/141021