Advertisement Jump to content
Sign in to follow this  

[java] Double buffer

This topic is 3879 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In the second example from the sticky FAQ there is Graphics g = backBuffer.getDrawGraphics(); Problem is Image has no such method getDrawGraphics . So I used getGraphics :
	public void paint(Graphics g)
		if (buffer==null) return;
		Graphics gb=buffer.getGraphics();
		gb.drawRect(0, 0, 100, 100);
		g.drawImage(buffer, 0, 0, null);
But it doesn't show anything .

Share this post

Link to post
Share on other sites
Yes you're right; must be a typo. "getDrawGraphics()" is a method from the BufferStrategy class, so in this case getGraphics() is the correct method to use.

Have you checked that buffer is correctly instantiated, not null, correct sizes.

Also are you using active rendering, or repaint(). Maybe your paint method never gets invoked?

Share this post

Link to post
Share on other sites
Hey, I've had the same problem before. Is the paint method painting directly to the screen? Is repaint() called by AWT/Swing or are you working with active rendering? Make sure AWT/Swing is invoking repaint(). Also try invoking the flush() method, so all the graphics will be flushed to the screen. Hope this will help!

I think it's because you don't close the backbuffer's graphics. Call gb.dispose().

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!