Revert "Revert "brought back the buffer trategy""

This reverts commit 504d09d8f8.
rotation
Marcus Gosselin 2016-02-23 13:23:19 -05:00
parent 504d09d8f8
commit 07b1f60f27
1 changed files with 16 additions and 26 deletions

View File

@ -19,6 +19,7 @@ public class Engine extends Canvas {
public static int WIDTH, HEIGHT;
public static String startScene = null;
public static String name = null;
public static BufferStrategy bs;
public Engine(String gameFolder) {
@ -60,36 +61,25 @@ public class Engine extends Canvas {
this.requestFocus();
this.addKeyListener(new Input());
//createBufferStrategy(2);
//bs = getBufferStrategy();
Time.nanos = System.nanoTime();
createBufferStrategy(2);
bs = getBufferStrategy();
while(true) {
Time.startTime = System.currentTimeMillis();
if (System.currentTimeMillis() > Time.nextSecond) {
Time.nextSecond += 1000;
Time.FPS = Time.framesInCurrentSecond;
Time.framesInCurrentSecond = 0;
//System.out.println("FPS: " + Time.FPS);
}
Time.framesInCurrentSecond++;
render();
long startTime = System.currentTimeMillis();
updateScene();
Time.tickTime = (System.nanoTime() - Time.nanos)/1000d;
Time.deltaTime = Time.tickTime * Time.timeScale;
Time.nanos = System.nanoTime();
// System.out.println("dTime: " + Time.deltaTime);
Graphics2D g = (Graphics2D)bs.getDrawGraphics();
render(g);
bs.show();
int elapsed = (int)(System.currentTimeMillis() - startTime);
try{
Thread.sleep(17 - elapsed);
}catch(Exception e) {
}
}
}
private void render() {
repaint();
}
private void updateScene() {
SceneManager.updateAll();
}
@ -154,8 +144,8 @@ public class Engine extends Canvas {
}
public void update(Graphics g) {
SceneManager.render((Graphics2D)g);
private void render(Graphics2D g) {
SceneManager.render(g);
g.setColor(Color.BLACK);
}
}