PGraphics clear() method?

edited March 2018 in Android Mode

Hi, I have problems clearing a PGraphics layer. Using Java mode, it works perfect, no more with Android mode. I've tried clear(), background(0,0), none works... The only way I found is to recreate the layer... Why is that?

My code, trimmed down to this problem, is like:

        PGraphics layer;
        //only debug version works
        boolean debug=true;
        void setup() {
          size(800, 800);
          layer=createGraphics(width, height);
          layer.beginDraw();
          layer.background(0, 0);
          layer.endDraw();
        }
        void draw() {
          background(128);
          layer.beginDraw();
          layer.ellipse(mouseX, mouseY, 50, 50);
          layer.endDraw();
          image(layer, 0, 0);
        }
        void mousePressed() {
          if (debug) {
            layer=createGraphics(width, height);
            layer.beginDraw();
            layer.background(0, 0);
            layer.endDraw();
          } else {
            layer.beginDraw();
            layer.clear();
            layer.endDraw();
          }
        }

Thanks for your answer.

Answers

  • you can also draw a black rect at 0,0

  • Yes Chrisir, but I still dont understand why clear doesnt work with Android mode...

  • I was having the exact same problem with one of my projects (a live wallpaper with a composition of PImages and PGraphics layers). I'm using the P2D renderer on the main project, while PGraphics objects have been initialized with the default renderer (that's because I whant a nearest neighbor scaling that I cant obtain with OpenGL PGraphics objects).

    The clear method not only just doesn't work, but it also provide a performances drop. Background(0,0) have the same problem (I just whant to clean with alpha = 0) but it doesn't provide performances decrese and the background(255,255) call works well, so it's just a problem with PGraphics alpha applied on the main renderer. I don't really know how to solve this problem otherwise :/

Sign In or Register to comment.