I thought I understood how it works in BufferedStrategy, but how wrong was I.
Basically I’m passing the strategy from the main class to the engineManager, which handles drawing. Everything is fine and it draws the actual Images except that it flickers horribly.
This is my main and how I form the buffered image
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = env.getDefaultScreenDevice();
gameFrame game = new gameFrame();
screenManager gameScreen = new screenManager(device, game);
engineManager engine = new engineManager(game);
engine.start();
KeyListener keyInput = new inputManager();
MouseListener mouseListener = new inputManager();
MouseMotionListener mouseTracker = new inputManager();
game.createBufferStrategy(2);
game.addKeyListener(keyInput);
game.addMouseMotionListener(mouseTracker);
game.addMouseListener(mouseListener);
game.setIgnoreRepaint(true);
Then at the engine manager I do this
Graphics2D g;
public engineManager(Frame f){
bufferStrategy = f.getBufferStrategy();
g = (Graphics2D)bufferStrategy.getDrawGraphics();
}
public void render(Graphics2D g){
Rectangle2D.Double rect = new Rectangle2D.Double(352F, 252F, 48F, 48F);
g.setColor(Color.white);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
AffineTransform t = new AffineTransform();
//t.rotate(java.lang.Math.PI/180*x);
t.rotate(inputManager.rotateAngle, 376, 276);
g.setTransform(t);
g.clearRect(0,0,800,600);
g.fill(rect);
bufferStrategy.show();
}
Nothing else here is important except the BufferStrategy.
How am I suppesed to work the Double Buffering? And what about the chance of getting memory leakage without g.dispose();
If I use g.dispose(); There won’t be any prettay pictures on mah screen.