/**
* Sets the current time on our AnimationClip instance, accounting for looping and time scaling.
*/
public boolean setTime(final double globalTime, final AnimationManager manager) {
final AnimationClipInstance instance = manager.getClipInstance(_clip);
if (instance.isActive()) {
double clockTime = instance.getTimeScale() * (globalTime - instance.getStartTime());
final double maxTime = _clip.getMaxTimeIndex();
if (maxTime <= 0) {
return false;
}
// Check for looping.
if (instance.getLoopCount() == Integer.MAX_VALUE || instance.getLoopCount() > 1
&& maxTime * instance.getLoopCount() >= Math.abs(clockTime)) {
if (clockTime < 0) {
clockTime = maxTime + clockTime % maxTime;
} else {
clockTime %= maxTime;
}
} else if (clockTime < 0) {
clockTime = maxTime + clockTime;
}
// Check for past max time
if (clockTime > maxTime || clockTime < 0) {
clockTime = MathUtils.clamp(clockTime, 0, maxTime);
// signal to any listeners that we have ended our animation.
instance.fireAnimationFinished();
// deactivate this instance of the clip
instance.setActive(false);
}
// update the clip with the correct clip local time.
_clip.update(clockTime, instance);
}
return instance.isActive();
}