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