How to stop the ball from moving when no key is beying pressed?

how to stop the ellipse from moving when no key is being pressed?

PImage shrek;
float charx=0;
float chary=0;
boolean invert= false;

void setup() {
  size(600, 500);
  shrek= loadImage("shrek.jpg");
  chary= height/2;
}
void draw() {
  background(0);
  color(255);

  ellipse(charx, chary, 50, 50);
  //invert colors
  if (invert==true) {
    filter(INVERT);
  }

  //move left with a
  if (key == 'a'&&invert==false) {
    charx=charx-10;
  } 

  //move right with d
  if (key == 'd'&&invert==false) {
    charx=charx+10;
  }

  //move right with a
  if (key == 'a'&&invert==true) {
    charx=charx+10;
  } 

  //move left with d
  if (key == 'd'&&invert==true) {
    charx=charx-10;
  }
}

Hi

For your previous code this example stop moving on one direction I am on Android I don’t have keyboard option


float charx=0;
float chary=0;

void setup() {
  size(600, 500);;
  chary= height/2;
}
void draw() {
  background(0);
  color(255);

  ellipse(charx, chary, 50, 50);
  
  filter(INVERT);
  
       //move left with a
     // if (key == 'a') {
       if (mousePressed == true) {
         
    charx=charx-0;
    
    //move right with d
   } else {
     
   
   
   charx=charx+10;
    }
}


Same idea you can use for other direction you need to make charx increase / decrease by zero when you press certain key to freeze the moving

studio.ProcessingTogether.com/sp/pad/export/ro.91tcpPtI9LrXp

1 Like

thank you, do you also happen to know how to turn of filters, is there maybe something like noFilter or filter(none)?

Umm… how about not calling filter()?

boolean doBlur = true;

void setup() {
  size(400, 400, P2D);
  frameRate(60);

  background(0);
}
void draw() {
  
  noStroke();
  
  fill(0, 5);
  rect(0, 0, width, height);
  
  fill(255, 0, 0);
  rect(mouseX, mouseY, width/4, height/4);
  
  if(doBlur)
    filter(BLUR);
}

void keyReleased()
{
  doBlur = !doBlur;
}