This class makes it easy to implement the correct rendering techniques mentioned previously without having to do much work. The method createBufferStrategy(), which is inherited from the java.awt.Window class, is called to create the appropriate buffering method. Let’s override the initToScreen method to include the creation of the BufferStrategy.
public void initToScreen(int numBuffers) { super.initToScreen(); // create a BufferStrategy with a number of buffers // the window must be on screen before this call is made createBufferStrategy(numBuffers); }
You can now pass in the number of buffers you want to use. The strategy will be created after the window is placed on the screen. (Double buffering uses two buffers, triple buffering uses three, and so on.) If the number of buffers requested is greater than the number that can fit into video memory, the extra buffers are placed into system memory. This slows down everything, so don’t do it. Use the getAvailableAcceleratedMemory() method of the GraphicsDevice class to determine how much accelerated memory is on the video card.