Text in PGraphic layer

edited November 2013 in Questions about Code

-I've noticed two things about text in a PGraphic layer: -

pg.fill(255, 80);
pg.text("asdf", 15, 15);

-Its transparency doesn't change (at least using JAVA2D), and it doesn't render on the layer(?)-

if (frameCount % 60 > 30) image(pg, 0, 0); //inside draw() function

-When the layer is not displayed the text keeps there.-


  • Answer ✓

    I'm not sure if I entirely understand your problem. First instinct response: Do you call background() at the beginning of draw()?

  • edited November 2013

    I wasn't cleaning the screen. What a fool. Thanks. Transparency worked too (only in JAVA2D. In P2D or P3D doesn't work).

    It was a simple window object that appears when mouse is pressed.

    I should think another fade out implementation .

    Window msg;
    void setup() {
      size(400, 400);
    void draw(){
      if (msg != null){
        if (!msg.finish()) msg.show(); else msg = null;
    void mousePressed(){
      msg = new Window("text here.", 200, 100); 
    class Window {
      PGraphics win;
      String body;
      int timeout = 255;
      Window(String _body, int w, int h){
        body = _body;
        win = createGraphics(w, h);
      void show(){
        win.background(255, 0, 0, timeout); //alpha = timeout
        win.fill(255, timeout); //alpha = timeout
        win.text(body, win.width/2 - textWidth(body), win.height/2);
        image(win, width/2 - win.width/2, height/2 - win.height/2);
      boolean finish(){
        if (timeout == 0) {
          return true;
        else {
          return false;
Sign In or Register to comment.