Hi! Welcome to the forum!
I guess you have more lines on your code - because I feel the rest of the code is causing the problem. More concretely, you may have noStroke()
somewhere to hide lines. But then once noStroke
is triggered, even once inside if
, the stroke will not come back. You have to call stroke(...)
to bring the stroke back, or wrap noStroke()
inside push()
/ pop()
to keep the style within the block. Just to illustrate the problem:
void setup() {
size(400, 400);
}
void draw() {
background(128);
if (mousePressed) {
noStroke();
ellipse(100, 100, 50, 50);
}
strokeWeight(5);
line(mouseX, mouseY, mouseX+10, mouseY);
}
Once you click, the line will be gone. I think this is the kind of problem you are having. One way to fix is
void setup() {
size(400, 400);
}
void draw() {
background(128);
if (mousePressed) {
noStroke();
ellipse(100, 100, 50, 50);
}
stroke(0);
strokeWeight(5);
line(mouseX, mouseY, mouseX+10, mouseY);
}
and the other (elegant) solution
void setup() {
size(400, 400);
}
void draw() {
background(128);
if (mousePressed) {
push();
noStroke();
ellipse(100, 100, 50, 50);
pop();
}
strokeWeight(5);
line(mouseX, mouseY, mouseX+10, mouseY);
}
Anyways it’s always a good idea to show the entire code (if the project is big, make sure you make a small enough program to reproduce the problem…)