简体   繁体   中英

LibGDX problems with if

I have this if statement in my LibGDX game. The problem is that my player watching left, he moves in the left direction, which is correct, but if he watshes in right direction he moves left anyway. How can I solve this problem?

 public boolean keyUp(int keycode) {
        if (keycode == Input.Keys.A &&  player.b2body.getLinearVelocity().x >=-0.5) {
            SpinDashleft();


            return true;
        }
        else   if (keycode == Input.Keys.A &&  player.b2body.getLinearVelocity().x <=0.5) {
            SpinDashright();


            return true;
        }


        return false;
    }
   public void SpinDashleft() {


    player.b2body.applyLinearImpulse(new Vector2(-7.1f, 0), player.b2body.getWorldCenter(),true);

}

public void SpinDashright() {


        player.b2body.applyLinearImpulse(new Vector2(7.00f, 0), player.b2body.getWorldCenter(),true);

}

What is the 0.5 for? Check for a minimum speed? If so, you probably got the signs wrong there.

    if (keycode == Input.Keys.A) {
      if (player.b2body.getLinearVelocity().x >= 0.5) {
        SpinDashleft();
        return true;
      }
      if (player.b2body.getLinearVelocity().x <= -0.5) {
        SpinDashright();
        return true;
      }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM