Skip to main content
deleted 5 characters in body; edited tags; edited title
Source Link
user1430
user1430

Rectangle moves Why does my rectangle move faster to the leftin one direction than toin the rightopposite?

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

Rectangle moves faster to the left than to the right

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 Rectangle to the display. It is noteworthy that the Rectangle class is a

org.newdawn.slick.geom.Rectangle

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

Why does my rectangle move faster in one direction than in the opposite?

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 rectangle to the display. It is noteworthy that the rectangle class is aorg.newdawn.slick.geom.Rectangle.

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

added 133 characters in body
Source Link

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 Rectangle to the display. It is noteworthy that the Rectangle class is a

org.newdawn.slick.geom.Rectangle

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

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 Rectangle to the display. It is noteworthy that the Rectangle class is a

org.newdawn.slick.geom.Rectangle

Why are the speeds for the movement different, and how can I fix this?

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 Rectangle to the display. It is noteworthy that the Rectangle class is a

org.newdawn.slick.geom.Rectangle

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

Source Link

Rectangle moves faster to the left than to the right

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 Rectangle to the display. It is noteworthy that the Rectangle class is a

org.newdawn.slick.geom.Rectangle

Why are the speeds for the movement different, and how can I fix this?