In p5, use mouseClicked() function only when the canvas is clicked

Viewed 764

In p5 I have a code with mouseClicked() function. I want this function to be called only when the canvas is clicked. Any idea ?

1 Answers

I found the answer. When creating the canvas, link it to a function like this:

function setup() {
    var canvas = createCanvas(width, height);
    canvas.mouseClicked(my_function);
    ...
}

function my_function(){
...
}
Related