2016-09-20 107 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.