Moving an image with key presses

so I am trying to do movement of a image with the arrow buttons and it says “the operator == is undefined for the argument type(s) Boolean, int” (i have no clue how to fix this and i don’t understand why it is happening) I have my code here it would really help if someone can tell me what is happening

//images
PImage up_frog;

//movement variables
int x = 225;
int y = 650;


void setup() {
  //set size
  size(500, 700);
  //load images
  up_frog = loadImage("Frog.png");
}



void draw() {



  //make 1st grass 
  fill(0, 255, 0); //green
  rect(-1, 600, 501, 100);

  //make 2nd grass
  fill(0, 255, 0); //green
  rect(-1, 300, 501, 100);

  //make 3rd grass
  fill(0, 255, 0); //green
  rect(-1, -1, 501, 100);

  //make 1st road 
  fill(0); //black
  rect(-1, 400, 500, 200);

  //make 2nd road 
  fill(0); //black
  rect(-1, 100, 500, 200);

  //make 1st road lines
  for (int road = -1; road <= 701; road += 80) {
    fill(255, 255, 255); //white
    rect(road, 495, 40, 20);
  }

  //make 2nd road lines
  for (int road = -1; road <= 701; road += 80) {
    fill(255, 255, 255); //white
    rect(road, 190, 40, 20);
  }


  //frog
  image(up_frog, x, y);
  up_frog.resize(0, 50);


  // go back from end
  if (x < 0) {
    x = 255;
  }
}

void keypressed() {
  //movement
  if (key == CODED) {
    //move up
    //Pressed
    if (keyPressed == UP) {
      y = y - 50;
    } else if (keyPressed == DOWN) {
      y = y+50;
    } else if (keyPressed == LEFT) {
      x = x- 50;
    } else if (keyPressed == RIGHT) {
      x = x +50;
    }
  }
}
1 Like

if (keyPressed == UP) {

Variable keyPressed is of datatype boolean:

A boolean can only be compared to another boolean in Java.

The constant UP is of datatype int; and thus can’t be compared to keyPressed:

I believe you meant to use key or keyCode system variable instead:

1 Like

thanks for the explanation! I switched it and I don’t get the error but it does not seem to move the picture as I press

Here’s some “Player Move” basic sketch example:
Studio.ProcessingTogether.com/sp/pad/export/ro.91tcpPtI9LrXp

You can replace ellipse() w/ your “frog” image() of course.

1 Like

thanks a lot !!!