-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPauseTimer.ts
More file actions
56 lines (45 loc) · 1.24 KB
/
PauseTimer.ts
File metadata and controls
56 lines (45 loc) · 1.24 KB
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
import {_, Main} from "../main";
import {TweenMax} from "./Application";
export class PauseTimer {
private paused: boolean = false;
private pauseStart: number = 0;
private totalPauseTime: number = 0;
private intervals: Array<any> = [];
private timeouts: Array<any> = [];
public since(time: number): number {
return this.getTimer() - time
}
public process() {
}
public removeListener(f: any) {
for (let i = 0; i < this.intervals.length; ++i) {
if (this.intervals[i] == f) {
this.intervals.splice(i, 1);
i--;
}
}
for (let i = 0; i < this.timeouts.length; ++i) {
if (this.timeouts[i] == f) {
this.timeouts.splice(i, 1);
i--;
}
}
}
public getTimer() {
return _.time - this.totalPauseTime;
}
public isPaused() {
return this.paused;
}
public pause() {
this.pauseStart = _.time;
TweenMax.pauseAll();
this.paused= true;
}
public resume() {
if (!this.paused) return;
this.totalPauseTime += (_.time - this.pauseStart);
TweenMax.resumeAll();
this.paused = false;
}
}