# How to move two multiple shapes as one with keys

**URL:** <https://discourse.processing.org/t/how-to-move-two-multiple-shapes-as-one-with-keys/35995>\
**Category:** Coding Questions\
**Created:** [March 29, 2022, 10:18am UTC](https://discourse.processing.org/t/how-to-move-two-multiple-shapes-as-one-with-keys/35995 "2022-03-29T10:18:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tojifan](https://avatars.discourse-cdn.com/v4/letter/t/58f4c7/32.png) [@tojifan](https://discourse.processing.org/u/tojifan)\
**Post date:** [March 29, 2022, 10:18am UTC](https://discourse.processing.org/t/how-to-move-two-multiple-shapes-as-one-with-keys/35995/1 "2022-03-29T10:18:05Z")

</div>

Does anyone know how to move multiple shapes as one? Like how you can move a circle with W,A,S,D or arrow keys and make it move up, down, left and right, how can this be done for lets say two rectangles that are ontop of each other? Im completely lost with this and dont know how to do it

Also i use processing v3.5 and im a complete beginner so any help would be greatly appreciated as i cant seem to find any tutorials anywhere on this

---

<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:** [March 29, 2022, 10:21am UTC](https://discourse.processing.org/t/how-to-move-two-multiple-shapes-as-one-with-keys/35995/2 "2022-03-29T10:21:41Z")

</div>

[Reddit.com/r/processing/comments/bshqa8/how\_would\_i\_make\_a\_keypressed\_function\_support/eor5epo/](http://Reddit.com/r/processing/comments/bshqa8/how_would_i_make_a_keypressed_function_support/eor5epo/)

> [@Issues with smooth 2D movement in python](https://discourse.processing.org/t/issues-with-smooth-2d-movement-in-python/18556/4):
>
> That’s a very old sketch of mine. innocent BtW, I did a followup w/ 2 players instead of 1 both for Java Mode & p5js flavors: sunglasses And now I’ve decided to do a Python Mode version as well. Check it out: snake #!/bin/python2 """ Players Movement (v1.1.0) by GoToLoop (2020/Mar/11) Discourse.Processing.org/t/issues-with-smooth-2d-movement-in-python/18556/4 GoToLoop.Trinket.io/sites/players-movement Trinket.io/processing/62fab051ed Reddit.com/r/processing/comments/bshqa8/ ho…

---

<div class="post-metadata">

**Author:** ![tojifan](https://avatars.discourse-cdn.com/v4/letter/t/58f4c7/32.png) [@tojifan](https://discourse.processing.org/u/tojifan)\
**Post date:** [March 29, 2022, 10:25am UTC](https://discourse.processing.org/t/how-to-move-two-multiple-shapes-as-one-with-keys/35995/3 "2022-03-29T10:25:00Z")

</div>

I think i failed to explain my problem clearly so i apologise for that, i want to move two or multiple shapes as one shape so in the example you sent, i dont want the two circles to move seperately with different keys i want the two circles to move as one so when i click the D key or the right key, both circles move to the right at the same time, sorry for the confusion

---

<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:** [March 29, 2022, 10:30am UTC](https://discourse.processing.org/t/how-to-move-two-multiple-shapes-as-one-with-keys/35995/4 "2022-03-29T10:30:26Z")

</div>

> [@tojifan](#):
>
> … so when i click the D key or the right key, both circles move to the right at the same time,

Well, in my sketch I have a 2D array representing the 4 movement keys for the 2 Player objects:

```auto
static final byte[][] KEYS = {
  { +'W', +'S', +'A', +'D' }, { UP, DOWN, LEFT, RIGHT }
};

```

You can simply repeat the same keys for both Player objects:

```auto
static final byte[][] KEYS = {
  { +'W', +'S', +'A', +'D' }, { +'W', +'S', +'A', +'D' }
};

```

---

<div class="post-metadata">

**Author:** ![tojifan](https://avatars.discourse-cdn.com/v4/letter/t/58f4c7/32.png) [@tojifan](https://discourse.processing.org/u/tojifan)\
**Post date:** [March 29, 2022, 10:34am UTC](https://discourse.processing.org/t/how-to-move-two-multiple-shapes-as-one-with-keys/35995/5 "2022-03-29T10:34:09Z")

</div>

I see. Thank you for that
