The following code is not working properly, what i want to happen is to call the placing_shapes_in_screen function with a mouse press and then wait for another press to place an object on the screen, however what is actually happening is that the first key press is registering twice!! please help?
boolean cont = false;
void setup(){
size(500,400);
background(0,0,53);
}
void draw(){
if(mousePressed){
placing_shapes_in_screen();
println("done");
}
}
void placing_shapes_in_screen(){
fill(204,0,102);
text("Hello", 60, 90);
noFill();
while(cont == false){
if(mousePressed){
ellipse(mouseX,mouseY,20,20);
cont=true;
}
}
cont=false;
}
Probably the issue is that by default draw is called 60 time each second. That makes relying in the var
mousePressed
to control user interaction, not very precise, perhaps the button was still pressed, 1/60th seconds later...The way to go is to use the function
mousePressed()
ormouseClicked()
that are callback functions called once when one of those events ocour.some thing like this:
edit to answer OP's comment:
Than you need to check if the mouse is inside the button, and a flag (or program states) to handle placing the ellipse.
in kind of pseudo code:
edit2
here a working one online at sketchpad.cchere: