We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Any help is much appreciated! Here is my code:
float x = 230;
float y = 200;
float w = 150;
float h = 80;
int state = 0;
PImage doctor;
void setup() {
size(1280, 836);
background(255);
stroke(0);
noFill();
doctor = loadImage("doctor office.jpg");
}
void draw() {
//draw button
rect(x, y, w, h);
fill(255);
//hover over button to change color
if (mouseX>x && mouseX <x+w && mouseY>y && mouseY <y+h) {
fill(0);
}
// state machine
if (mousePressed && mouseX>x && mouseX <x+w && mouseY>y && mouseY <y+h) {
state = 1;
} else {
state = 0;
}
if (state == 1) {
background(200);
image(doctor,0,0, width, height);
}
}
Answers
You are almost there.
On a side note, you are better off creating a class for button. If you want to see it, say so below.
For now, check the code below.
Kf
I would love to see the button as a class! Except this code doesn't make the button disappear after clicking on it
Right... you need to add background(0) (or your favorite color) to clear the screen every time draw() is executed. Add this line as your first line in the draw function.
As a class see below.
Kf