Specific Image fade issues

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);
  
}
}

Did you try to put noTint() at the beginning of your draw() function?
I don’t know if the tint got reinitialized when a new loop starts :thinking:.

Also can you please create a github repository for us to be able to run your example? You have images that we don’t have access to so it is hard to see exactly what you mean.

Ah yes, sorry about that. Here you go: https://github.com/Nedelstein/Lightning-Sketch.git

Check the changes in the sketch. I didn’t touch the rain class. Use by clicking on the sketch.

Kf

//import com.temboo.core.*;
//import com.temboo.Library.Yahoo.Weather.*;

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));
  }

  stormMountain = loadImage("stormMountain.png");
  lightning = loadImage("lightning.png");

  imageMode(CENTER);
}


void draw() {
  noTint();
  background(255);

  image(stormMountain, width/2, height/2);

  for (int i = 0; i<30; i++) {
    rain[i].displayRain();
    rain[i].moveDrop();
    //loop();
  }


  boom[0].lightingStrike();
  //boom[i].moveLightning();
}

void mousePressed() {
  boom[0].transparency=255;
  boom[0].y = mouseY;//random(height);
  boom[0].x = mouseX;//random(width);
}



class flash {

  float x, y;
  float xMove, yMove;
  float strike;
  float transparency;


  flash(float tempX, float tempY) {
    x = tempX;
    y = tempY;
    xMove = random(width/2);
    yMove = random(height/2);
    strike = random(0, 20);
    transparency = 255;
  }


  void lightingStrike() {

    if (frameCount % 5 == 0)
      if (transparency>0) {
        transparency -=20;
      } else {
        y = mouseY;//random(height);
        x = mouseX;//random(width);
        return;
      }

    tint(255, transparency);
    image(lightning, x, y);
  }


  //void moveLightning() {
  //  y = random(height);
  //  x = random(width);
  //  if (transparency>0) {
  //    //transparency -=10;
  //  }
  //  //tint(255, transparency);
  //}
}