# Moving an image with key presses

**URL:** <https://discourse.processing.org/t/moving-an-image-with-key-presses/8432>\
**Category:** Beginners\
**Created:** [February 16, 2019, 1:32am UTC](https://discourse.processing.org/t/moving-an-image-with-key-presses/8432 "2019-02-16T01:32:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Supergreek72](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@Supergreek72](https://discourse.processing.org/u/Supergreek72)\
**Post date:** [February 16, 2019, 1:32am UTC](https://discourse.processing.org/t/moving-an-image-with-key-presses/8432/1 "2019-02-16T01:32:45Z")

</div>

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

```auto
//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;
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 16, 2019, 1:51am UTC](https://discourse.processing.org/t/moving-an-image-with-key-presses/8432/2 "2019-02-16T01:51:36Z")

</div>

`if (keyPressed == UP) {`

Variable _keyPressed_ is of datatype `boolean`:

- [Processing.org/reference/keyPressed.html](http://Processing.org/reference/keyPressed.html)
- [Processing.org/reference/boolean.html](http://Processing.org/reference/boolean.html)

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_:

- [Processing.GitHub.io/processing-javadocs/core/processing/core/PConstants.html#UP](http://Processing.GitHub.io/processing-javadocs/core/processing/core/PConstants.html#UP)

I believe you meant to use _key_ or _keyCode_ system variable instead:

- [Processing.org/reference/key.html](http://Processing.org/reference/key.html)
- [Processing.org/reference/keyCode.html](http://Processing.org/reference/keyCode.html)

---

<div class="post-metadata">

**Author:** ![Supergreek72](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@Supergreek72](https://discourse.processing.org/u/Supergreek72)\
**Post date:** [February 16, 2019, 2:06am UTC](https://discourse.processing.org/t/moving-an-image-with-key-presses/8432/3 "2019-02-16T02:06:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 16, 2019, 2:12am UTC](https://discourse.processing.org/t/moving-an-image-with-key-presses/8432/4 "2019-02-16T02:12:33Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Supergreek72](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@Supergreek72](https://discourse.processing.org/u/Supergreek72)\
**Post date:** [February 16, 2019, 3:26am UTC](https://discourse.processing.org/t/moving-an-image-with-key-presses/8432/5 "2019-02-16T03:26:24Z")

</div>

thanks a lot !!!
