We are about to switch to a new forum software. Until then we have removed the registration on this forum.
int s = 33;
int x = 27;
int y = 46;
boolean rectHitTest;
void draw() {
background(200);
if (squareHitTest(mouseX, mouseY, x, y, s)) {
fill(255);
} else {
noFill();
}
rect(x, y, s -1, s - 1);
void squareHitTest(int a, int b, int c, int d, int e) {
if ((a > e) && ( a < a + e) && (b > d) && ( b < d + e)) {
rectHitTest = true;
} else {
rectHitTest = false;
}
}
So I want to make the square fill white and return true when the mouse is inside the square, and no fil and return false when the mouse is outside the square? Any idea how to fix my code?
Answers
Line 8 is expecting a yes/no response from squareHitTest but line 17 says it returns nothing (void)
Remove the global variable in line 4 and use return () to return the value.
You are also missing a } from the end of draw