Hello @MarkusWiesinger
This post by @jeremydouglass might be of use:
But because we can see only the class code and not the main program I had to kind of imagine the other variables at play.
For example, when you say:
Does endless here mean that there is an accumulation of a score that remains intact that you build upon when you reset?
Or does everything reset to the original default settings?
Also, regarding the boolean end
in:
I’m assuming this is declared and initialized in the main program.
But cannot see how/or where in your main code you mark the event that the game is over. This may be key to understanding the issue.
Also, I played with your code a bit to understand the behavior you want.
A super simple working version to confirm this is the basic behavior you want to reset the color to the initial red. (?) With a few comments.
//////////////////////////////////////////////////////////////////////////////
int x = 150;
int y = 150;
int w = 100;
int h = 100;
boolean activated = false; //set to false/off before the mouse position is hovering over the rect
boolean invisible = false; //?? no info on how this fits into your main program
boolean end = false; //?? no info on how this fits into your main program
color col = color(255, 0, 0);
color black = color(0);
void setup() {
size(400, 400);
background(0);
fill(col); // initialize with red
rect (x, y, w, h);
}
void draw() {
if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) {
activated = true;
} else {
activated = false;
}
if (activated) {
fill(black); // change to black after mouse position over rect, stays black until reset(any key is pressed)
rect (x, y, w, h);
}
if (keyPressed == true) {
fill(col);
rect (x, y, w, h);
} else {
fill(0); // need the else statement or reset to red does not work
}
}
Hopefully this is helpful!