java - Moving a sprite to the left or down is faster than moving it to the right or up -


i making basic game slick2d , lwgjl having wierd issue when i'm moving player(an image) left/down slower moving 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 code in method update()

edit: of code can viewed in here https://www.dropbox.com/sh/p13sbxucmni36vd/k5xtanoulm

any appreciated

  //setting original playerx , 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 problem yet? change playerx , playery(delta in case) floats , problem solved. remember when convert float int round down.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -