# Problem with procesing in game

**URL:** <https://discourse.processing.org/t/problem-with-procesing-in-game/11265>\
**Category:** Coding Questions\
**Created:** [May 15, 2019, 11:17am UTC](https://discourse.processing.org/t/problem-with-procesing-in-game/11265 "2019-05-15T11:17:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Garcia](https://avatars.discourse-cdn.com/v4/letter/g/ecc23a/32.png) [@Garcia](https://discourse.processing.org/u/Garcia)\
**Post date:** [May 15, 2019, 11:17am UTC](https://discourse.processing.org/t/problem-with-procesing-in-game/11265/1 "2019-05-15T11:17:42Z")

</div>

Hey guys!  
I have a little problem.  
I’m making a game for classes. It’s similar to Space Invaders.  
So when i’m press \<- (to left) and -\> (to right), sometimes it takes to move.  
Does anyone have a solution?  
My code for move:

```auto
void movNave(){
  //Movimiento de la nave
  if(keyPressed){
    if(!bullet){
      if(keyCode == 38){
        if(!bullet){
          bulletIndepe=pos[0]+40;
          bullet = true;
          numdisparos++;
          println(numdisparos);
        }
      }
    }
    if (keyCode == 39 && (pos[0]<=1080)){ //derecha
      if(tipoNave==1){
        image(navev1D, pos[0], pos[1]);
      }else if(tipoNave==2){
        image(navev2D, pos[0], pos[1]);
      }else{
        image(navev3D, pos[0], pos[1]);
      }
      pos[0] = pos[0]+indmov;
    }else if(keyCode == 37 && (pos[0]>=500)){ //izquierda
      if(tipoNave==1){
        image(navev1I, pos[0], pos[1]);
      }else if(tipoNave==2){
        image(navev2I, pos[0], pos[1]);
      }else{
        image(navev3I, pos[0], pos[1]);
      }
      pos[0] = pos[0]-indmov;
    }else{
      printarNave();
    }
  }else{
    printarNave();
  }
}

```

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [May 15, 2019, 2:44pm UTC](https://discourse.processing.org/t/problem-with-procesing-in-game/11265/2 "2019-05-15T14:44:50Z")

</div>

Im not sure what this question is asking, could you clarify please

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [May 15, 2019, 2:56pm UTC](https://discourse.processing.org/t/problem-with-procesing-in-game/11265/3 "2019-05-15T14:56:09Z")

</div>

It is hard to get the exact problem since you did not provide all your code but you can try to do something like this:

```auto
boolean moveLeft;
boolean moveRight;

void setup() {
  ...
  moveLeft = false;
  moveRight = false;
  ...
}

void draw() {
  ...
  if (moveLeft) {
    ...
  }
  if (moveRight) {
    ...
  }
  ...
}

void keyPressed() {
  if (keyCode == 37) { // not sure about the keyCode
    moveLeft = true;
  }
  if (keyCode == 39) { // not sure about the keyCode
    moveLeft = true;
  }
}

void keyReleased() {
  if (keyCode == 37) { // not sure about the keyCode
    moveLeft = false;
  }
  if (keyCode == 39) { // not sure about the keyCode
    moveLeft = false;
  }
}

```
