# Can there exist multiple pairs of beginDraw() and endDraw() invoked on the same PGraphics in the same frame?

**URL:** <https://discourse.processing.org/t/can-there-exist-multiple-pairs-of-begindraw-and-enddraw-invoked-on-the-same-pgraphics-in-the-same-frame/48408>\
**Category:** Beginners\
**Created:** [April 6, 2026, 2:54pm UTC](https://discourse.processing.org/t/can-there-exist-multiple-pairs-of-begindraw-and-enddraw-invoked-on-the-same-pgraphics-in-the-same-frame/48408 "2026-04-06T14:54:31Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [April 6, 2026, 4:47pm UTC](https://discourse.processing.org/t/can-there-exist-multiple-pairs-of-begindraw-and-enddraw-invoked-on-the-same-pgraphics-in-the-same-frame/48408/2 "2026-04-06T16:47:42Z")

</div>

> Can there exist multiple pairs of beginDraw() and endDraw() invoked on the same PGraphics in the same frame?

Yes

Example code that worked with P2D:

> **Code**
>
> ```processing
> PGraphics a;
> PGraphics b;
> 
> char c;
> 
> void setup()
> {
> size(600, 200, P2D);
> a = createGraphics(180, 180, P2D);
> b = createGraphics(180, 180, P2D);
>   
> a.beginDraw();
> //a.background(255, 0, 0); // Set initial background
> a.textAlign(CENTER, CENTER);
> a.textSize(96);
> c = 'A';
> a.endDraw();
>   
> b.beginDraw();
> //b.background(0, 255, 0); // Set initial background
> b.endDraw();
>   
> imageMode(CENTER);
>   
> noLoop();
> }
>   
> void draw()
> {
> // Set background and paint over
> a.beginDraw();
> a.background(155, 128, 0); // Set background to pain over
> //a.clear();
> a.text(c, a.width/3, a.height/2);
> a.endDraw();
>   
> image(a, width/6, height/2); 
>   
> c++;
> // Adds to above
> a.beginDraw();
> a.text(c, 2*a.width/3, a.width/2);
> a.endDraw();
>   
> c++;
> if(c>'A' + 25) c = 'A';
>   
> image(a, 3*width/6, height/2);  
>   
> // Display image
> b.beginDraw();
> b.image(a, 0, 0);
> b.endDraw();
>   
> image(b, 5*width/6, height/2);
>   
> noLoop();
> }
> 
> void keyPressed()
> {
> loop();
> }
> 
> ```

I had initial issues _without P2D_ and worked directly with P2D.

Advance frames with a key press.

References:

- [Render Techniques / Processing.org](https://processing.org/tutorials/rendering)
- [PGraphics saving to GIF with transparent background](https://discourse.processing.org/t/pgraphics-saving-to-gif-with-transparent-background/42267)

`:)`

---

_[View the full topic](https://discourse.processing.org/t/can-there-exist-multiple-pairs-of-begindraw-and-enddraw-invoked-on-the-same-pgraphics-in-the-same-frame/48408)._
