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:
[source]
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;
}
[/source]
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.
[]