# Action when mouse is on object

**URL:** <https://discourse.processing.org/t/action-when-mouse-is-on-object/17277>\
**Category:** Libraries\
**Created:** [January 23, 2020, 5:30am UTC](https://discourse.processing.org/t/action-when-mouse-is-on-object/17277 "2020-01-23T05:30:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![floflopm](https://avatars.discourse-cdn.com/v4/letter/f/779978/32.png) [@floflopm](https://discourse.processing.org/u/floflopm)\
**Post date:** [January 23, 2020, 5:30am UTC](https://discourse.processing.org/t/action-when-mouse-is-on-object/17277/1 "2020-01-23T05:30:35Z")

</div>

Hi,

I now have a script with objects (i’m using Fisica library). I would like to have two classes of circles. When the mouse in on a circle, something happens to the other (ex. it scales up). I just don’t know how to code this (in a void mouseSomething? with ‘‘if’’?). in // are various attempts I made but they didn’t work…

Thank you,

```auto
import fisica.*;
FCircle c;
ArrayList <FCircle> list = new ArrayList();
FWorld world;

//-----------------------------------
void setup() {
  size(500,500);
  smooth();
  
  Fisica.init(this);
  
  world = new FWorld();
  world.setGravity(0,1);
  world.setEdges();
  
  FCircle c = new FCircle(30);
  c.setPosition(300,300);
  c.setDamping(0.01);
  c.setVelocity(0, 200);
  c.setRestitution(0.6);
  world.add(c);
}

//------------------------------
void draw(){
  background(255);
  world.draw();
  world.step();
}
  
// // Test if the cursor is over the box 
// if (mouseX == circle position) { //????
// onshape = true;  
// if(!locked) { 
// stroke(255); 
// fill(153);
// } 
// } else {
// stroke(153);
// fill(153);
// onshape = false;
// }
//}

// void mouseMoved() {
// FBody hovered = world.getBody(mouseX, mouseY);
// if (hovered == c){
// FCircle b = new FCircle(2);
// b.setPosition(random(0,width),random(0,height));
// world.add(b);

//void mouseMoved(){
// FBody hovered = world.getBody(mouseX, mouseY);
// if c.collide (mouseX, mouseY){
// FCircle b = new FCircle(2);
// b.setPosition(random(0,width),random(0,height));
// world.add(b);
// }
  
  
  
  //void mousePressed() {
  // FBody pressed = world.getBody (mouseX,mouseY); 
  // if (F){
  // float sz = 40;
  // FCircle b = new FCircle(sz); 
  // b.setPosition(300,300);
  // b.setVelocity(0, 200);
  // b.setRestitution(0.7);
  // b.setDamping(0.01);
  // b.setNoStroke();
  // b.setFill(0);
```

---

<div class="post-metadata">

**Author:** ![LuckSmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lucksmith/32/5805_2.png) [@LuckSmith](https://discourse.processing.org/u/LuckSmith)\
**Post date:** [January 23, 2020, 8:18am UTC](https://discourse.processing.org/t/action-when-mouse-is-on-object/17277/2 "2020-01-23T08:18:36Z")

</div>

Hi,

within `draw()` smth like:

```auto
if (dist(mouseX, mouseY, circle.x, circle.y)<circle.radius) {
  theOtherCircle.scale(2.0);
}

```

---

<div class="post-metadata">

**Author:** ![floflopm](https://avatars.discourse-cdn.com/v4/letter/f/779978/32.png) [@floflopm](https://discourse.processing.org/u/floflopm)\
**Post date:** [January 23, 2020, 5:18pm UTC](https://discourse.processing.org/t/action-when-mouse-is-on-object/17277/3 "2020-01-23T17:18:59Z")

</div>

This could work! But I get an error message ‘‘x cannot be resolved or is not a field’’ because I’m using Fisica (I’m not sure how they define position of the circles because there arent’t any x and y in the code)…
