mouseClicked() to make code reset completely

edited November 2013 in Questions about Code

So basically i have 2 layers of images the top layer changes the tint / transparancy then when it = 0 the next image loads (starting on image 1) the bottom layer is a solid image that changes to the next image when the other one changes (starting on image 2) so it gives the illusion of the images fading into each other there is a loop so it does begin again by itself but i want to be able to manually reset the code with a mouse click help please!

int sWidth = 1000;
int sHeight = 600;
String[] imgNames = {
  "closedbox.jpeg", "1.jpeg", "2.jpeg"
};
PImage img1, img2;
int start = 0;
int next = 1;
int startTime = millis();
int tintVal = 255;

void setup() {

  size(sWidth, sHeight);

  img1 = loadImage(imgNames[start]);
  img2 = loadImage(imgNames[next]);
}

void draw() {
  background(0);

  int currentTime = millis();
  int lapsedTime = currentTime - startTime;

  println(lapsedTime);

  if (lapsedTime > 16.9412) 
    startTime = millis();
  }
  println(tintVal);
  tint(255, 255);
  image(img2, 10, 10);
  tint(255, tintVal);    
  image(img1, 10, 10);

  if (tintVal<0) {
    tintVal = 255;
    start++;
    if (start>2) {
      start = 0;
    }
    next++;
    if (next>2) {
      next = 0;
    }
    img1 = loadImage(imgNames[start]);
    img2 = loadImage(imgNames[next]);
  }
}__
Tagged:

Answers

  • Add a mouseClicked() function, where you reset the global variables to their initial values.

Sign In or Register to comment.