触摸物体和分数增量不起作用
Touch on an object and score increment does not working
我有一个 coins.I 的数组,通过触摸硬币来增加分数。
if (Gdx.input.isTouched()) {
Vector3 touchPos = new Vector3();
touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
game.camera.unproject(touchPos);
for (int i = 0; i < coins.length; i++) {
Rectangle textureBounds = new Rectangle(coins[i].getX(), coins[i].getY(), coins[i].getWidth(),
coins[i].getHeight());
if (textureBounds.contains(touchPos.x, touchPos.y)/* && !coins[i].isTapBool()*/) {
System.out.println("touched");
coins[i].setTapBool(true);
}
}
}
像这样增加分数:
for (int i = 0; i < coins.length; i++) {
if (coins[i].isTapBool()&&coins[i].isCoinVisible()) {
coinScoreController.updateCoinScore(delta);//score=score+1
coins[i].setTapBool(false);
}
coins[i].isTapBool());
}
现在,每次我触摸硬币时,分数都会增加 13,而不是 1.The 在点击的 if 条件中打印语句也会打印 13 次。
我只想将分数增加 1。
如何解决这个问题?我在代码中做错了什么?
我在将 Gdx.input.isTouched() 更改为 Gdx.input.justTouched() 后开始工作。
我有一个 coins.I 的数组,通过触摸硬币来增加分数。
if (Gdx.input.isTouched()) {
Vector3 touchPos = new Vector3();
touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
game.camera.unproject(touchPos);
for (int i = 0; i < coins.length; i++) {
Rectangle textureBounds = new Rectangle(coins[i].getX(), coins[i].getY(), coins[i].getWidth(),
coins[i].getHeight());
if (textureBounds.contains(touchPos.x, touchPos.y)/* && !coins[i].isTapBool()*/) {
System.out.println("touched");
coins[i].setTapBool(true);
}
}
}
像这样增加分数:
for (int i = 0; i < coins.length; i++) {
if (coins[i].isTapBool()&&coins[i].isCoinVisible()) {
coinScoreController.updateCoinScore(delta);//score=score+1
coins[i].setTapBool(false);
}
coins[i].isTapBool());
}
现在,每次我触摸硬币时,分数都会增加 13,而不是 1.The 在点击的 if 条件中打印语句也会打印 13 次。 我只想将分数增加 1。 如何解决这个问题?我在代码中做错了什么?
我在将 Gdx.input.isTouched() 更改为 Gdx.input.justTouched() 后开始工作。