-
Notifications
You must be signed in to change notification settings - Fork 0
/
Transitionable.pde
78 lines (62 loc) · 1.41 KB
/
Transitionable.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
/**
* Class for objects whitch transition between frames in the app
*/
public abstract class Transitionable extends Obj {
// Set to true to begin transitioning!
public boolean trans = false;
// Done transitioning
public boolean middle = false;
public boolean done = false;
public boolean paused = false;
protected void postSetup() {
super.postSetup();
m.transIn.reset();
m.transOut.reset();
}
protected void preUpdate() {
super.preUpdate();
if (middle && trans) {
transition();
}
}
protected void postUpdate() {
super.postUpdate();
if (!middle && trans) {
transition();
}
}
private void transition() {
if (paused) return;
if (!m.transIn.done) {
m.transIn.update();
if (m.transIn.beforeDone) {
middle = true;
shouldUpdate = false;
onTransOutBegin();
}
}
else {
if (!m.transOut.done) {
m.transOut.update();
}
}
if (m.transIn.done && m.transOut.done) {
// When the trans is done
onDone();
}
}
protected void clean() {
m.transIn.reset();
m.transOut.reset();
}
protected void onDone() {
trans = false;
done = true;
middle = false;
clean();
}
// Method whitch inheriting classes should implement
// for cleanup
protected void onTransOutBegin() {}
public Transitionable(Snap app) { super(app); }
}