java - Graphics are flickering when I draw with double buffering -
i'm building simple 2d java game , having flickering issues though draw graphics using double buffering technique.
i've got started , have simple game loop far. think should work fine anyway? without flickering.. here's how it:
@override public void run() { while (running) { currentstate.update(); preparegameimage(); currentstate.render(gameimage.getgraphics()); repaint(); try { thread.sleep(14); } catch (interruptedexception e) { e.printstacktrace(); } } system.exit(0); } @override protected void paintcomponent(graphics g) { super.paintcomponent(g); if (gameimage == null) { return; } g.drawimage(gameimage, 0, 0, null); } private void preparegameimage() { if (gameimage == null) { gameimage = createimage(gamewidth, gameheight); } graphics g = gameimage.getgraphics(); g.clearrect(0, 0, gamewidth, gameheight); }
you can see how mean in this video
i'm looking tips lead me whats causing glitch. doing double buffering wrong?
any appreciated!
thanks
Comments
Post a Comment