xxxxxxxxxx
let on = true;
function setup() {
createCanvas(windowWidth, windowHeight);
button = new Button(width/2, height/2, 80, 80);
}
function draw() {
button.display();
}
function mouseClicked() {
button.pop();
}
class Button {
constructor(x, y, w, h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
display() {
rect( this.x, this.y, this.w, this.h);
}
pop(){
if(mouseX > this.w && mouseY > this.h && on == true) {
background(0);
on = false;
}else{
background(255);
on = true;
}
}
}