We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, how to make that click on the mouse would be the text that appears
void setup() {
size(100, 100);
}
void draw() {
if (mousePressed == true) {
if (mouseButton == LEFT) {
fill(0); // Black
} else if (mouseButton == RIGHT) {
fill(255); // White
}
} else {
fill(126); // Gray
}
rect(25, 25, 50, 50);
}
Answers
text (mouseX , mouseX, mouseY);
but me make clicking on an item to display the text
please don't post duplicates.
i've copied the code here and deleted the other.
thanks koogs
Post your entire code
For example draw a rectangle with rect()
see reference for rect()
Then write text on it using text() , e.g. click me
Then in function mousePressed () check if the mouse is on the rect (don’t confuse the function mousePressed () with the variable mousePressed. The function has the brackets () the variable has not)
You want
void mousePressed () {
}
The function gets called automatically on mouse press
in it you want to check with if if mouseX>rectX position and if mouseX < rectX + rectWidth && same for mouseY
So you know mouse is inside rectangle
Then set a variable hasBeenPressed to true
Declare it before setup as false
boolean hasBeenPressed=false;
Now finally in draw if(hasBeenPressed) text(“Yes“,33,33);