Problem with endShape(CLOSE) when called inside void keyPressed(){}

edited November 2017 in Questions about Code

How come the program does not complete the shape when the user hits 'Enter'?

Here is the code:

boolean firstPoint;

void setup(){
  size(500,500,P2D);
  firstPoint = true;
}

//for some reason point will not work without draw
void draw(){

}

void keyPressed(){
  if(key == ENTER){
    endShape(CLOSE);
    firstPoint = true;
  }
}

void mousePressed(){
  if(firstPoint){
    beginShape();
    firstPoint = false;
  }
  vertex(mouseX,mouseY);
  point(mouseX,mouseY);
}

Answers

Sign In or Register to comment.