I'm working on a java game using LibGdx and I need your help.
Explanation: There is one issue that I have with the arrow keys. Let me explain how my code works first. So in my update method, I check to see if keys are pressed. And if they are I handle them. The thing is that my code checks on after the other. So the first arrow key it checks has priority over all the others since, if it is pressed, it will be called first. Ex:
public static void updateControls(){
if(Gdx.input.isKeyPressed(Input.Keys.UP){
//Make player move up...
}
if(Gdx.input.isKeyPressed(Input.Keys.DOWN){
//Make player move down...
}
if(Gdx.input.isKeyPressed(Input.Keys.LEFT){
//Make player move left...
}
if(Gdx.input.isKeyPressed(Input.Keys.RIGHT){
//Make player move right...
}
}
By the way, my game is tile base. When the player is done moving 1 tile, it checks the arrow key input again to see which direction it needs to go next.
What causes the problem: Whenever a player is moving left, right or down and is holding one of those buttons and decides to press up. Up will take priority and the player will start moving up even though the player was initially moving down.
I tried explaining this to my best abilities since it's pretty hard to comprehend without trying it yourself. if you need more explanation or a link to my game to try the glitch yourself, feel free to comment and ask for those things. Thanks!