[java] Double buffering in java applet...
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"
November 24, 2000 03:06 AM
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement