[java] Double buffering in java applet...

Started by
1 comment, last by Mazen 23 years, 5 months ago
I need help with my double buffering update procedure... I use this: Image offScreenBuffer; public void update(Graphics g) { Graphics gr; offScreenBuffer = null; if (offScreenBuffer==null || (! (offScreenBuffer.getWidth(this) == this.size().width && offScreenBuffer.getHeight(this) == this.size().height))) { offScreenBuffer = this.createImage(size().width, size().height); } gr = offScreenBuffer.getGraphics(); paint(gr); g.drawImage(offScreenBuffer, 0, 0, this); } But the gfx is doesn''t run smooth at all, and some CPUs even hang up when using this code... if anyone know a solution to my little prob (or even better: know a better way to use double buffering), please reply. Help my out here guys! "We paint the sky with blood tonight, setting free the damned to fight"
"We paint the sky with blood tonight, setting free the damned to fight"
Advertisement
Try something like this.

Image offScreenImage;
Graphics offScreenBuffer;

offScreenImage = createImage( somewidth, someheight );
offScreenBuffer = offScreenImage.getGraphics();

// Put your stuff here
public void dostuff() {
offScreenBuffer.drawLine
offScreenBuffer.drawOval
repaint();
}

public void update( Graphics g ) {
paint(g);
}

public void paint( Graphics g ) {
g.drawImage( offScreenImage, 0, 0 );
}

I wanrned you! Didn''t I warn you?! That colored chalk was forged by Lucifer himself!

Opere Citato
Looks like everytime update() is called, a new double buffer is being created -- you''re setting offScreenBuffer to null right before you check if it''s null or not . . .
Ernest WooWoo Gameshttp://www.woogames.com

This topic is closed to new replies.

Advertisement