-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimemanager.js
68 lines (68 loc) · 1.71 KB
/
timemanager.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
59
60
61
62
63
64
65
66
67
68
var gdjs;
(function(gdjs2) {
class TimeManager {
constructor() {
this._elapsedTime = 0;
this._timeScale = 1;
this._timeFromStart = 0;
this._firstFrame = true;
this._timers = new Hashtable();
this._firstUpdateDone = false;
this.reset();
}
reset() {
this._elapsedTime = 0;
this._timeScale = 1;
this._timeFromStart = 0;
this._firstFrame = true;
this._timers = new Hashtable();
}
update(elapsedTime, minimumFPS) {
if (this._firstUpdateDone) {
this._firstFrame = false;
}
this._firstUpdateDone = true;
this._elapsedTime = Math.min(elapsedTime, 1e3 / minimumFPS);
this._elapsedTime *= this._timeScale;
for (const name in this._timers.items) {
if (this._timers.items.hasOwnProperty(name)) {
this._timers.items[name].updateTime(this._elapsedTime);
}
}
this._timeFromStart += this._elapsedTime;
}
setTimeScale(timeScale) {
if (timeScale >= 0) {
this._timeScale = timeScale;
}
}
getTimeScale() {
return this._timeScale;
}
getTimeFromStart() {
return this._timeFromStart;
}
isFirstFrame() {
return this._firstFrame;
}
getElapsedTime() {
return this._elapsedTime;
}
addTimer(name) {
this._timers.put(name, new gdjs2.Timer(name));
}
hasTimer(name) {
return this._timers.containsKey(name);
}
getTimer(name) {
return this._timers.get(name);
}
removeTimer(name) {
if (this._timers.containsKey(name)) {
this._timers.remove(name);
}
}
}
gdjs2.TimeManager = TimeManager;
})(gdjs || (gdjs = {}));
//# sourceMappingURL=timemanager.js.map