2

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

LW001
  • 2,452
  • 6
  • 27
  • 36
Joe Tannoury
  • 145
  • 10
  • when you add a negative sign to each delta thereby reversing the controls does it still have the same effect? – CodeCamper Apr 13 '14 at 21:10
  • it moves my player to the other side but always going up and right are slower.. thats interesting, still the same effect – Joe Tannoury Apr 13 '14 at 21:17
  • 1
    The problem might be somewhere `PlayerX` and `PlayerY` is handled. Going to have to see that code. You don't have any sort of gravity or wind right? You can always put in the intro of the game that there is a very strong north-eastward gust. – CodeCamper Apr 13 '14 at 21:20
  • No there isnt any kind of that :P. There is now a link to the code of the game, if you have time you can get a sneak peek :) – Joe Tannoury Apr 13 '14 at 21:49

1 Answers1

3
  //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.

CodeCamper
  • 6,609
  • 6
  • 44
  • 94
  • @JoeTannoury Anytime, I had the same problem the other day. I created an int and then added the delta which was a float because I wanted to keep a side counter. My timer stayed at zero and finally I realized (int)0 + (float)0.9 = 0 because the int will chop off everything after the decimal. – CodeCamper Apr 13 '14 at 22:14