So I’m trying to make the player move using Box2D. The player moves left and right using ‘A’ and ‘B’ keys.
When I press ‘A’ and ‘D’ very fast the movement lags or should i say twitches. Here is the code.
The Player class extends InputAdapter and I Override 2 methods, KeyDown and KeyUp.
The movement is Vector2 variable.
@Override
public boolean keyUp(int keycode) {
if(Keys.A == keycode || Keys.D == keycode && movement.x > 0) {
body.setAngularVelocity(0);
movement.x = 0f;
body.setLinearVelocity(movement);
}else
return false;
return true;
}
@Override
public boolean keyDown(int keycode) {
switch(keycode) {
case Keys.A:
movement.x = -velocity;
break;
case Keys.D:
movement.x = velocity;
break;
default:
return false;
}
return true;
}
The Player class has also update method where I apply the movement
public void update() {
body.applyLinearImpulse(movement, new Vector2(), true);
}
And then I’ve just used the players update method in the render method like so player.update();
of course the i’ve added listenenrs and so on. Is there something that I’ve forgotten?
Here is the .jar file.
http://www.mediafire.com/download/x5aogpoqahcb87h/test.jar
Is it normal that the file is 18Mb??
Thank you very much.