SaveFrame function exporting black frames

Hi all,
This is my first attempt at processing and I’m trying to export the frames of a sketch I’ve created. Unfortunately all the frames come out as a black png with no other content. This is the code I’m using in my sketch. Any advice much appreciated! </>

PGraphics pg;
PFont font;

void setup() {
  font = createFont("GTFAdieuTRIAL-Light.otf", 600);
  size(800, 800, P2D);
  pg = createGraphics(800, 800, P2D);

}
void draw() {
  
  background(0);
  
  pg.beginDraw();
  pg.background(216,71,26);
  pg.fill(255);
  pg.textFont(font);
  pg.textSize(160);
  pg.pushMatrix();
  pg.translate(width/2, height/2);
  pg.textAlign(CENTER, CENTER);
  pg.text("MOVING", 0, 0);
  pg.text("MOVING", 0, -375);
  pg.text("MOVING", 0, -250);
  pg.text("MOVING", 0, -125);
  pg.text("MOVING", 0, 125);
  pg.text("MOVING", 0, 250);
  pg.text("MOVING", 0, 375);
  pg.popMatrix();
  saveFrame("moving_####.png");
  pg.endDraw();
  
  
  int tilesX = 100;
  int tilesY = 100;

  int tileW = int(width/tilesX);
  int tileH = int(height/tilesY);

  for (int y = 0; y < tilesY; y++) {
    for (int x = 0; x < tilesX; x++) {
      
      int wave = int(sin(frameCount * 0.005 * (x*y) * 0.005)*60);

  // SOURCE
      int sx = x * tileW + wave;
      int sy = y * tileH;
      int sw = tileW;
      int sh = tileH;


      // DESTINATION
      int dx = x * tileW;
      int dy = y * tileH;
      int dw = tileW;
      int dh = tileH;
      
    
      copy(pg, sx, sy, sw, sh, dx, dy, dw, dh);

    }
  }
  
}

Please format your code! Select it all and use the toolbar icon.

Are you trying to save the output of pg or the screen? If pg, try (I think) pg.saveFrame(...)

If the screen, move saveFrame() to the end of draw()

2 Likes