Need help with mouseY

Hello, below I have pasted my code. What I have been working on, but couldn’t figure out how to preform it, is to not be able to draw the ellipse (when pressing on the mouse) on the text at the top of the screen. I have used a line like “if (mouseY>100);” before, but not I can’t seem to make one such line work in this situation.

PGraphics circles;
//Variables for the size and color of the ball and the text
String v = "Welcome to Paint Game! Below are a list of keys for different colors and a list of challenges for you! But, remember to reset after each challenge.";
String s = "Q = Blue,  W = Green,  E = Orange,  R = Purple,  A = Red,  S = White,  D = Yellow,  F = Pink, Z = Black,  X = Brown,  C = Gray,  V = Cyan  Tab = Random.";
String e = "You can to click 'Space' to erase your drawing, and press numbers 0-9 to change the size of the paint!";
String q = "Challenge 1:  Draw a face.  Challenge 2: Draw a person for the face.  Challenge 3: Draw a family for the person.  Challenge 4: Draw a house for the family.  Challenge 5: Have fun!";


void setup() 
{
  //Setup the window
  size(1280, 730);
  background(255);
  fill(0);
  //Paste the text
  text(v, 10, 20);
  text(s, 10, 40);
  text(e, 10, 60);
  text(q, 10, 80);
  line(0, 85, 1280, 85);
  circles = createGraphics(1280, 730); 
}

void draw() 
{
  //Setup
  background(255);
  noStroke();
  noCursor();
  //When different keys are pressed they change the color of the ellipse
  //If mouse is pressed, then draw 
  if (mousePressed)
  {
    circles.beginDraw();
    circles.noStroke();
    circles.fill(0);
    circles.ellipse(mouseX, mouseY, 50, 50);
    circles.endDraw();
  }
  //Print the second plane
  image(circles, 0, 0);
  //If mouse isn't pressed, show the ellipse but dont draw it
  ellipse(mouseX, mouseY, 50, 50);
  fill(0);
  stroke(0);
  line(0, 85, 1280, 85);
  text(v, 10, 20);
  text(s, 10, 40);
  text(e, 10, 60);
  text(q, 10, 80);
}

You have 2 ways of solving this:

Either you forbid to draw when mouseY is too low and the if statement that you are speaking about should work

if (mousePressed)  {
  if (mouseY > 100) {
    circles.beginDraw();
    circles.noStroke();
    circles.fill(0);
    circles.ellipse(mouseX, mouseY, 50, 50);
    circles.endDraw();
  }
}

Or, you simply draw back your text on top of it every time at the end of draw.

2 Likes