Good work here!
Good idea to use InButtonSelection as a variable
Remarks:
I ignore the idea to turn red and then off. Only going red for the moment.
No use to draw stuff in the function setup(). Draw stuff only in the function draw(). Use background at start of draw() so rects gets drawn throughout again and again fresh.
when you wan to see the buttons throughout you must draw them outside the if-clause (if (mousePressed)
). Otherwise they appear only briefly (when use background at start of draw() ). To achieve this you could have separate color variables for each button and store its color therein.
when you want to change each button separately, InButtonSelection must be separate for each button. So use InButtonSelection1, InButtonSelection2, InButtonSelection3, InButtonSelection4
Do you want it possible to change them back and forth? Then you have to change the if-clauses :
if (mouseY > 100 && mouseY < 350 && mouseX > 100 && mouseX < 350 ) {
if (InButtonSelection1) {
Important: with mousePressed used as a variable, each mouse press gets registered multiple times. Bad in your case. (good for drawing continously).
- When you use mousePressed() as function each mouse press gets registered only once. Better
Code example below.
Chrisir
boolean InButtonSelection1 = true;
void setup() {
size(1920, 1080);
background(222);
}
void draw() {
background(222);
// evaluate InButtonSelection1
if (InButtonSelection1) {
fill(255, 0, 0);
rect(100, 100, 250, 250);
} else {
fill(0);
rect(100, 100, 250, 250);
}
}
void mousePressed() {
// set InButtonSelection1
if (mouseY > 100 && mouseY < 350 &&
mouseX > 100 && mouseX < 350 ) {
// toggle InButtonSelection1
if (InButtonSelection1) {
InButtonSelection1 = false;
} else {
InButtonSelection1 = true;
}
}//if
//
}
//