Repeating shapes

I have a player I want to control with the arrow keys. I can’t figure out for the life of me how to stop the objects the player is made out of (an ellipse and rectangle) from repeating after moving.

I’m sure the solution is simple but I have no idea how to word my google to get the answer I need. Any help would be appreciated, thanks!

Here’s my code:

//player's position
int[] playerXY = {640, 360};
//player's speed
int playerSpeed = 5;

void setup(){
  size(1280, 720);
  background(255);
}

void draw(){
 player(playerXY[0], playerXY[1]);
}

//Player
void player(int x, int y){
  fill(0, 200, 0);
  rect(x, y, 20, 40);
  fill(255, 245, 200);
  ellipse(x + 9, y - 2, 30, 30);
}

//Arrow key controls
void keyPressed() {
  if (key == CODED){
    if(keyCode == UP){
      playerXY[1] = playerXY[1] - playerSpeed;
    }
    if(keyCode == DOWN){
      playerXY[1] = playerXY[1] + playerSpeed;
    }
    if(keyCode == LEFT){
      playerXY[0] = playerXY[0] - playerSpeed;
    }
    if(keyCode == RIGHT){
      playerXY[0] = playerXY[0] + playerSpeed;
    }
  }
  
}
1 Like

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

1 Like