apply method
void
apply(
- Skeleton skeleton,
- double lastTime,
- double time,
- List<
Event?> events, - double alpha,
- MixPose pose,
- MixDirection direction,
override
Implementation
@override
void apply(Skeleton skeleton, double lastTime, double time,
List<Event?> events, double alpha, MixPose pose, MixDirection direction) {
final Slot slot = skeleton.slots[slotIndex];
final Float32List frames = this.frames;
if (time < frames[0]) {
if (pose == MixPose.setup) {
slot.color.setFromColor(slot.data.color);
} else if (pose == MixPose.current) {
final Color? color = slot.color, setup = slot.data.color;
color!.add((setup!.r - color.r) * alpha, (setup.g - color.g) * alpha,
(setup.b - color.b) * alpha, (setup.a - color.a) * alpha);
}
return;
}
double r = 0.0, g = 0.0, b = 0.0, a = 0.0;
if (time >= frames[frames.length - ColorTimeline.entries]) {
// Time is after last frame.
final int i = frames.length;
r = frames[i + ColorTimeline.prevR];
g = frames[i + ColorTimeline.prevG];
b = frames[i + ColorTimeline.prevB];
a = frames[i + ColorTimeline.prevA];
} else {
// Interpolate between the previous frame and the current frame.
final int frame =
Animation.binarySearch(frames, time, ColorTimeline.entries);
r = frames[frame + ColorTimeline.prevR];
g = frames[frame + ColorTimeline.prevG];
b = frames[frame + ColorTimeline.prevB];
a = frames[frame + ColorTimeline.prevA];
final double frameTime = frames[frame];
final double percent = getCurvePercent(
frame ~/ ColorTimeline.entries - 1,
1 -
(time - frameTime) /
(frames[frame + ColorTimeline.prevTime] - frameTime));
r += (frames[frame + ColorTimeline.r] - r) * percent;
g += (frames[frame + ColorTimeline.g] - g) * percent;
b += (frames[frame + ColorTimeline.b] - b) * percent;
a += (frames[frame + ColorTimeline.a] - a) * percent;
}
if (alpha == 1) {
slot.color.set(r, g, b, a);
} else {
final Color color = slot.color;
if (pose == MixPose.setup) color.setFromColor(slot.data.color);
color.add((r - color.r) * alpha, (g - color.g) * alpha,
(b - color.b) * alpha, (a - color.a) * alpha);
}
}