-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.js
More file actions
37 lines (30 loc) · 719 Bytes
/
Timer.js
File metadata and controls
37 lines (30 loc) · 719 Bytes
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
var Timer = EventTarget.$extend({
_timer: null,
_stats: null,
_logFps: false,
frame: 0,
fps: 25,
__init__: function(fps, logFps) {
this.fps = fps || this.fps;
this._logFps = logFps || this._logFps;
},
start: function () {
if (this._logFps) {
this._stats = window.setInterval(bind(this.onStats, this), 1000);
}
this._timer = window.setInterval(bind(this.onFrame, this), 1000 / this.fps);
},
stop: function () {
window.clearInterval(this._timer);
if (this._logFps) {
window.clearInterval(this._stats);
}
},
onFrame: function () {
this.fire('frame');
this.frame++;
},
onStats: function() {
console.log('FPS: ', this.frame);
}
});