Skip to main content
gamedev.net
🔒 Locked

[java] Problems with Double Buffering

Started by donbonifacio Apr 25, 2003 at 3:44 AM 2 replies 2.7k views
Original Post
donbonifacio
donbonifacio
Hi all. I am having troubles double buffering my images. I hope that you can help me and tell me what I''m doing worng. I have my paint method in my Actor class (base class of all showables) like this:
  
public void paint( Graphics g )
{
	if( img == null )
		throw new RuntimeException("Calling Paint and image not Created!!!");

	if( buffer == null ) {
		buffer = Util.getBuffer(img);
		//buffer = img;

		
	}
	g.drawImage(buffer,tile.x,tile.y,TILE_SIZE,TILE_SIZE,null);
}
  
And that Util.getBuffer is a static method that allows me to have secevral objects sharing the same image(BufferedImage ins this case). I have it like this:
  
public static Image getBuffer( Image img )
{
	if( allBuffers.containsKey(new Integer(img.hashCode())) )
		return (BufferedImage)allBuffers.get(new Integer(img.hashCode()));
		
	BufferedImage backbuffer = new BufferedImage(Actor.TILE_SIZE, Actor.TILE_SIZE, BufferedImage.TYPE_4BYTE_ABGR);
	Graphics backbuffergc = backbuffer.getGraphics();
	backbuffergc.drawImage(img,0,0,Actor.TILE_SIZE,Actor.TILE_SIZE,null);
	
	allBuffers.put(new Integer(img.hashCode()),backbuffer);
	
	return backbuffer;
}
  
Well, like this, the Window is blank, no image is shown. Why? I am using 45x45 png''s in MDK 9.1! Tkz for any help. []
CaptainJester
CaptainJester
We would have to see your whole code to find the problem.



First make it work,
then make it fast.

--Brian Kernighan

"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
donbonifacio
donbonifacio
Humz... but I think that the problem is in that getBuffer method. I use it to have an offscreen image to double buffering. If i do not use that image it runs fine (with lots of flickring), with that is not shown anything...

I hava a class Arena (extends Canvas). It''s in the paint method that I call paint ou all my actors (that apint method in the first post).
fadilthrejk
fadilthrejk
here is an url to a lesson in JavaBoutique:
http://javaboutique.internet.com/tutorials/Java_Game_Programming/MausereignisseEng.html

It has double buffering info somewhere.
don''t use the mouse methods, though, they are deprecated.


[edited by - fadilthrejk on March 19, 2002 at 4:53 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.