Henry Zhu
Henry Zhu

Reputation: 2618

Processing Java: How do you detect if the mouse was dragged through a variable

I understand that code inside Processing's mouseDragged() function will run if the mouse is moved and pressed at the same time. I was wondering how I could detect such movement through a variable since Processing doesn't provide a corresponding variable for mouseDragged() unlike mousePressed(). Thanks!

Upvotes: 1

Views: 858

Answers (3)

Bill Morgan
Bill Morgan

Reputation: 1

There is https://processing.org/reference/mouseMoved_.html which sounds like the right thing.

Upvotes: -1

Henry Zhu
Henry Zhu

Reputation: 2618

A solution specific to Processing would be to create the variable that stores whether the user dragged the mouse or not. Under mouseDragged(), the variable is set to true. Inside the draw() function, if the mouse is not pressed, the variable is set to false.

Example:

boolean mouseDragged = false;

void draw()
{
    if (mousePressed == false)
    {
        mouseDragged = false;
    }

    println(mouseDragged);
}

void mouseDragged()
{
    mouseDragged = true;
}

Upvotes: 0

user4624062
user4624062

Reputation:

You need the MouseMotionListener instead. It has two methods:

  1. Mousedragged
  2. MouseMoved

Upvotes: 4

Related Questions