# Pregunta mouseDragged , control en función draw

**URL:** https://discourse.processing.org/t/pregunta-mousedragged-control-en-funcion-draw/24447
**Category:** Español
**Created:** [October 8, 2020, 6:35pm UTC](https://discourse.processing.org/t/pregunta-mousedragged-control-en-funcion-draw/24447 "2020-10-08T18:35:44Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![TiagoNess](https://avatars.discourse-cdn.com/v4/letter/t/a4c791/32.png) [@TiagoNess](https://discourse.processing.org/u/TiagoNess)
#### Post date: [October 8, 2020, 6:35pm UTC](https://discourse.processing.org/t/pregunta-mousedragged-control-en-funcion-draw/24447/1 "2020-10-08T18:35:44Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

Hola muchas gracias por la ayuda de antemano, tengo el siguiente código, y quiero que no pinte la elipse de la posición (0,0). Quiero que funcione el mouseDragged, y que no pinte el arreglo, pero no encuentro solución. En el depurador, pinta la elipse al 3° frame, ayuda por favor.

```auto

int fila = 6;
int columna = 9 ;
int radio = 50;
Hueco[][] huecos;
Ficha f;

void setup() {
  size(800, 600);
  background(236, 224, 232);
  //fullfcreen();
  f = new Ficha(width/2, height/2, 50); 
  huecos = new Hueco[fila][columna];

  for (int i = 0; i < fila; i++) {
    for (int j = 0; j < columna; j++) {
      Hueco h = new Hueco(i, j, radio);
      huecos [i][j]=h;
    }
  }
}

void draw() {
  background(236, 224, 232);
  drawHuecos();
   f.draw();
  //if(f.x == mouseX&& f.y == mouseY){
  // f.draw();
  // }   

  //HELP HERE, Ayuda aquí por favor
  // aquí no comprendo porque pinta el arreglo (0,0)
  // pase el depurador y es al 3° frame que lo pinta,
  //¿como sería el codigo para que funcione mouseDraggued. ?
}

void drawHuecos() {
  for (int i = 0; i < fila; i++) {
    for (int j = 0; j < columna; j++) {
      huecos[i][j].draw();
    }
  }
}

void mouseDragged() {
  f.x = mouseX;
  f.y = mouseY;
  f.mouseDragged();
}

//void mousePressed() {
// f.x = mouseX;
// f.y = mouseY;
//}

class Hueco{
  private int x;
  private int y;
  private int radio;

  Hueco(int x_ , int y_ , int r_){
    x = x_;
    y = y_;
    radio = r_;
  }
 
  void draw(){
   // ellipse(x,y,radio,radio);
    ellipse( x*radio+radio/2 ,y*radio+radio/2,3*radio/4,3*radio/4);
    fill(250);
  }
}
public class Ficha {
  int x, y;
  int rsem;

  Ficha(int x_, int y_, int r_) {
    x = x_;
    y = y_;
    rsem= r_;
  }
  
  void draw() {
    fill(30, 11, 54);
    circle(x, y, rsem);
  }
  
  void mouseDragged(){
    this.x=mouseX;
    this.y=mouseY;
    this.draw();
  }
}

```

>

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [October 8, 2020, 7:22pm UTC](https://discourse.processing.org/t/pregunta-mousedragged-control-en-funcion-draw/24447/2 "2020-10-08T19:22:33Z")

</div>

no hablo espangol

```auto

int fila = 6;
int columna = 9 ;
int radio = 50;
Hueco[][] huecos;
Ficha f;

void setup() {
  size(800, 600);
  background(236, 224, 232);
  //fullfcreen();
  f = new Ficha(width/2, height/2, 50); 
  huecos = new Hueco[fila][columna];

  for (int i = 0; i < fila; i++) {
    for (int j = 0; j < columna; j++) {
      Hueco h = new Hueco(i*radio+radio/2, j*radio+radio/2, radio);
      huecos [i][j]=h;
    }
  }
}

void draw() {
  background(236, 224, 232);
  drawHuecos();
  f.draw();
  //if(f.x == mouseX&& f.y == mouseY){
  // f.draw();
  // }   

  //HELP HERE, Ayuda aquí por favor
  // aquí no comprendo porque pinta el arreglo (0,0)
  // pase el depurador y es al 3° frame que lo pinta,
  //¿como sería el codigo para que funcione mouseDraggued. ?
}

void drawHuecos() {
  for (int i = 0; i < fila; i++) {
    for (int j = 0; j < columna; j++) {
      huecos[i][j].draw();
    }
  }
}

void mouseDragged() {
  f.mouseDragged();

  for (int i = 0; i < fila; i++) {
    for (int j = 0; j < columna; j++) {
      huecos[i][j].mouseDragged();
    }
  }
}

//void mousePressed() {
// f.x = mouseX;
// f.y = mouseY;
//}

//==========================================================================
class Hueco {
  private int x;
  private int y;

  Hueco(int x_, int y_, int r_) {
    x = x_;
    y = y_;
    radio = r_;
  }

  void draw() {
    fill(250);
    // ellipse(x,y,radio,radio);
    ellipse( x, y, 
      3*radio/4, 3*radio/4);
  }

  void mouseDragged() {
    if (dist(mouseX, mouseY, x, y) > 22)
      return; // leave

    x=mouseX;
    y=mouseY;
    //this.draw();
  }
}//class
//==========================================================================
public class Ficha {
  int x, y;
  int rsem;

  Ficha(int x_, int y_, int r_) {
    x = x_;
    y = y_;
    rsem= r_;
  }

  void draw() {
    fill(30, 11, 54);
    ellipse(x, y, 
      rsem, rsem);
  }

  void mouseDragged() {
    if (dist(mouseX, mouseY, x, y) > 22)
      return; // leave
    x=mouseX;
    y=mouseY;
    //this.draw();
  }
}
//==========================================================================

```

---

<div class="post-metadata">

### Author: ![TiagoNess](https://avatars.discourse-cdn.com/v4/letter/t/a4c791/32.png) [@TiagoNess](https://discourse.processing.org/u/TiagoNess)
#### Post date: [October 9, 2020, 1:50am UTC](https://discourse.processing.org/t/pregunta-mousedragged-control-en-funcion-draw/24447/3 "2020-10-09T01:50:15Z")

</div>

😀  
thank you very much

The error is in the draw method of the “Hueco”, is the order, thanks.  
You clarified the way to write between classes.

Thank you very much!!! 😌 😁
