p5js 按钮.鼠标按下调用函数 + 参数

p5js button.mousePressed calls function + arguments?

本文关键字:函数 参数 调用 按钮 鼠标 p5js      更新时间:2023-09-26

可能是愚蠢的问题,但这在 p5js 中可能吗?

function setup() {
   myButton.mousePressed(toggleVideo(1)); //This toggleVideo works well without argument
}
function toggleVideo(v) {
    blablabla[v].loop();
}  

非常感谢!

使用

mousePressed(function() { toggleVideo(1);});

使用最新的 JS,您可以编写以下内容:

function setup() {
 myButton.mousePressed(() => {
    toggleVideo(1)
 });
}
function toggleVideo(v) {
  blablabla[v].loop();
}