How to Draw to/Continually reload an offscreen buffer?

I'm trying to make a drawing program based on the user input, but I can't seem to figure out how to draw to the permanent buffer vs. the screen.

E.g. allowing one to "slide" a specific shape without smearing it, via refreshing the buffer.

Tagged:

Answers

  • That's not really going to work.

    Instead, you're going to have to use data structures: like an array or ArrayList of Shape objects (you might have to create your own class, or use the PShape class). Add to that data structure to draw a shape, and then modify those shapes to move them around.

  • PGraphics is what Processing uses for off-screen buffers -- but you draw into them in the same way that you do the screen, so I'm not sure if it will help you with "sliding/smearing".

    Both PGraphics() and PImage() can be rendered in the draw loop with the image() call, which accepts coordinates. So if you want to render a fancy shape, and then slide it around the screen (e.g. following mouseX / mouseY), then the normal way is to create and PGraphics or PImage object, draw into it, and then use variables to translate it while rendering it in the draw() loop using e.g. image(myImage, mouseX, mouseY);

Sign In or Register to comment.