Loading...
Logo
Processing Forum
So I'm trying to use PGraphics to get a buffer for Syphon. My main program calls three separate classes' "run" function, and each class draws itself within those functions. How do I get those classes to be rendered into the PGraphics object? Do I have to have some sort of return value on the individual "run" functions? Perhaps return another PGraphics object? Quite confused. So my code essentially looks like this right now-


void draw(){
      canvas.beginDraw();
      object1.run();
      object2.run();
      object3.run();
      canvas.endDraw();
}

Replies(2)

One possible solution is to pass the graphics object (canvas) to the run methods e.g.

void draw(){
    canvas.beginDraw();
    object1.run(canvas);
    object2.run(canvas);
    object3.run(canvas);
    canvas.endDraw();
}

Then modify the run method signature for the three classes e.g.

public void run(PGraphics pg){
    // now use pg to draw to the canvas e.g.
    pg.fill(255);
    pg.stroke(0);
    // ...
}