Question

I am making a basic game with Slick2D and LWGJL but I am having a wierd issue that when i'm moving my player(an image) to the left/down it is slower than moving to the right/up.

Input input = gc.getInput();

    if(input.isKeyDown(Input.KEY_W)){
        PlayerY += delta * .1f;
    }
    if(input.isKeyDown(Input.KEY_S)){
        PlayerY -= delta * .1f;
    }

    if(input.isKeyDown(Input.KEY_A)){
        PlayerX -= delta * .1f;
    }
    if(input.isKeyDown(Input.KEY_D)){
        PlayerX += delta * .1f;
    }

All of this code is in the method update()

Edit: All of my code can be viewed in here https://www.dropbox.com/sh/p13sbxucmni36vd/K5XTaNOulm

Any help will be appreciated

Was it helpful?

Solution

  //Setting the original PlayerX and PlayerY values
    private static int PlayerX = Game.ScreenLength/2;
    private static int PlayerY = Game.ScreenHeight/2; 

vs

   if(input.isKeyDown(Input.KEY_W)){
        PlayerY += delta * .1f;
    }
    if(input.isKeyDown(Input.KEY_S)){
        PlayerY -= delta * .1f;
    }

    if(input.isKeyDown(Input.KEY_A)){
        PlayerX -= delta * .1f;
    }
    if(input.isKeyDown(Input.KEY_D)){
        PlayerX += delta * .1f;
    } 

See the problem yet? Change PlayerX and PlayerY(Delta too just in case) to floats and your problem will be solved. Remember when you convert from float to int it always will round down.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top