Getting an instance of a class to fade out before a new one appears
in
Programming Questions
•
2 years ago
I have a class which basically just displays an image, and that's stored in an ArrayList. When the user mouses over the image, that one vanishes and a new one appears elsewhere. I'd like the image to fade out on a mouse hit test before the new one appears, but I'm having trouble implementing this.
The display function in the class is basically just:
void display() {
tint(255, opac);
image(target, x, y);
}
And I have the ArrayList call 'remove' on a successful hit test, followed by adding a new instance of the class where 'opac' is reset to 255. What I'm not sure about is where to put an 'opac = opac - 5;' line to get the image to fade out, and THEN have the new one called.
Obviously it won't work outside draw(), but I don't want it triggered until the hit test is successful, and then need opac reset to 255 for the new instance. Any thoughts?
1