Replace an Image on MousePressed and making it stay
in
Programming Questions
•
6 months ago
In my code, i was able to make the second image appear on top of the first image when the mouse is pressed, but it goes away when the mouse is released. How do i make the second image stay? and is there a way to make the first image underneath disappear? or change the transparency of it or something when the mouse is pressed?
Here's the code:
PImage img30;
PImage img31;
PImage img32;
PImage img33;
PImage img35;
PImage img36;
PImage img37;
void setup () {
size (700, 700);
img30 = loadImage ("kitchen2.png");
img31 = loadImage ("family2.png");
img35 = loadImage ("straw.png");
img32 = loadImage ("grape2.png");
img33 = loadImage ("sadwatermelon2.png");
img36 = loadImage ("knife.png");
img37 = loadImage ("murder.png");
}
void draw (){
image (img30, 0, 0, 700, 700);
image (img31, 0, 200, 400, 400);
if (mousePressed) {
image (img37, 0, 200, 400, 450);
}
image (img35, -50, 380, 200, 200);
image (img32, 70, 440, 80, 80);
image (img33, 460, 400, 230, 150);
image (img36, mouseX, mouseY, 50, 200);
}
1