-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFps.js
44 lines (33 loc) · 781 Bytes
/
Fps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';
function Fps() {
// fps
var fpsRate = 50;
var fpsCount = 0;
this.val;
var lastCalledTime = Date.now();
this.update = function() {
var delta = (new Date().getTime() - lastCalledTime)/1000;
lastCalledTime = Date.now();
this.val = Math.round(1/delta);
if (game.advanced.active && game.started) {
this.drawFps();
}
};
this.drawFps = function() {
fpsCount++;
if (fpsCount > fpsRate) {
var fpsText = {
x: game.width - 35,
y: game.height - 10
};
fpsCount = 0;
this.context.textAlign="left";
this.context.font="9px Verdana";
this.context.fillStyle="#888";
this.context.clearRect(fpsText.x-2, fpsText.y-10, 40, 15);
this.context.fillText('fps:'+this.val,fpsText.x,fpsText.y);
}
};
}
function FPS() {
}