@@ -16,8 +16,9 @@ public enum Direction {
16
16
private float duration ;
17
17
private int resetIndex ;
18
18
private float offset ;
19
+ private boolean randomOffset ;
19
20
20
- private AnimationFrames (int originX , int originY , Direction direction , Animation .PlayMode playMode , int frames , float duration , int resetIndex , float offset ) {
21
+ private AnimationFrames (int originX , int originY , Direction direction , Animation .PlayMode playMode , int frames , float duration , int resetIndex , float offset , boolean randomOffset ) {
21
22
this .originX = originX ;
22
23
this .originY = originY ;
23
24
this .direction = direction ;
@@ -26,12 +27,17 @@ private AnimationFrames(int originX, int originY, Direction direction, Animation
26
27
this .duration = duration ;
27
28
this .resetIndex = resetIndex ;
28
29
this .offset = offset ;
30
+ this .randomOffset = randomOffset ;
29
31
}
30
32
31
33
public float getOffset () {
32
34
return offset ;
33
35
}
34
36
37
+ public boolean isRandomOffset () {
38
+ return randomOffset ;
39
+ }
40
+
35
41
public void setOriginX (int originX ) {
36
42
this .originX = originX ;
37
43
}
@@ -101,6 +107,7 @@ public static class AnimationFramesBuilder {
101
107
private float duration = 1f ;
102
108
private int resetIndex = 0 ;
103
109
private float offset = 0 ;
110
+ private boolean randomOffset ;
104
111
105
112
private AnimationFramesBuilder () {
106
113
@@ -143,11 +150,8 @@ public AnimationFramesBuilder offset(float offsetInMilliseconds) {
143
150
}
144
151
145
152
public AnimationFramesBuilder randomOffset () {
146
- if (frames > 0 ) {
147
- return this .offset ((float ) (Math .random () * (this .duration * this .frames )));
148
- } else {
149
- return this .offset ((float ) (Math .random () * (this .duration * 8f )));
150
- }
153
+ randomOffset = true ;
154
+ return this ;
151
155
}
152
156
153
157
public AnimationFrames build () {
@@ -159,7 +163,8 @@ public AnimationFrames build() {
159
163
frames ,
160
164
duration ,
161
165
resetIndex ,
162
- offset
166
+ offset ,
167
+ randomOffset
163
168
);
164
169
}
165
170
0 commit comments