Drag and Drop random behaviour

I’m following this example 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 :thinking:
It’s a very random behaviour and I can’t figure out where is the problem.

Here is a link to my sketch

Any advice is welcome!

1 Like

Hello @yurikleb,

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

    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
1 Like

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

    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!!

2 Likes