-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimatorClass.js
More file actions
68 lines (61 loc) · 1.71 KB
/
animatorClass.js
File metadata and controls
68 lines (61 loc) · 1.71 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class Animator {
constructor(waitDelay, nFrames) {
this.nFrames = nFrames;
this.i = nFrames;
this.j = nFrames;
this.k = nFrames;
this.isWaiting = false;
this.waitDelay = waitDelay;
this.rotState = 0;
this.isActive = false;
}
update() {
if (!this.isActive) {
return;
}
if (this.isWaiting) {
if (millis() - this.waitStart < this.waitDelay) {
return;
}
this.isWaiting = false;
}
if (this.i == this.nFrames - 1) {
this.isWaiting = true;
this.waitStart = millis();
this.i += 1;
return;
}
if (this.j == this.nFrames - 1) {
this.isWaiting = true;
this.waitStart = millis();
this.j += 1;
return;
}
if (this.k == this.nFrames - 1) {
this.isActive = false;
this.rotState = 0;
this.k += 1;
return;
}
if (this.i < this.nFrames - 1) {
this.rotState = 1;
this.i += 1;
} else if (this.j < this.nFrames - 1){
this.rotState = 2;
this.j += 1;
} else if (this.k < this.nFrames - 1){
this.rotState = 3;
this.k += 1;
}
}
start() {
this.i = 0;
this.j = 0;
this.k = 0;
this.isActive = true;
this.isWaiting = true;
this.waitStart = millis();
}
isAnimating() { return this.isActive; }
getState() { return [this.i/this.nFrames, this.j/this.nFrames, this.k/this.nFrames, this.rotState]; }
}