Cleaning up flicker...

In previous programs created by myself, I have used a double buffering method to prevent flicker from being created when the screen is cleared for the next frame. However, this does not stop the flicker created when two drawn pieces of the program overlap.

My graphical code looks like this:

publicvoid update (Graphics g){

paint(g);

if (dbImage ==null){

dbImage = createImage(this.getSize().width, this.getSize().height);

dbg = dbImage.getGraphics();

}

dbg.setColor(getBackground());

dbg.fillRect(0, 0, this.getSize().width, this.getSize().height);

dbg.setColor(getForeground());

paint(dbg);

g.drawImage(dbImage, 0, 0,this);

}

publicvoid paint (Graphics g){

g.setColor(Color.red);

g.fillRect(100, 100, 100, 100);

g.setColor(Color.blue);

g.fillRect(150, 150, 100, 100);

}

Where update is called by a repaint() method inside a run() method loop. Any help or advice that could be offered is much appreciated, just trying to step my code up to the next level.

[1476 byte] By [risingechoa] at [2007-11-27 1:30:31]
# 1
Why are you calling paint() twice in your update() method? Take a look at this tutorial on Double Buffering. http://www.realapplets.com/tutorial/DoubleBuffering.htmlAlso, Swing components automatically use Double Buffering. You might want to look into those.
CaptainMorgan08a at 2007-7-12 0:31:52 > top of Java-index,Other Topics,Java Game Development...
# 2
i used that exact same code segment and it cleaned up the flicker in my game.
stephensk8sa at 2007-7-12 0:31:52 > top of Java-index,Other Topics,Java Game Development...