parent
504d09d8f8
commit
07b1f60f27
|
|
@ -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,34 +61,23 @@ 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() {
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue