This commit is contained in:
Collin Smith 2019-11-06 13:13:04 -08:00
parent 223efec103
commit 5361d80864
2 changed files with 24 additions and 6 deletions

View File

@ -43,6 +43,8 @@ public class Animation extends BaseDrawable {
private COF cof;
private BBox box;
private boolean highlighted;
private int startIndex;
private int endIndex;
private IntMap<Array<AnimationListener>> animationListeners;
@ -62,6 +64,8 @@ public class Animation extends BaseDrawable {
clamp = true;
frameDuration = FRAME_DURATION;
box = new BBox();
startIndex = 0;
endIndex = numFrames;
animationListeners = EMPTY_MAP;
}
@ -97,6 +101,9 @@ public class Animation extends BaseDrawable {
elapsedTime = 0;
//}
startIndex = 0;
endIndex = numFrames;
return true;
}
@ -200,7 +207,7 @@ public class Animation extends BaseDrawable {
}
public boolean isFinished() {
return frame == numFrames - 1;
return frame == endIndex - 1;
}
public boolean isLooping() {
@ -216,7 +223,17 @@ public class Animation extends BaseDrawable {
}
public void setClamp(boolean b) {
setClamp(b, 0, numFrames);
}
public void setClamp(int startIndex, int endIndex) {
setClamp(true, startIndex, endIndex);
}
public void setClamp(boolean b, int startIndex, int endIndex) {
clamp = b;
this.startIndex = startIndex;
this.endIndex = endIndex;
}
public boolean isHighlighted() {
@ -284,11 +301,12 @@ public class Animation extends BaseDrawable {
}
public int getKeyFrameIndex(float stateTime) {
if (numFrames <= 1) return 0;
int frameRange = endIndex - startIndex;
if (frameRange <= 1) return startIndex;
int frameNumber = (int) (stateTime / frameDuration);
return looping
? frameNumber % numFrames
: Math.min(clamp ? numFrames - 1 : numFrames, frameNumber);
? startIndex + (frameNumber % frameRange)
: startIndex + Math.min(clamp ? frameRange - 1 : frameRange, frameNumber);
}
public void act() {
@ -299,7 +317,7 @@ public class Animation extends BaseDrawable {
elapsedTime += delta;
frame = getKeyFrameIndex(elapsedTime);
notifyListeners(frame);
if (frame == numFrames - 1) notifyAnimationFinished();
if (frame == endIndex - 1) notifyAnimationFinished();
}
public void drawDebug(ShapeRenderer shapes, float x, float y) {

View File

@ -299,7 +299,7 @@ public class QuestsPanel extends WidgetGroup implements Disposable {
addActor(background);
anim = Animation.newAnimation(questicons[q]);
anim.setClamp(true);
anim.setClamp(FRAME_UP, FRAME_DOWN);
anim.setFrameDuration(Float.MAX_VALUE);
AnimationWrapper animWrapper = new AnimationWrapper(anim);
animWrapper.setPosition(5, 4);