Follow-up from my thread
here:
The source code for Animation.restart():
Code:
public void restart() {
if (frames.size() == 0) {
return;
}
stopped = false;
currentFrame = 0;
nextChange = (int) (((Frame) frames.get(0)).duration / speed);
firstUpdate = true;
lastUpdate = 0;
}
If at the time restart() is called the animation is playing backwards (e.g. because pingPong is set to true), then the next call to nextFrame() will throw an ArrayIndexOutOfBoundsException.
Excerpt from nextFrame()'s code:
Code:
private void nextFrame(long delta) {
[...]
currentFrame = (currentFrame + direction) % frames.size(); //currentFrame will be -1
if (pingPong) { // too late to check here
if ((currentFrame == 0) || (currentFrame == frames.size()-1)) {
direction = -direction;
}
}
int realDuration = (int) (((Frame) frames.get(currentFrame)).duration / speed); //frames.get() will throw the exception
[...]
}
Should be a trivial fix, but it confused the hell out of me at first.