这实际上比我想象的要容易。我只需要在类中实现 InputProcessor 并生成缺少的方法。之后,我在课堂上安装了 az InputListener,这样我就可以在整个屏幕上收听事件了。
public class GameScreen implements Screen, InputProcessor {
// ...
// rest of the class ommited for clarity
@Override
public boolean keyDown(int keycode) {
return false;
}
@Override
public boolean keyUp(int keycode) {
return false;
}
@Override
public boolean keyTyped(char character) {
return false;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
return true;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
if(gameOver){
clearGame();
}
return true;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
return false;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
return false;
}
@Override
public boolean scrolled(int amount) {
return false;
}
// ...
}