added count for fps inside handle loop and displayed fps on the canvas #story[463]

This commit is contained in:
Peter
2017-03-27 16:34:54 +13:00
parent cf6bbdd1f1
commit 65ac864bf2
2 changed files with 18 additions and 2 deletions
@@ -78,15 +78,19 @@ public class CanvasController {
// overriding the handle so that it can clean canvas and redraw boats and course marks
AnimationTimer timer = new AnimationTimer() {
private long lastUpdate = 0;
private long lastFpsUpdate = 0;
private int lastFpsCount = 0;
private int fpsCount = 0;
@Override
public void handle(long now) {
if (now - lastUpdate >= 33000000){
if (true){ //if statement for limiting refresh rate if needed
gc.clearRect(0, 0, canvas.getWidth(),canvas.getHeight());
gc.setFill(Color.SKYBLUE);
gc.fillRect(0,0,canvas.getWidth(),canvas.getHeight());
drawCourse();
drawBoats();
drawFps(lastFpsCount);
// If race has started, draw the boats and play the timeline
if (race.getRaceTime() > 1){
@@ -98,6 +102,12 @@ public class CanvasController {
pauseTimelines();
}
lastUpdate = now;
fpsCount ++;
if (now - lastFpsUpdate >= 1000000000){
lastFpsCount = fpsCount;
fpsCount = 0;
lastFpsUpdate = now;
}
}
}
};
@@ -256,6 +266,13 @@ public class CanvasController {
}
}
private void drawFps(int fps){
gc.setFill(Color.BLACK);
gc.setFont(new Font(14));
gc.setLineWidth(3);
gc.fillText(fps + " FPS", 5, 20);
}
/**
* Draws all the boats.
*/
-1
View File
@@ -152,7 +152,6 @@ public class Race {
* @param boat The boat that has finished the race
*/
public void setBoatFinished(Boat boat){
System.out.println(boat.getTeamName() + " finished");
this.finishingOrder.add(boat);
}