Closed Tsourdox closed 3 days ago
Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, please make sure to fill out the inputs in the issue forms. Thank you!
Hi @Tsourdox,
mouseIsPressed is a boolean that indicates whether the mouse is pressed (true if pressed, false otherwise). It’s not an event like mousePressed(), and it’s independent of the mouse position.
I made a working example for your use case, which stops drawing the circle when hovering over an overlay: Example
let isMouseInOverlay = false;
const overlayElement = document.querySelector('#overlay');
overlayElement.addEventListener('mouseover', () => {
isMouseInOverlay = true;
});
overlayElement.addEventListener('mouseout', () => {
isMouseInOverlay = false;
});
function setup() {
createCanvas(400, 400);
}
function draw() {
background(255, 100, 100);
if (mouseIsPressed && !isMouseInOverlay) {
ellipse(mouseX, mouseY, 100);
}
}
Additionally, here’s another example comparing mousePressed() and mouseIsPressed: Comparison example
Hope this helps!
Thanks @sikaili for answering here! @Tsourdox if you have further questions or need additional help with your code, feel free to join the community Discord if you haven't already.
Topic
Is there a way to prevent the mouseIsPressed to become true if there is an element overlaying the canvas?
Basically I don't want to draw the circle when the mouse is over the div element.