Using PGraphics as background?

edited January 2014 in Programming Questions

Hi

This problem is driving me nuts! Is it possible to use PGraphics for a Sketch background?

Here is the example:

PGraphics pg;

void setup(){
  size(640, 480);
  pg = createGraphics(640, 480);
  gMethod();
}

void draw(){
  background(pg);
}

void gMethod(){
  pg.beginDraw();
  fill(255);
  rect(0, 0, 100, 100);
  pg.endDraw();
}

It displays the graphics for one frame and then it draws black. Is this a way how PGraphics behaves? Does it expire after one draw cycle?

Thanks

Answers

  • edited January 2014 Answer ✓

    You need to call the fill() and rect() functions of your PGraphics instance, not the fill() and draw() functions of your sketch.

    pg.fill(255);
    pg.rect(0, 0, 100, 100);
    

    Compare your code to the documentation: http://www.processing.org/reference/PGraphics.html

  • Ha, ha, ha! This is so true! Thank you for saving me from insanity.

  • Just because I helped you with your code does NOT mean I saved you from insanity. You might be crazy as a loon! :p

  • Well, I don't know... Dali's quote: "The difference between me and the crazy man is that I am not crazy!" is the only psychotherapy I've had so far... 8-}

Sign In or Register to comment.