Skip to content
Snippets Groups Projects
Commit be9175e1 authored by koz01's avatar koz01
Browse files

Define fix FPS

parent 05d16b51
Branches
No related merge requests found
...@@ -6,6 +6,8 @@ import javafx.scene.canvas.GraphicsContext; ...@@ -6,6 +6,8 @@ import javafx.scene.canvas.GraphicsContext;
public class DrawingThread extends AnimationTimer { public class DrawingThread extends AnimationTimer {
private static final int FPS = 100;
private final Canvas canvas; private final Canvas canvas;
private final GraphicsContext gc; private final GraphicsContext gc;
...@@ -25,13 +27,19 @@ public class DrawingThread extends AnimationTimer { ...@@ -25,13 +27,19 @@ public class DrawingThread extends AnimationTimer {
*/ */
@Override @Override
public void handle(long now) { public void handle(long now) {
gc.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
world.draw(gc); double deltaT = (now - lasttime) / 1e9;
if (lasttime > 0) { if (deltaT >= 1./FPS) {
//time are in nanoseconds and method simulate expects seconds gc.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
world.simulate((now - lasttime) / 1e9); world.draw(gc);
if (lasttime > 0) {
//time are in nanoseconds and method simulate expects seconds
world.simulate(deltaT);
}
lasttime = now;
} }
lasttime = now;
} }
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment