mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
added count for fps inside handle loop and displayed fps on the canvas #story[463]
This commit is contained in:
@@ -78,15 +78,19 @@ public class CanvasController {
|
|||||||
// overriding the handle so that it can clean canvas and redraw boats and course marks
|
// overriding the handle so that it can clean canvas and redraw boats and course marks
|
||||||
AnimationTimer timer = new AnimationTimer() {
|
AnimationTimer timer = new AnimationTimer() {
|
||||||
private long lastUpdate = 0;
|
private long lastUpdate = 0;
|
||||||
|
private long lastFpsUpdate = 0;
|
||||||
|
private int lastFpsCount = 0;
|
||||||
|
private int fpsCount = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(long now) {
|
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.clearRect(0, 0, canvas.getWidth(),canvas.getHeight());
|
||||||
gc.setFill(Color.SKYBLUE);
|
gc.setFill(Color.SKYBLUE);
|
||||||
gc.fillRect(0,0,canvas.getWidth(),canvas.getHeight());
|
gc.fillRect(0,0,canvas.getWidth(),canvas.getHeight());
|
||||||
drawCourse();
|
drawCourse();
|
||||||
drawBoats();
|
drawBoats();
|
||||||
|
drawFps(lastFpsCount);
|
||||||
|
|
||||||
// If race has started, draw the boats and play the timeline
|
// If race has started, draw the boats and play the timeline
|
||||||
if (race.getRaceTime() > 1){
|
if (race.getRaceTime() > 1){
|
||||||
@@ -98,6 +102,12 @@ public class CanvasController {
|
|||||||
pauseTimelines();
|
pauseTimelines();
|
||||||
}
|
}
|
||||||
lastUpdate = now;
|
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.
|
* Draws all the boats.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -152,7 +152,6 @@ public class Race {
|
|||||||
* @param boat The boat that has finished the race
|
* @param boat The boat that has finished the race
|
||||||
*/
|
*/
|
||||||
public void setBoatFinished(Boat boat){
|
public void setBoatFinished(Boat boat){
|
||||||
System.out.println(boat.getTeamName() + " finished");
|
|
||||||
this.finishingOrder.add(boat);
|
this.finishingOrder.add(boat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user