One key is released, other is, too?
in
Programming Questions
•
1 years ago
Hello, I'm trying to make a run and jump type mini-game thing, and I'm having difficulties with multiple keys. I picked option 2 from this site:
http://wiki.processing.org/w/Multiple_key_presses and it worked well to do the 2 keys at once. However, if I let go of the second key I pressed down, it also reads it as I let go of the first one, too....Is there a good way to fix this?
Thanks for the help
- void setup(){
- size(400,400);
- a=loadImage("map.png");
- x=0;
- y=200;
- }
- PImage a;
- int x,y;
- boolean[] keys=new boolean[526];
- boolean checkKey(int k){
- if (keys.length >= k) {
- return keys[k];
- }
- return false;
- }
- void draw(){
- background(0);
- image(a,x,0);
- if(keyPressed){
- if(checkKey(LEFT)){
- if(x<=0){
- x+=2;
- }
- }
- if(checkKey(UP)){
- y-=2;
- }
- if(checkKey(RIGHT)){
- x-=2;
- }
- }
- fill(100,0,0);
- ellipse(200,y,50,50);
- }
- void keyPressed(){
- keys[keyCode]=true;
- }
- void keyReleased(){
- keys[keyCode]=false;
- }
Thanks for the help

1