RIGHT在function mouseClicked()中不触发吗?

huangapple go评论64阅读模式
英文:

(p5.js) RIGHT doesn't trigger in function mouseClicked()?

问题

由于某种原因,我无法进入条件 if (mouseButton === RIGHT)

function mouseClicked()
{
    if (mouseButton === LEFT)
    {
        console.log("左键按下");
        Nodes.push(new Node(mouseX, mouseY));
    }
    else
    {
        console.log("右键按下");
        Attractors.push(new Attractor(mouseX, mouseY));    
    }
}

我尝试了同时使用 console.log 来检查左右键,并交换了条件的顺序,但只有 if (mouseButton === LEFT) 被调用。

英文:

For some reason I can't enter the condition if (mouseButton === RIGHT).

function mouseClicked()
{
    if (mouseButton === LEFT)
    {
        console.log("left pressed");
        Nodes.push(new Node(mouseX, mouseY));
    }
    else
    {
        console.log("right pressed");
        Attractors.push(new Attractor(mouseX, mouseY));    
    }
}

I tried console.loging for both left and right and swapping the orders of the conditions but only if (mouseButton === LEFT) gets called.

答案1

得分: 0

所以 mouseClicked 函数只有在左鼠标按钮被点击时才保证运行。根据文档,您应该使用 mousePressedmouseReleased 代替。

英文:

So the mouseClicked function is only guaranteed to be run when the left mouse button is clicked. You shoud use the mousePressed or mouseReleased instead (according to the docs)

huangapple
  • 本文由 发表于 2023年7月3日 09:41:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76601428.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定