Commit 9064e309 by Alexander Bazo

Fix fps display

parent 85a592f2
...@@ -25,6 +25,14 @@ class GameManger { ...@@ -25,6 +25,14 @@ class GameManger {
this.fps = fps; this.fps = fps;
} }
showFPS() {
this.shouldDisplayFrameRate = true;
}
hideFPS() {
this.shouldDisplayFrameRate = false;
}
setSize(width, height) { setSize(width, height) {
this.canvas.width = width; this.canvas.width = width;
this.canvas.height = height; this.canvas.height = height;
...@@ -59,7 +67,9 @@ class GameManger { ...@@ -59,7 +67,9 @@ 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(); if (this.shouldDisplayFrameRate === true) {
this.drawFrameRate();
}
this.setUpdateTime(); this.setUpdateTime();
} }
...@@ -91,11 +101,11 @@ class GameManger { ...@@ -91,11 +101,11 @@ class GameManger {
} }
drawFrameRate() { drawFrameRate() {
let fps = 1000 / lastDelta; let fps = parseInt(1000 / lastDelta);
this.context.beginPath(); this.context.beginPath();
this.context.font = "30px Arial"; this.context.font = "20px Arial";
this.context.fillStyle = FPS_COLOR; this.context.fillStyle = FPS_COLOR;
this.context.fillText(`FPS: ${fps}`, 20, 20); this.context.fillText(`FPS: ${fps}`, 30, 30);
this.context.closePath(); this.context.closePath();
} }
......
...@@ -3,7 +3,7 @@ class GazePoint { ...@@ -3,7 +3,7 @@ class GazePoint {
constructor(screenX, screenY, createdAt, id) { constructor(screenX, screenY, createdAt, id) {
this.screenX = screenX; this.screenX = screenX;
this.screenY = screenY; this.screenY = screenY;
this.createdAt = createdAt; this.createdAt = Date.now();
this.id = id || this.createdAt; this.id = id || this.createdAt;
} }
......
...@@ -5,22 +5,25 @@ var canvas, gm; ...@@ -5,22 +5,25 @@ var canvas, gm;
class StarGazer { class StarGazer {
init(config) { init(config) {
Logger.log("Starting StarGazer game"); Logger.log("Starting StarGazer game");
canvas = config.canvas; canvas = config.canvas;
gm = new GameManager(); gm = new GameManager();
gm.setCanvas(canvas); gm.setCanvas(canvas);
gm.setFrameRate(config.fps); gm.setFrameRate(config.fps);
gm.setSize(config.width, config.height); if (config.showFPS === true) {
gm.start(); gm.showFPS();
} }
gm.setSize(config.width, config.height);
gm.start();
}
onGazeUpdate(gazePoint) { onGazeUpdate(gazePoint) {
gazePoint.linkTo(canvas); gazePoint.linkTo(canvas);
if(gazePoint.hasLink) { if (gazePoint.hasLink) {
gm.addGazePoint(gazePoint); gm.addGazePoint(gazePoint);
} }
} }
} }
......
...@@ -23,6 +23,7 @@ function initStarGazer() { ...@@ -23,6 +23,7 @@ function initStarGazer() {
StarGazer.init({ StarGazer.init({
canvas: document.querySelector("canvas"), canvas: document.querySelector("canvas"),
fps: 60, fps: 60,
showFPS: true,
width: 800, width: 800,
height: 800, height: 800,
}); });
...@@ -41,7 +42,7 @@ function onGazeDataAvailable(event) { ...@@ -41,7 +42,7 @@ function onGazeDataAvailable(event) {
} }
function onDisconnected(event) { function onDisconnected(event) {
console.log(event); console.log( event);
} }
init(); init();
\ 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