Commit 85a592f2 by Alexander Bazo

Add fps counter

parent 512fc907
...@@ -3,6 +3,7 @@ import Logger from "../utils/Logger.js"; ...@@ -3,6 +3,7 @@ import Logger from "../utils/Logger.js";
const BACKGROUND_COLOR = "rgba(30,30,30,0.5)", const BACKGROUND_COLOR = "rgba(30,30,30,0.5)",
DEFAULT_GAZE_POINT_RADIUS = 10, DEFAULT_GAZE_POINT_RADIUS = 10,
DEFAULT_GAZE_POINT_COLOR = "#ff007b", DEFAULT_GAZE_POINT_COLOR = "#ff007b",
FPS_COLOR = "#ffbb00",
MAX_GAZE_POINT_AGE = 500; MAX_GAZE_POINT_AGE = 500;
var lastUpdate, var lastUpdate,
...@@ -58,6 +59,7 @@ class GameManger { ...@@ -58,6 +59,7 @@ class GameManger {
this.updateGazePoints(); this.updateGazePoints();
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height); this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
this.drawGazePoints(); this.drawGazePoints();
this.drawFrameRate();
this.setUpdateTime(); this.setUpdateTime();
} }
...@@ -76,7 +78,8 @@ class GameManger { ...@@ -76,7 +78,8 @@ class GameManger {
this.context.fillStyle = DEFAULT_GAZE_POINT_COLOR; this.context.fillStyle = DEFAULT_GAZE_POINT_COLOR;
for (let item of this.gazePoints) { for (let item of this.gazePoints) {
this.context.save(); this.context.save();
this.context.globalAlpha = 1 - (now - item[1].createdAt) / MAX_GAZE_POINT_AGE; this.context.globalAlpha = 1 - (now - item[1].createdAt) /
MAX_GAZE_POINT_AGE;
this.context.beginPath(); this.context.beginPath();
this.context.ellipse(item[1].targetX, item[1].targetY, this.context.ellipse(item[1].targetX, item[1].targetY,
DEFAULT_GAZE_POINT_RADIUS, DEFAULT_GAZE_POINT_RADIUS, Math.PI / 4, DEFAULT_GAZE_POINT_RADIUS, DEFAULT_GAZE_POINT_RADIUS, Math.PI / 4,
...@@ -87,6 +90,15 @@ class GameManger { ...@@ -87,6 +90,15 @@ class GameManger {
} }
} }
drawFrameRate() {
let fps = 1000 / lastDelta;
this.context.beginPath();
this.context.font = "30px Arial";
this.context.fillStyle = FPS_COLOR;
this.context.fillText(`FPS: ${fps}`, 20, 20);
this.context.closePath();
}
} }
export default GameManger; export default GameManger;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment