@@ -15,15 +15,21 @@ public enum Direction {
15
15
private int frames ;
16
16
private float duration ;
17
17
private int resetIndex ;
18
+ private float offset ;
18
19
19
- private AnimationFrames (int originX , int originY , Direction direction , Animation .PlayMode playMode , int frames , float duration , int resetIndex ) {
20
+ private AnimationFrames (int originX , int originY , Direction direction , Animation .PlayMode playMode , int frames , float duration , int resetIndex , float offset ) {
20
21
this .originX = originX ;
21
22
this .originY = originY ;
22
23
this .direction = direction ;
23
24
this .playMode = playMode ;
24
25
this .frames = frames ;
25
26
this .duration = duration ;
26
27
this .resetIndex = resetIndex ;
28
+ this .offset = offset ;
29
+ }
30
+
31
+ public float getOffset () {
32
+ return offset ;
27
33
}
28
34
29
35
public void setOriginX (int originX ) {
@@ -94,6 +100,7 @@ public static class AnimationFramesBuilder {
94
100
private int frames = 1 ;
95
101
private float duration = 1f ;
96
102
private int resetIndex = 0 ;
103
+ private float offset = 0 ;
97
104
98
105
private AnimationFramesBuilder () {
99
106
@@ -130,6 +137,19 @@ public AnimationFramesBuilder resetIndex(int resetIndex) {
130
137
return this ;
131
138
}
132
139
140
+ public AnimationFramesBuilder offset (float offsetInMilliseconds ) {
141
+ this .offset = offsetInMilliseconds ;
142
+ return this ;
143
+ }
144
+
145
+ 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
+ }
151
+ }
152
+
133
153
public AnimationFrames build () {
134
154
return new AnimationFrames (
135
155
originX ,
@@ -138,7 +158,8 @@ public AnimationFrames build() {
138
158
playMode ,
139
159
frames ,
140
160
duration ,
141
- resetIndex
161
+ resetIndex ,
162
+ offset
142
163
);
143
164
}
144
165
0 commit comments