英文:
(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.log
ing for both left and right and swapping the orders of the conditions but only if (mouseButton === LEFT)
gets called.
答案1
得分: 0
所以 mouseClicked
函数只有在左鼠标按钮被点击时才保证运行。根据文档,您应该使用 mousePressed 或 mouseReleased 代替。
英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论