How to use MouseClicked() to make the background permanently clear
in
Programming Questions
•
2 years ago
Hello. I've been following the other forums that are related to this topic and have tried numerous different things but I can't seem to get my code to work. I want to click within a certain rectangle on screen and have that click clear the screen and show something new. Here's my code:
void setup() {
size (480, 480);
smooth();
}
void draw() {
background(255);
int[] numbers = new int[2];
QuestionOne();
}
void QuestionOne() {
fill(255);
rect(50, 50, 40, 20);
fill(0);
text("3 + 5 =", 15, 40);
text("8", 60, 65);
mouseClicked();
}
void mouseClicked() {
if (mouseX > 50 && mouseX < 90 && mouseY > 50 && mouseY < 70) {
background(255);
fill(0);
text("8 + 6 =", 15, 40);
}
}
Currently it is only changing when I drag the mouse over my X and Y locations. I thought that by putting that condition within mouseClicked() it would require the mouse to be clicked as well, but this isn't what is happening.
Any help would be really appreciated! Thanks!
void setup() {
size (480, 480);
smooth();
}
void draw() {
background(255);
int[] numbers = new int[2];
QuestionOne();
}
void QuestionOne() {
fill(255);
rect(50, 50, 40, 20);
fill(0);
text("3 + 5 =", 15, 40);
text("8", 60, 65);
mouseClicked();
}
void mouseClicked() {
if (mouseX > 50 && mouseX < 90 && mouseY > 50 && mouseY < 70) {
background(255);
fill(0);
text("8 + 6 =", 15, 40);
}
}
Currently it is only changing when I drag the mouse over my X and Y locations. I thought that by putting that condition within mouseClicked() it would require the mouse to be clicked as well, but this isn't what is happening.
Any help would be really appreciated! Thanks!
1