我正在使用Libgdx制作一款赛车游戏。我希望触摸屏幕右半部分来加速,同时不需要移除之前的触摸点,在屏幕左侧再次触摸以发射子弹。我无法检测到后续的触摸点。
我已经搜索并获得了Gdx.input.isTouched(int index)
方法,但无法确定如何使用它。我的屏幕触摸代码如下:
if(Gdx.input.isTouched(0) && world.heroCar.state != HeroCar.HERO_STATE_HIT){
guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
if (OverlapTester.pointInRectangle(rightScreenBounds, touchPoint.x, touchPoint.y)) {
world.heroCar.state = HeroCar.HERO_STATE_FASTRUN;
world.heroCar.velocity.y = HeroCar.HERO_STATE_FASTRUN_VELOCITY;
}
} else {
world.heroCar.velocity.y = HeroCar.HERO_RUN_VELOCITY;
}
if (Gdx.input.isTouched(1)) {
guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
if (OverlapTester.pointInRectangle(leftScreenBounds, touchPoint.x, touchPoint.y)) {
world.shot();
}
}
getX(i)
之前,代码应该检查Gdx.input.isTouched(i)
?(可能未使用的触摸点的X坐标为零...)。我会更新代码。 - P.T.