2016-09-20 3 views
0
 if(Gdx.input.isTouched()) {  
     //moving right touchscreen 
     if(touchPos.x >= 310 && touchPos.x <= 445 && touchPos.y >= 770 &&touchPos.y <= 870) 
      man.b2body.applyLinearImpulse(new Vector2(0.1f, 0), man.b2body.getWorldCenter(), true); 
     //moving left touchscreen 
     if(touchPos.x >= 70 && touchPos.x <= 220 && touchPos.y >= 770 &&touchPos.y <= 870) 
      man.b2body.applyLinearImpulse(new Vector2(-0.1f, 0), man.b2body.getWorldCenter(), true); 
     if(touchPos.x >=1630 && touchPos.x <= 1815 && touchPos.y >= 740 &&touchPos.y <= 935 && man.b2body.getPosition().y <=0.22) 
      man.b2body.applyLinearImpulse(new Vector2(0, 4f), man.b2body.getWorldCenter(), true); 

위 코드는 응용 프로그램을 실행할 때 내 문자가 오른쪽과 왼쪽으로 이동하고 누를 때마다 개별적으로 이동할 수 있습니다. 달리기 중에 어떻게 내 캐릭터를 점프하게 할 수 있습니까? 두 개의 입력을 처리합니까?여러 개의 터치 입력을 처리하는 방법

답변

-1

터치가 정사각형 안에 있는지 확인하는 것처럼 보입니다. 터치가 모든 좌표의 경계 안에 있는지 확인하는 대신, 일부 직사각형을 배치하고 플레이어가 터치를하는지 확인할 수 있습니다.

또는 더 좋게는 Scene2d를 사용하여 버튼을 추가하십시오. 이것은 훨씬 더 신뢰할 수있는 입력 제어를 가능하게합니다. 보이지 않는 단추를 보이지 않게 만들 수 있습니다.

Brent Aureli made a nice tutorial for on-screen controles.

관련 문제