-
Notifications
You must be signed in to change notification settings - Fork 2
/
Ticker.pde
60 lines (51 loc) · 939 Bytes
/
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
/**
* A ticker class to manage animation timing.
*/
public class Ticker{
private int lastTime;
private float deltaTime;
private boolean isPaused;
private float totalTime;
public Ticker(){
reset();
}
public void reset(){
deltaTime = 0f;
lastTime = -1;
isPaused = false;
totalTime = 0f;
}
//
public void pause(){
isPaused = true;
}
public void resume(){
if(isPaused == true){
reset();
}
}
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;
totalTime += deltaTime;
}
}