Hi all,
I have multiple images on my sketch and am trying to only get one to fade out, but I can’t seem to get the fade to only work for the one image. It’s fading out everything when I run it. Any help would be really appreciated!
I’m trying to get the “lightning” image to fade slowly after it appears.
`
PImage stormMountain;
PImage lightning;
flash[] boom = new flash[1];
raindrop[] rain = new raindrop[30];
void setup() {
size(350, 350);
frameRate(15);
for (int i = 0; i<30; i++) {
rain[i] = new raindrop(random(width), random(height));
}
for (int i = 0; i<1; i++){
boom[i] = new flash(random(width), random(height));
}
///mountain image///
stormMountain = loadImage("stormMountain.png");
///lightning image
lightning = loadImage("lightning.png");
}
void draw() {
background(255);
rect(0,0,width,height);
imageMode(CENTER);
image(stormMountain, width/2, height/2);
for (int i = 0; i<30; i++) {
rain[i].displayRain();
rain[i].moveDrop();
//loop();
}
for (int i = 0; i<1; i++){
boom[i].lightingStrike();
boom[i].moveLightning();
}
}
`
and then my lightning class:
class flash {
float x, y;
float xMove, yMove;
float strike;
float transparency;
flash(float tempX, float tempY) {
x = tempX;
y = tempY;
xMove = random(width);
yMove = random(height);
strike = random(0,20);
transparency = 255;
}
void lightingStrike() {
if (frameCount % 20 == 0){
if(transparency>0){
transparency -=10;
}
tint(255, transparency);
image(lightning, x, y);
y = random(height);
x = random(width);
}
}
void moveLightning() {
y = random(height);
x = random(width);
if(transparency>0){
transparency -=10;
}
tint(255, transparency);
}
}