I am using Slick2d to create a top-down game, however an rectangle than I am drawing to the display is moving faster to the left than to the right, and faster up than down.
I am updating frames like so:
public void update(GameContainer gameContainer, int delta) throws SlickException {
player = new Rectangle(playerX, playerY, 10, 20);
if (gameContainer.getInput().isKeyDown(Input.KEY_LEFT)) {
x -= delta * 0.1f;
}
if (gameContainer.getInput().isKeyDown(Input.KEY_RIGHT)) {
x += delta * 0.1f;
}
if (gameContainer.getInput().isKeyDown(Input.KEY_UP)) {
y -= delta * 0.1f;
}
if (gameContainer.getInput().isKeyDown(Input.KEY_DOWN)) {
y += delta * 0.1f;
}
}
I then simply draw the Rectanglerectangle to the display. It is noteworthy that the Rectanglerectangle class is aorg.newdawn.slick.geom.Rectangle
.
org.newdawn.slick.geom.Rectangle
Why are the speeds for the movement different, and how can I fix this? Why are the speeds for the movement different, and how can I fix this?
EDIT: I have fixed the problem by slowing the movement to the left and up, but this does not explain why the problem occurs