如何处理多个触摸输入

时间:2016-09-20 03:00:17

标签: input libgdx

        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 个答案:

答案 0 :(得分:-1)

看起来你正在检查触摸是否在方块内。您可以放置​​一些矩形并检查玩家是否触摸它们,而不是检查触摸是否在所有这些坐标的范围内。

甚至更好,使用Scene2d添加按钮。这将使更好和可靠的输入控制。 如果你不想让它们被看到,你可以制作隐形按钮。

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

相关问题