your "buffer." syntax is the "right" way to do it.
but, since the papplet calls just redirect to the pgraphics (and potentially the recorder)...
this is probably considered a "hack" approach, so not officially sanctioned, but you can often get away with swapping in/out the "g" reference like so:
Quote:
PGraphics originalG;
PGraphics bufferG;
void setup() {
size(400,400,JAVA2D);
originalG = g;
bufferG = createGraphics(200,200,JAVA2D);
}
void useBufferG() {
g.endDraw();
g = bufferG;
g.beginDraw();
}
void useOriginalG() {
g.endDraw();
g = originalG;
g.beginDraw();
}
void draw() {
// main screen red background, green line
useOriginalG();
background(255,0,0);
stroke(0,255,0);
strokeWeight(3);
line(10,10,390,390);
// offscreen blue background, yellow line
useBufferG();
background(0,0,255);
stroke(255,255,0);
strokeWeight(3);
line(10,10,190,190);
// blit the offscreen to center of main screen
useOriginalG();
image(bufferG,100,100);
}
(you might also be able to just use the recorder mechanism -- if you don't mind that drawing also occurs on the main graphics)