Processing Java: 如何检测鼠标是否被拖过一个变量

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

我知道如果同时移动和按下鼠标,ProcessingmouseDragged() 函数中的代码将 运行。我想知道如何通过变量检测这种移动,因为 Processing 不像 mousePressed() 那样为 mouseDragged() 提供相应的变量。谢谢!

您需要 MouseMotionListener。它有两个方法:

  1. Mousedragged
  2. MouseMoved

针对 Processing 的解决方案是创建一个变量来存储用户是否拖动了鼠标。在 mouseDragged() 下,变量设置为 true。在 draw() 函数内部,如果没有按下鼠标,则变量设置为 false

示例

boolean mouseDragged = false;

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

    println(mouseDragged);
}

void mouseDragged()
{
    mouseDragged = true;
}

https://processing.org/reference/mouseMoved_.html 听起来是对的。