# Repeating shapes

**URL:** https://discourse.processing.org/t/repeating-shapes/18033
**Category:** Coding Questions
**Created:** [February 23, 2020, 4:37am UTC](https://discourse.processing.org/t/repeating-shapes/18033 "2020-02-23T04:37:48Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Mythikal](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@Mythikal](https://discourse.processing.org/u/Mythikal)
#### Post date: [February 23, 2020, 4:37am UTC](https://discourse.processing.org/t/repeating-shapes/18033/1 "2020-02-23T04:37:48Z")

</div>

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:

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

```

---

<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 23, 2020, 7:03am UTC](https://discourse.processing.org/t/repeating-shapes/18033/2 "2020-02-23T07:03:37Z")

</div>

[Studio.ProcessingTogether.com/sp/pad/export/ro.91tcpPtI9LrXp](http://Studio.ProcessingTogether.com/sp/pad/export/ro.91tcpPtI9LrXp)

> **[Players Movement (Java) - OpenProcessing](https://www.openprocessing.org/sketch/718355)**
>
> https://Reddit.com/r/processing/comments/bshqa8/how\_would\_i\_make\_a\_keypressed\_function\_support/eor5epo/
