How to Merge 2 Sketches with different setups

edited April 2016 in Library Questions

Hello everyone! I am trying to merge two sketches into one and switch between them with p5control. I have already put them into classes and this kinda works well but I still have a problem. One of the two sketches uses PeasyCam, the other doesn't. I would like to being able to limit the activity of Peasy cam only to one of the sketches, equivalently being able to embed each sketch into a main one, having each sketch working separately with their own setup and draw functions. Would you think it is possible? By looking around I saw that it could be possible by the main class PApplet, i.e. by statements of the type: public class Collision extends PApplet {}, but I haven't been able to find anything precise for implementing it. Here is an example of code until now:

import peasy.*;
import processing.opengl.*;

Withpeasy Mypeasy;
Nopeasy MyNopeasy;


void setup() {

  size(600, 600, OPENGL);
  smooth();
  Mypeasy = new Withpeasy(this);
  MyNopeasy= new Nopeasy();

}

void draw(){
 background(0);  
 Mypeasy.display(); 
 MyNopeasy.display();
 }

public class Withpeasy {
  PeasyCam cam;
//--------First sketch: I want to control it with peasycam
  Withpeasy(processing.core.PApplet parent) {

    cam = new PeasyCam(parent, 1000);

  }
  void display() {
    stroke(235);
    noFill();
    strokeWeight(0.5);
    box(600);

  }
}
//--------Second sketch: I want it static, that doesn't react to peasycam
public class Nopeasy {
  Nopeasy() {}
  void display() {
    stroke(235);
    noFill();
    strokeWeight(0.5);
    ellipse(0,0,200,200);
  }
} 

Thank you all!

Tagged:

Answers

  • Answer ✓

    look at hud() in the peasycam library - that lets you define bits of the code that are outside the peasycam transformations.

  • Answer ✓

    sorry, it's beginHUD() and endHUD()

    documentation is minimal...

  • This works really well, I could also implement ControlP5 buttons with this example. Thanks!

  • iirc there is also setActive or active to disable or enable it completely

Sign In or Register to comment.