We are about to switch to a new forum software. Until then we have removed the registration on this forum.
How do I make my ellipse move only horizontally if I click my mouse and if I click it again it moves as it did before? This is my code:
int xPosition, yPosition;
int xAdder = 3;
int yAdder = 7;
int r, g, b;
boolean rIncreasing = true;
void setup() {
  size(displayWidth/2, displayHeight); 
  xPosition = 200;
}
void draw() {
  background(255, 0, 255);
  fill(r, g, b);
  ellipse(xPosition, yPosition, 100, 100);
  xPosition = xPosition + xAdder;
  yPosition = yPosition + yAdder;
  if (xPosition > displayWidth/2) {
    xAdder = -3;
  }
  if (yPosition > displayHeight) {
   yAdder = -7; 
  }
  if (xPosition < 0) {
    xAdder = 3;
  }
  if (yPosition < 0) {
    yAdder = 7;
  }
  if (rIncreasing) {
    r = r + 1;
  } 
  else {
    r = r - 1;
  }
  if (r > 255) {
    rIncreasing = false;
  } 
  else if (r < 0) {
    rIncreasing = true;
  }
}
            
Answers
Do you want the ball to move only if you click the mouse? If so, wrap your "movement code" inside a
if(){}block that usesmousePressedas the boolean operator in the conditional statement.ex.
A simpler 1 just for comparison: :bz