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
|
||||
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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user