-
Notifications
You must be signed in to change notification settings - Fork 1
/
Ticker.pde
89 lines (75 loc) · 1.48 KB
/
Ticker.pde
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* A ticker class to manage animation timing.
*/
public class Ticker{
private int lastTime;
private float deltaTime;
private boolean isPaused;
private float totalTime;
private boolean countingUp;
public Ticker(){
reset();
}
public void setDirection(int d){
countingUp = false;
}
public void reset(){
deltaTime = 0f;
lastTime = -1;
isPaused = false;
totalTime = 0f;
countingUp = true;
}
//
public void pause(){
isPaused = true;
}
public void resume(){
deltaTime = 0f;
lastTime = -1;
isPaused = false;
}
public void setTime(int min, int sec){
totalTime = min * 60 + sec;
}
/*
Format: 5.5 = 5 minutes 30 seconds
*/
public void setTime(float minutes){
int int_min = (int)minutes;
int sec = (int)((minutes - (float)int_min) * 60);
setTime( int_min, sec);
}
//public void setMinutes(int min){
// totalTime = min * 60;
//}
public float getTotalTime(){
return totalTime;
}
/*
*/
public float getDeltaSec(){
if(isPaused){
return 0;
}
return deltaTime;
}
/*
* Calculates how many seconds passed since the last call to this method.
*
*/
public void tick(){
if(lastTime == -1){
lastTime = millis();
}
int delta = millis() - lastTime;
lastTime = millis();
deltaTime = delta/1000f;
if(countingUp){
totalTime += deltaTime;
}
else{
totalTime -= deltaTime;
}
}
}