public void apply (Skeleton skeleton, float time, float alpha) {
float[] frames = this.frames;
if (time < frames[0]) return; // Time is before first frame.
Color color = skeleton.slots.get(slotIndex).color;
if (time >= frames[frames.length - 5]) { // Time is after last frame.
int i = frames.length - 1;
float r = frames[i - 3];
float g = frames[i - 2];
float b = frames[i - 1];
float a = frames[i];
color.set(r, g, b, a);
return;
}
// Interpolate between the last frame and the current frame.
int frameIndex = binarySearch(frames, time, 5);
float lastFrameR = frames[frameIndex - 4];
float lastFrameG = frames[frameIndex - 3];
float lastFrameB = frames[frameIndex - 2];
float lastFrameA = frames[frameIndex - 1];
float frameTime = frames[frameIndex];
float percent = MathUtils.clamp(1 - (time - frameTime) / (frames[frameIndex + LAST_FRAME_TIME] - frameTime), 0, 1);
percent = getCurvePercent(frameIndex / 5 - 1, percent);
float r = lastFrameR + (frames[frameIndex + FRAME_R] - lastFrameR) * percent;
float g = lastFrameG + (frames[frameIndex + FRAME_G] - lastFrameG) * percent;
float b = lastFrameB + (frames[frameIndex + FRAME_B] - lastFrameB) * percent;
float a = lastFrameA + (frames[frameIndex + FRAME_A] - lastFrameA) * percent;
if (alpha < 1)
color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha);
else
color.set(r, g, b, a);
}