2017-05-17 1 views
0

동전이 있습니다. 코인을 터치하면 점수가 증가합니다.오브젝트를 터치하면 점수 증분이 작동하지 않습니다.

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. 인쇄 문에 의해 동전 점수 증가를 터치 할 때마다도 13 시간을 인쇄합니다. 점수를 1 만 올리려고합니다. 이 문제를 해결하는 방법은 무엇입니까? 코드에서 내가 잘못 했습니까?

+0

내가 잘못했을 수도 있지만이 문제를 해결하는 데 도움이되는 정보가 더 필요합니다. 동전으로 만든 배열은 무엇입니까? 당신이 setTapBool 메소드를 호출 했으므로 커스텀 클래스가 있다고 상상해보십시오. 그래서 아마도이 문제는 여러분이이 커스텀 클래스에서 getX, getY 등으로 직사각형을 만들고 있다는 것입니다. – EsotericVoid

답변

0

Gdx.input.isTouched()를 Gdx.input.justTouched()로 변경 한 후 작동 시켰습니다.

관련 문제