I want to make a door open when the user clicks on it. Here's how the code looks like:
with(processing) {
noStroke();
size(1200, 900);
background(255, 153, 153);
var x = 50;
var y = 50;
if(mousePressed && (mouseButton === LEFT)) {
fill(139, 69, 19);
rect(x+150, y, 150, 200); // door opened
fill(89, 60, 31);
rect(x, y, 150, 200); // doorway
fill(255, 222, 173);
ellipse(x+(335-50), y+100, 10, 10); // handle
}
else {
fill(139, 69, 19);
rect(x, y, 150, 200); // door unopened
fill(89, 60, 31);
rect(x, y, 150, 200); // doorway
fill(255, 222, 173);
ellipse(x+15, y+100, 10, 10); // handle
}
};
However, when I click on the door, it won't open. It seems like it doesn't even understand when my mouse is pressed. I wonder what's wrong with my code. I try copy-pasting the same code to Khan Academy (except that I use mouseIsPressed instead of mousePressed) and it works!! So why is it not working in my IDE? I use VSCode btw.
Thank you!
You need move your code to
mousePressedevent handlerCode in Khanacdemy
https://www.khanacademy.org/computer-programming/spin-off-of-mousepressed-processingjs/5395110149373952
If you want to run in HTML file, you need include script code to script tag with
type="application/processing"