Leuven Wang
Leuven Wang

Reputation: 151

keyDown() Not working Processing

I'm using Processing to make something and basically my keyDown() is not working. It supposed to be triggered when any key is pressed but the function is not being called. Code below:

int playerno=0; //determines player
boolean ready=true;
void setup() {
  size(700, 700);
  background(#FFFFFF);
  fill(#000000);
  textSize(50);
  text("Press Any Key To Start", 350, 350);
}

void keyPressed() {
  if (ready) {
    fill(#FFFFFF);
    rect(350, 350, 200, 100);
    fill(#000000);
    textSize(50);
    text("Game Ready", 350, 350);
    boolean ready=false;
  }
}

Upvotes: 0

Views: 1934

Answers (1)

Majlik
Majlik

Reputation: 1082

This will won't work without draw function. Also you are declaring new local variable ready inside keypressed() this is bad mistake. Try move your drawing code from "keyDown()" into "drawing" like this:

void draw() {
  if (ready == false) {
    background(#FFFFFF);     //This is needed for redrawing whole scene
    fill(#FFFFFF);
    rect(350, 350, 200, 100);
    fill(#000000);
    textSize(50);
    text("Game Ready", 350, 350);
  }
}

void keyPressed() {
  if (ready) {
    ready=false;
  }
}

Upvotes: 1

Related Questions