Java 2D - Double Buffering a large image - is it a good idea to do so ?

I'm developing a small maze like game. I'm using double buffering. So I double buffer the enter screen area (1024x768) and copy them all back to the on screen buffer...

I need my code to run atleast at 18 - 24 fps.

Is there a better/efficient way to do this...

Note : I'm manually double buffer. I don't use any Buffer manager.

like this

publicvoid update(Graphics g)

{

Image i = createImage(...);

paint(i.getGraphics() );

g.drawImage(i..)

}

[701 byte] By [chaos_begins_herea] at [2007-11-26 23:29:56]
# 1

Hi chaos,

I am developing a game too and I achieve very high frame rate (up to 60 fps) using the hardware accelerated pipelines and the double buffering/page flipping strategy.

here is the method I call to update my the entire screen of my game:

private void screenUpdate()

{

try

{

Graphics gScr = bufferStrategy.getDrawGraphics();

gameRender(gScr); //this is where I paint the game screen

gScr.dispose();

if (!bufferStrategy.contentsLost())

{

bufferStrategy.show();

}

} catch (Exception e)

{

e.printStackTrace();

running = false;

}

}

Here is how I create the buffer strategy in the main JFrame:

try

{

EventQueue.invokeAndWait(new Runnable()

{

public void run()

{

createBufferStrategy(NUM_BUFFERS);

}

});

} catch (Exception e)

{

System.out.println("Error while creating buffer strategy");

System.exit(0);

}

bufferStrategy = getBufferStrategy();

In my gameRender method, I use only draming method that works without breaking the hardware acceleration (by default enabled with java 6.0). I just make sure to use BufferedImage without rotation or manually written filters and the game runs at 60 fps without any issue.

The CPU is even still sleeping more than 70% of the time which gives a lot room for all other processing such as path finders, A.I., ...

Cheers.

Vince.

blendinga at 2007-7-10 14:40:40 > top of Java-index,Security,Cryptography...
# 2
Thanks dude !!It's really a good new for me ... If I could achieve 20 fps that itself is enough for me..I will try out and let you know...
chaos_begins_herea at 2007-7-10 14:40:40 > top of Java-index,Security,Cryptography...