Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
(1 edit)

Oh yeah that was so annoying. The way I fixed it was instead of checking if a key was pressed using keyPressed and checking hat key was being held at the time, I had up, left, down, and right variables. In the keyPressed() function I check what key is pressed and change the variable to true, and in the keyReleased() function I check which key gets released and change the variable to false. This way you can check if multiple keys are pressed at a time, and it doesn't do that weird thing where it can't decide what key is being pressed. Sorry if that was confusing but I hope it helped :)

Heres an example with two buttons (left and right)

boolean left;
boolean right;
int x;
void keyPressed(){
  if(keyCode==LEFT||key=='a'){
    left=true;
  }
  if(keyCode==RIGHT||key=='d'){
    right=true;
  }
}
void keyReleased(){
  if(keyCode==LEFT||key=='a'){
    left=false;
  }
  if(keyCode==RIGHT||key=='d'){
    right=false;
  }
}
void move(){
  if(left){
    x--;
  }
  if(right){
    x++;
  }
}
(+1)

Wow, why didn't I think of this?  It's a shame I didn't find any online tutorials or documentation dealing with this problem. Thanks a lot!