# Drag and Drop random behaviour

**URL:** https://discourse.processing.org/t/drag-and-drop-random-behaviour/20419
**Category:** Coding Questions
**Created:** [May 3, 2020, 5:26am UTC](https://discourse.processing.org/t/drag-and-drop-random-behaviour/20419 "2020-05-03T05:26:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![yurikleb](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/yurikleb/32/9059_2.png) [@yurikleb](https://discourse.processing.org/u/yurikleb)
#### Post date: [May 3, 2020, 5:26am UTC](https://discourse.processing.org/t/drag-and-drop-random-behaviour/20419/1 "2020-05-03T05:26:47Z")

</div>

I’m following [this example](https://editor.p5js.org/projects/B13wH5T3) which seems to work very well.

I’m trying to rewrite it using classes, as I need to have several draggable objects in my project (I’m creating an image tagging tool for a computer vision project).

However, my sketch behaves very strangely and I can’t identify the problem.  
The dragging works for the first few drags, then it stops working, then sometimes it works again.  
When I do shorter drags is seems to work better and for a bit longer 🤔  
It’s a very random behaviour and I can’t figure out where is the problem.

[Here is a link to my sketch](https://editor.p5js.org/yurikleb/sketches/GihD3V9N_)

Any advice is welcome!

---

<div class="post-metadata">

### Author: ![Sven](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sven/32/8293_2.png) [@Sven](https://discourse.processing.org/u/Sven)
#### Post date: [May 3, 2020, 8:49pm UTC](https://discourse.processing.org/t/drag-and-drop-random-behaviour/20419/2 "2020-05-03T20:49:51Z")

</div>

Hello @yurikleb,

Debugging can be a challenge sometimes. 😄 I would recommend limiting your bug hunt to the following lines of code.

```auto
    mouseX > tag_rect.x - tag_rect.radius &&
    mouseX < tag_rect.y + tag_rect.radius &&
    mouseY > tag_rect.y - tag_rect.radius &&
    mouseY < tag_rect.y + tag_rect.radius

```

---

<div class="post-metadata">

### Author: ![yurikleb](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/yurikleb/32/9059_2.png) [@yurikleb](https://discourse.processing.org/u/yurikleb)
#### Post date: [May 4, 2020, 10:55am UTC](https://discourse.processing.org/t/drag-and-drop-random-behaviour/20419/3 "2020-05-04T10:55:52Z")

</div>

Hey @Sven thanks!  
Just had another look and saw the problem on the 2nd line,  
the code should be:

```auto
    mouseX > tag_rect.x - tag_rect.radius &&
    mouseX < tag_rect.x + tag_rect.radius &&
    mouseY > tag_rect.y - tag_rect.radius &&
    mouseY < tag_rect.y + tag_rect.radius

```

Thanks!!
