Is there a less CPU intensive way to create a double buffer, bec just now when am doing it this way it takes up 50-60% of CPU without it, it’s 10-20%.
I know i could use OpenGL or Slick etc… but am trying to create this whole thing without any Libraries (except System Library).
public void draw() {
if (this.getBufferStrategy() == null) {
createBufferStrategy(2);
return;
}
Graphics2D g = (Graphics2D) getBufferStrategy().getDrawGraphics();
g.setColor(Color.BLACK);
g.fillRect(0, 0, WIDTH+2, HEIGHT);
g.setColor(Color.white);
g.setFont(new Font("Serif", Font.PLAIN, 14));
g.drawString("Ups: " + this.Ups , 4, 12);
g.drawString("FPS: " + this.frameRate , 4, 24);
// for(int i = 0; i < test.length; i++){
// if(getCurrentState().toLowerCase().contains(test[i].getClass().getSimpleName().toLowerCase())){
// try {
// Method m = test[i].getClass().getDeclaredMethod("draw", Graphics2D.class);
// m.invoke(test[i], g);
// }catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// System.out.println("graphics Error!");
// System.out.println(e.toString());
// }
// }
// }
g.dispose();
getBufferStrategy().show();
}
Any information would be appreciated
Cheers