# Help with movement on a background

**URL:** <https://discourse.processing.org/t/help-with-movement-on-a-background/4813>\
**Category:** Coding Questions\
**Created:** [October 24, 2018, 5:40pm UTC](https://discourse.processing.org/t/help-with-movement-on-a-background/4813 "2018-10-24T17:40:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![somedude](https://avatars.discourse-cdn.com/v4/letter/s/ecd19e/32.png) [@somedude](https://discourse.processing.org/u/somedude)\
**Post date:** [October 24, 2018, 5:40pm UTC](https://discourse.processing.org/t/help-with-movement-on-a-background/4813/1 "2018-10-24T17:40:11Z")

</div>

hello i am making a code for a character that moves on oa background but i keep having the following error  
"Badly formed character constant(expecting quote, got E)

PImage bg, personagem;  
int px, py;  
boolean cima, baixo, esq, dir;

void setup(){  
size(988,795);  
bg = loadImage(“tela\_velho.jpg”);  
personagem = loadImage(“jogador.png”);

px = 500;  
py= 500;

cima = baixo = dir = esq = false;

}

void draw(){  
background(bg);  
movejogador();

}

void movejogador(){  
if(cima == true){  
py -= 3;  
}else{  
if(baixo == true){  
py += 3;  
}  
}  
if(esq == true){  
px -= 3;  
}else{  
if(dir == true){  
px += 3;  
}  
}  
image(personagem, px, py);  
}

void keyPressed(){  
if(key ==‘LEFT’){  
esq = true;  
}else{  
if(key == ‘RIGHT’){  
dir = true;  
}else{  
if(key == ‘DOWN’){  
baixo = true;  
}else{  
if(key == ‘UP’){  
cima = true;  
}  
}

Thanks in Advance

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [October 25, 2018, 10:01am UTC](https://discourse.processing.org/t/help-with-movement-on-a-background/4813/2 "2018-10-25T10:01:07Z")

</div>

> [@somedude](#):
>
> cima = baixo = dir = esq = false

If i‘m not mistaken, then this is not possibile. You should set each Variable individually.

Correction: As jeremydouglass said below, it is actually valid code.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [October 28, 2018, 5:18pm UTC](https://discourse.processing.org/t/help-with-movement-on-a-background/4813/3 "2018-10-28T17:18:50Z")

</div>

> [@Lexyth](#):
>
> If i‘m not mistaken, then this is not possibile.

Actually, it is possible. Not always recommended, but valid code.

@somedude:

If you look at your error box, you will see that the error gives a line number: 40. If you click on the error message it will highlight the error line.

```
if (key =='LEFT') {

```

…you can’t put a String in single quotes in Java – it needs to be a char or Character, like ‘L’, or a String in double quotes like “LEFT”. But you don’t want either of those – you want the built-in [PConstants keyword LEFT](https://github.com/processing/processing/blob/master/core/src/processing/core/PConstants.java#L453), which is a variable name and so doesn’t appear in quotes at all.

…AND you want to use it like this:

> **[keyCode / Reference](https://processing.org/reference/keyCode.html)**
>
> The variable keyCode is used to detect special keys such as the UP, DOWN, LEFT, RIGHT arrow keys and ALT, CONTROL, SHIFT. When checking for these keys, it can be useful to first chec…

```auto
color fillVal = color(126);

void draw() {
  fill(fillVal);
  rect(25, 25, 50, 50);
}

void keyPressed() {
  if (key == CODED) {
    if (keyCode == LEFT) {
      fillVal = 255;
    } else if (keyCode == RIGHT) {
      fillVal = 0;
    } 
  } else {
    fillVal = 126;
  }
}

```
