Original Post
Got a problem with drawImage with Image double buffer. I''m drawing two or more pictures, one large background and other small images on top of the background to the backbuffer then transfer whole thing to display. But the problem, I think, due to the large size of the background image, the small images actually appears on the screen first then a few seconds later the background appears; quite annoying. Is there a way to synchronize and wait until all the images are drawn on the back buffer and then copy it all to the display?
Maybe use a second Canvas as backbuffer rather than Image so it is possible to register an ImageObserver and control everything?
public class Display extends Canvas implements Runnable{
Image gbuffer;
Graphics bg;
Thread runner;
Image image1; //bottom layer large image
Image image2; //top layer small image
public Display(){
//loadimage
runner = new Thread(this);
runner.start();
}
public void paint(Graphics g) {
System.out.println("paint called");
update(g);
}
public void update(Graphics g){
if (gbuffer == null){
gbuffer = createImage(240, 240);
bg = gbuffer.getGraphics();
}
bg.drawImage(image1, 0, 0, null);
bg.drawImage(image2, 0, 0, null);
g.drawImage(gbuffer, 0, 0, this);
}
public void run() {
while (true) {
try{
runner.sleep(60);
} catch (Exception e){}
repaint();
}
}
}