Java 输入事件在libgdx中的android设备上不能同时工作

Java 输入事件在libgdx中的android设备上不能同时工作,java,libgdx,2d-games,Java,Libgdx,2d Games,我正在用Libgdx做一个简单的平台游戏。。。我让玩家向左移动,向右移动,然后跳跃。该代码在桌面上运行良好,但在Android设备上,当玩家向左或向右移动时不会触发跳转。看起来很奇怪。这是我的密码 私有void updatePlayerForUserInput(浮点增量时间) { //检查输入并应用于速度和状态 如果((Gdx.input.isKeyPressed(Keys.SPACE)| | ISTOUCH(0.87f,1,0,1f))&&world.player.grounded) { wo

我正在用Libgdx做一个简单的平台游戏。。。我让玩家向左移动,向右移动,然后跳跃。该代码在桌面上运行良好,但在Android设备上,当玩家向左或向右移动时不会触发跳转。看起来很奇怪。这是我的密码

私有void updatePlayerForUserInput(浮点增量时间) {

//检查输入并应用于速度和状态
如果((Gdx.input.isKeyPressed(Keys.SPACE)| | ISTOUCH(0.87f,1,0,1f))&&world.player.grounded)
{
world.player.velocity.y+=world.player.JUMP\u速度;
world.player.state=2;
world.player.grounded=false;
}
如果(Gdx.input.isKeyPressed(Keys.LEFT)| | Gdx.input.isKeyPressed(Keys.A)| | |被触摸(0,0.1f,0,1f))
{
world.player.velocity.x-=world.player.MAX_velocity;
if(世界玩家接地)
world.player.state=1;
world.player.facesRight=false;
}
如果(Gdx.input.isKeyPressed(Keys.RIGHT)| | Gdx.input.isKeyPressed(Keys.D)| | |被触摸(0.2f、0.3f、0.1f))
{
world.player.velocity.x=world.player.MAX_velocity;
if(世界玩家接地)
world.player.state=1;
world.player.facesRight=true;
}
}
私有布尔值已启用(浮点开始tx、浮点结束x、浮点开始ty、浮点结束y)
{
//检查startX和endX之间是否有任何finge接触
//startX/endX的值在0(屏幕左边缘)和1(屏幕右边缘)之间
对于(int i=0;i<2;i++)
{
float x=Gdx.input.getX()/(float)Gdx.graphics.getWidth();
float y=Gdx.input.getY()/(float)Gdx.graphics.getHeight();
如果(Gdx.input.isTouched(i)&&&(x>=startX&&x=startY&&y此代码:

    float x = Gdx.input.getX() / (float) Gdx.graphics.getWidth();
    float y = Gdx.input.getY() / (float) Gdx.graphics.getHeight();
始终从第一次活动触摸中获取x/y。您需要检查“i'th”活动触摸。如下所示:

for (int i = 0; i < 20; i++) {
    if (Gdx.input.isTouched(i)) {
      float x = Gdx.input.getX(i) / (float) Gdx.graphics.getWidth();
      float y = Gdx.input.getY(i) / (float) Gdx.graphics.getHeight();
      if ((x >= startX && x <= endX) && (y>=startY && y<= endY)) {
          return true;
      }
}
return false;
for(int i=0;i<20;i++){
if(Gdx.input.isTouched(i)){
float x=Gdx.input.getX(i)/(float)Gdx.graphics.getWidth();
float y=Gdx.input.getY(i)/(float)Gdx.graphics.getHeight();
如果((x>=startX&&x=startY&&y)
for (int i = 0; i < 20; i++) {
    if (Gdx.input.isTouched(i)) {
      float x = Gdx.input.getX(i) / (float) Gdx.graphics.getWidth();
      float y = Gdx.input.getY(i) / (float) Gdx.graphics.getHeight();
      if ((x >= startX && x <= endX) && (y>=startY && y<= endY)) {
          return true;
      }
}
return false;