-
Notifications
You must be signed in to change notification settings - Fork 0
/
fpsTimer.js
58 lines (42 loc) · 1014 Bytes
/
fpsTimer.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class FpsTimer{
constructor(){
this.frameRate = 12;
this.lastFrameChange = 0;
this.frameDuration = 0;
this.calculateFrameDuration();
this.changeFlag = false;
this.playing = false;
}
calculateFrameDuration(){
this.frameDuration = 1000 / this.frameRate;
}
play(){
this.lastFrameChange = millis();
this.playing = true;
}
stop(){
this.playing = false;
}
update(){
if(this.playing){
let currentTime = millis();
if(currentTime - this.lastFrameChange > this.frameDuration){
this.changeFlag = true;
this.lastFrameChange = millis();
}
}
}
setFrameRate(fps){
this.frameRate = fps;
this.calculateFrameDuration();
}
lowerFlag(){
this.changeFlag = false;
}
checkChange(){
return this.changeFlag;
}
isPlaying(){
return this.playing;
}
}