简体   繁体   English

p5.j​​s mousePressed在第一次迭代后停止

[英]p5.js mousePressed stop after first iteration

I need just the first click. 我只需要第一次点击。 I cannot do mouseClicked() because it does not allow you to get the mouse button clicked (left or right). 我不能使用mouseClicked(),因为它不允许您单击鼠标按钮(向左或向右)。 Anyone know any workarounds? 有人知道任何解决方法吗? I'm not opposed to doing this in vanilla js but I was wondering if anyone with more knowledge in p5 than me knows how to do this. 我不反对在Vanilla js中执行此操作,但我想知道是否有人对p5的了解超过我,知道如何执行此操作。

you can check if mousePressed once via this 您可以通过此mousePressed检查一次 mousePressed

int pressed = false;
mousePressed(){
    if(!pressed){
        //run code
        pressed=true;
    }
};
mouseReleased(){
    pressed=false;
};

As i learned how to code on a processingJS on khan academy which is extremely close to p5.js 当我学会了如何在可汗学院的处理JS上编码时,它与p5.js极为接近

EDIT looking at https://processing.org/tutorials/interactivity/ I learned that it isnt button it is mouseButton so if you run 编辑查看https://processing.org/tutorials/interactivity/我了解到它不是button而是mouseButton因此如果您运行

mouseClicked(){
    println(mouseButton);  
   //0 === left
   //1 === right
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM