# Move up and down rectangle by mousepressed

**URL:** <https://discourse.processing.org/t/move-up-and-down-rectangle-by-mousepressed/20179>\
**Category:** Libraries\
**Created:** [April 26, 2020, 3:24pm UTC](https://discourse.processing.org/t/move-up-and-down-rectangle-by-mousepressed/20179 "2020-04-26T15:24:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MCGFP](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@MCGFP](https://discourse.processing.org/u/MCGFP)\
**Post date:** [April 26, 2020, 3:24pm UTC](https://discourse.processing.org/t/move-up-and-down-rectangle-by-mousepressed/20179/1 "2020-04-26T15:24:39Z")

</div>

Hi,

I have a FBox in Fisica (actually more but I simplified the code) that I need to move up or down when clicking in it. It’s meant to be a sliding door, so it represents opening and closing it. I now have a code that scales it, but I would like to replace the void(mousepressed) part with the moving up& down.

How can I do this?

Thanks,

```auto
import fisica.*;
FWorld world;

FBox rectangle1;

ArrayList<FBox> rectangles = new ArrayList<FBox>();

void setup() {
  size(1000,1000); 
  smooth();
  Fisica.init(this);
  world = new FWorld ();

  rectangle1 = new FBox (20,height/6);
  rectangle1.setPosition(width/3,height/12);
  rectangle1.setRestitution(1);
  rectangle1.setDamping(0.0);
  rectangle1.setStatic(true);
  rectangle1.setGrabbable(false);
  rectangle1.setStrokeWeight(1);
  rectangle1.setFill(174,174,211);
  rectangle1.setStroke(0);
  rectangles.add(rectangle1);
  world.add(rectangle1);
  
  }
  
  void draw() {
  background(255);
  world.draw();
  world.step();
  }
  
  
void mousePressed() {
  
FBody pressed = world.getBody(mouseX, mouseY);

   if (pressed == rectangle1) {
      if (mouseButton == LEFT ) {
      rectangle1.setHeight(rectangle1.getHeight()*1.1);
      }
      if (mouseButton == RIGHT ) {
      rectangle1.setHeight(rectangle1.getHeight()*0.9);
      }
    }
    
    //replace by if button = left, move up and if = right, move down
    // OR better, when button = left, alternate between up and down (open/close the door)
    
  }
    

```

---

<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:** [May 3, 2020, 7:12pm UTC](https://discourse.processing.org/t/move-up-and-down-rectangle-by-mousepressed/20179/2 "2020-05-03T19:12:19Z")

</div>

FBox is an FBody.

[http://www.ricardmarxer.com/fisica/reference/fisica/FBox.html](http://www.ricardmarxer.com/fisica/reference/fisica/FBox.html)

When we look at all the things that it can do, these look potentially useful:

[addForce](http://www.ricardmarxer.com/fisica/reference/fisica/FBody.html#addForce(float,%20float)), [addImpulse](http://www.ricardmarxer.com/fisica/reference/fisica/FBody.html#addImpulse(float,%20float)), [adjustPosition](http://www.ricardmarxer.com/fisica/reference/fisica/FBody.html#adjustPosition(float,%20float)), [adjustVelocity](http://www.ricardmarxer.com/fisica/reference/fisica/FBody.html#adjustVelocity(float,%20float)), … [setForce](http://www.ricardmarxer.com/fisica/reference/fisica/FBody.html#setForce(float,%20float)), … [setVelocity](http://www.ricardmarxer.com/fisica/reference/fisica/FBody.html#setVelocity(float,%20float)), …

although there are lots.
