From 5361d808643b208b04f817be1a08a7eae3b5d81f Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Wed, 6 Nov 2019 13:13:04 -0800 Subject: [PATCH] Closes #34 --- core/src/com/riiablo/codec/Animation.java | 28 +++++++++++++++++---- core/src/com/riiablo/panel/QuestsPanel.java | 2 +- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/core/src/com/riiablo/codec/Animation.java b/core/src/com/riiablo/codec/Animation.java index 5b4df2b7..2fd7ac02 100644 --- a/core/src/com/riiablo/codec/Animation.java +++ b/core/src/com/riiablo/codec/Animation.java @@ -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> 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) { diff --git a/core/src/com/riiablo/panel/QuestsPanel.java b/core/src/com/riiablo/panel/QuestsPanel.java index 537f7cab..41821d7c 100644 --- a/core/src/com/riiablo/panel/QuestsPanel.java +++ b/core/src/com/riiablo/panel/QuestsPanel.java @@ -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);