parent
87ddfbfe72
commit
504d09d8f8
|
|
@ -19,7 +19,6 @@ 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) {
|
||||||
|
|
||||||
|
|
@ -61,23 +60,34 @@ 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();
|
|
||||||
updateScene();
|
Time.startTime = System.currentTimeMillis();
|
||||||
Graphics2D g = (Graphics2D)bs.getDrawGraphics();
|
if (System.currentTimeMillis() > Time.nextSecond) {
|
||||||
render(g);
|
Time.nextSecond += 1000;
|
||||||
bs.show();
|
Time.FPS = Time.framesInCurrentSecond;
|
||||||
int elapsed = (int)(System.currentTimeMillis() - startTime);
|
Time.framesInCurrentSecond = 0;
|
||||||
try{
|
//System.out.println("FPS: " + Time.FPS);
|
||||||
Thread.sleep(17 - elapsed);
|
|
||||||
}catch(Exception e) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
Time.framesInCurrentSecond++;
|
||||||
|
|
||||||
|
render();
|
||||||
|
updateScene();
|
||||||
|
Time.tickTime = (System.nanoTime() - Time.nanos)/1000d;
|
||||||
|
Time.deltaTime = Time.tickTime * Time.timeScale;
|
||||||
|
Time.nanos = System.nanoTime();
|
||||||
|
// System.out.println("dTime: " + Time.deltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void render() {
|
||||||
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateScene() {
|
private void updateScene() {
|
||||||
|
|
@ -144,8 +154,8 @@ public class Engine extends Canvas {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void render(Graphics2D g) {
|
public void update(Graphics g) {
|
||||||
SceneManager.render(g);
|
SceneManager.render((Graphics2D)g);
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue