G
Guest
Hi, I'm looking for some double-buffering help. I'm back with a different question than my previous one.
Within a derived Canvas class, PlotCanvas, I have declared:
Image offscreenImage;
Graphics offscreenGraphics;
What I originally had inside paint() was:
------------------------------
if(offscreenImage == null) {
offscreenImage = createImage(this.getSize().width, this.getSize().height);
offscreenGraphics = offscreenImage.getGraphics();
}
// Do lots of drawing to 'offscreenGraphics'
g.drawImage(offscreenImage,0,0,this);
------------------------------
This resulted in flickering. I did some debugging and realized that immediately upon entering paint(), the canvas was cleared. So
during all of that writing to 'offscreenGraphics', the Canvas wasn't showing the old image, and swapping at the last minute.
So, I took "lots of drawing to 'offscreenGraphics'" and put that into a function, pre_paint(), with a repaint() at the end of it, so
that all that was needed inside paint() was:
g.drawImage(offscreenImage, 0, 0, this);
I still had flickering. Any suggestions?
The code is online at:
http://www.angelfire.com/retro/there/lab73_exer2.zip
The interesting functions are in the PlotCanvas class: paint(), pre_paint(), maybe update(). The project was done in Eclipse.
Help is very much appreciated, TIA.
Within a derived Canvas class, PlotCanvas, I have declared:
Image offscreenImage;
Graphics offscreenGraphics;
What I originally had inside paint() was:
------------------------------
if(offscreenImage == null) {
offscreenImage = createImage(this.getSize().width, this.getSize().height);
offscreenGraphics = offscreenImage.getGraphics();
}
// Do lots of drawing to 'offscreenGraphics'
g.drawImage(offscreenImage,0,0,this);
------------------------------
This resulted in flickering. I did some debugging and realized that immediately upon entering paint(), the canvas was cleared. So
during all of that writing to 'offscreenGraphics', the Canvas wasn't showing the old image, and swapping at the last minute.
So, I took "lots of drawing to 'offscreenGraphics'" and put that into a function, pre_paint(), with a repaint() at the end of it, so
that all that was needed inside paint() was:
g.drawImage(offscreenImage, 0, 0, this);
I still had flickering. Any suggestions?
The code is online at:
http://www.angelfire.com/retro/there/lab73_exer2.zip
The interesting functions are in the PlotCanvas class: paint(), pre_paint(), maybe update(). The project was done in Eclipse.
Help is very much appreciated, TIA.