linking sketches link a hyperlink

edited September 2015 in Programming Questions

Hi all,

I am creating a series of sketches in Processing and I would like to link each of the sketches together with a button on each of the sketches that then loads another sketch. I see this interaction similar to a way that one might move between web pages. For example, when I click on a area in the sketch, I then load a new sketch. I have been looking into using switch statements with button clicks using "if" expressions but I am having a hard time running each of of the animations in the sketches. Here is where I am right now.

void setup() {
  size(1000, 1000);
  smooth();
  frameRate(30);
}

void draw(){
  
 
 if (keyPressed){          //when key is pressed the scene will change
   
   int num = key;
  int rooms = num;
  
  switch(rooms){
    case 'a':
    case 'A':
      room1(mouseX, mouseY);   //right now you need to hold down the key
 break; 
    case 's':
    case 'S':
      room2();
  break;
  
  } 
}
}

void room1(int x, int y) {

      background(0);
      stroke(255, 0, 0);
      //line(30, 20, 80, 5);
      //line(10, 75, 30, 75);
      strokeWeight(5);
      stroke(0, 0, 0);
      fill(255);
      bezier(x, y, 80, 200, 80, 75, 100, mouseY);
      bezier(100, 5, mouseX, mouseY, 80, 400, mouseX, 60);
      fill(0);
      ellipse(300, 300, 60, 60);
      ellipse(20, 20, 60, 60);
    }
  
void room2() {


      background(255,0,0);
      stroke(255, 0, 0);
      //line(30, 20, 80, 5);
      //line(10, 75, 30, 75);
      strokeWeight(5);
      stroke(0, 0, 0);
      fill(255);
      bezier(mouseX, mouseY, 80, 200, 80, 75, 100, mouseY);
      bezier(100, 5, mouseX, mouseY, 80, 400, mouseX, 60);
      fill(0);
      ellipse(300, 300, 60, 60);
      ellipse(20, 20, 60, 60);
    }

Answers

Sign In or Register to comment.