mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Better timelines.
This commit is contained in:
parent
280024a685
commit
42e3b95e33
@ -290,9 +290,9 @@ public class Animation {
|
|||||||
if (setupPose)
|
if (setupPose)
|
||||||
bone.rotation = bone.data.rotation + frames[frames.length + PREV_ROTATION] * alpha;
|
bone.rotation = bone.data.rotation + frames[frames.length + PREV_ROTATION] * alpha;
|
||||||
else {
|
else {
|
||||||
float amount = bone.data.rotation + frames[frames.length + PREV_ROTATION] - bone.rotation;
|
float r = bone.data.rotation + frames[frames.length + PREV_ROTATION] - bone.rotation;
|
||||||
amount -= (16384 - (int)(16384.499999999996 - amount / 360)) * 360;
|
r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360;
|
||||||
bone.rotation += amount * alpha;
|
bone.rotation += r * alpha;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -303,16 +303,16 @@ public class Animation {
|
|||||||
float frameTime = frames[frame];
|
float frameTime = frames[frame];
|
||||||
float percent = getCurvePercent((frame >> 1) - 1, 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
|
float percent = getCurvePercent((frame >> 1) - 1, 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
|
||||||
|
|
||||||
float amount = frames[frame + ROTATION] - prevRotation;
|
float r = frames[frame + ROTATION] - prevRotation;
|
||||||
amount -= (16384 - (int)(16384.499999999996 - amount / 360)) * 360;
|
r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360;
|
||||||
amount = prevRotation + amount * percent;
|
r = prevRotation + r * percent;
|
||||||
if (setupPose) {
|
if (setupPose) {
|
||||||
amount -= (16384 - (int)(16384.499999999996 - amount / 360)) * 360;
|
r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360;
|
||||||
bone.rotation = bone.data.rotation + amount * alpha;
|
bone.rotation = bone.data.rotation + r * alpha;
|
||||||
} else {
|
} else {
|
||||||
amount = bone.data.rotation + amount - bone.rotation;
|
r = bone.data.rotation + r - bone.rotation;
|
||||||
amount -= (16384 - (int)(16384.499999999996 - amount / 360)) * 360;
|
r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360;
|
||||||
bone.rotation += amount * alpha;
|
bone.rotation += r * alpha;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -362,10 +362,14 @@ public class Animation {
|
|||||||
|
|
||||||
Bone bone = skeleton.bones.get(boneIndex);
|
Bone bone = skeleton.bones.get(boneIndex);
|
||||||
|
|
||||||
float x, y;
|
|
||||||
if (time >= frames[frames.length - ENTRIES]) { // Time is after last frame.
|
if (time >= frames[frames.length - ENTRIES]) { // Time is after last frame.
|
||||||
x = frames[frames.length + PREV_X];
|
if (setupPose) {
|
||||||
y = frames[frames.length + PREV_Y];
|
bone.x = bone.data.x + frames[frames.length + PREV_X] * alpha;
|
||||||
|
bone.y = bone.data.y + frames[frames.length + PREV_Y] * alpha;
|
||||||
|
} else {
|
||||||
|
bone.x += (bone.data.x + frames[frames.length + PREV_X] - bone.x) * alpha;
|
||||||
|
bone.y += (bone.data.y + frames[frames.length + PREV_Y] - bone.y) * alpha;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Interpolate between the previous frame and the current frame.
|
// Interpolate between the previous frame and the current frame.
|
||||||
int frame = binarySearch(frames, time, ENTRIES);
|
int frame = binarySearch(frames, time, ENTRIES);
|
||||||
@ -375,9 +379,8 @@ public class Animation {
|
|||||||
float percent = getCurvePercent(frame / ENTRIES - 1,
|
float percent = getCurvePercent(frame / ENTRIES - 1,
|
||||||
1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
|
1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
|
||||||
|
|
||||||
x = prevX + (frames[frame + X] - prevX) * percent;
|
float x = prevX + (frames[frame + X] - prevX) * percent;
|
||||||
y = prevY + (frames[frame + Y] - prevY) * percent;
|
float y = prevY + (frames[frame + Y] - prevY) * percent;
|
||||||
}
|
|
||||||
if (setupPose) {
|
if (setupPose) {
|
||||||
bone.x = bone.data.x + x * alpha;
|
bone.x = bone.data.x + x * alpha;
|
||||||
bone.y = bone.data.y + y * alpha;
|
bone.y = bone.data.y + y * alpha;
|
||||||
@ -387,6 +390,7 @@ public class Animation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static public class ScaleTimeline extends TranslateTimeline {
|
static public class ScaleTimeline extends TranslateTimeline {
|
||||||
public ScaleTimeline (int frameCount) {
|
public ScaleTimeline (int frameCount) {
|
||||||
@ -406,8 +410,8 @@ public class Animation {
|
|||||||
|
|
||||||
float x, y;
|
float x, y;
|
||||||
if (time >= frames[frames.length - ENTRIES]) { // Time is after last frame.
|
if (time >= frames[frames.length - ENTRIES]) { // Time is after last frame.
|
||||||
x = frames[frames.length + PREV_X];
|
x = frames[frames.length + PREV_X] * bone.data.scaleX;
|
||||||
y = frames[frames.length + PREV_Y];
|
y = frames[frames.length + PREV_Y] * bone.data.scaleY;
|
||||||
} else {
|
} else {
|
||||||
// Interpolate between the previous frame and the current frame.
|
// Interpolate between the previous frame and the current frame.
|
||||||
int frame = binarySearch(frames, time, ENTRIES);
|
int frame = binarySearch(frames, time, ENTRIES);
|
||||||
@ -417,11 +421,9 @@ public class Animation {
|
|||||||
float percent = getCurvePercent(frame / ENTRIES - 1,
|
float percent = getCurvePercent(frame / ENTRIES - 1,
|
||||||
1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
|
1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
|
||||||
|
|
||||||
x = prevX + (frames[frame + X] - prevX) * percent;
|
x = (prevX + (frames[frame + X] - prevX) * percent) * bone.data.scaleX;
|
||||||
y = prevY + (frames[frame + Y] - prevY) * percent;
|
y = (prevY + (frames[frame + Y] - prevY) * percent) * bone.data.scaleY;
|
||||||
}
|
}
|
||||||
x *= bone.data.scaleX;
|
|
||||||
y *= bone.data.scaleY;
|
|
||||||
if (alpha == 1) {
|
if (alpha == 1) {
|
||||||
bone.scaleX = x;
|
bone.scaleX = x;
|
||||||
bone.scaleY = y;
|
bone.scaleY = y;
|
||||||
@ -464,8 +466,13 @@ public class Animation {
|
|||||||
|
|
||||||
Bone bone = skeleton.bones.get(boneIndex);
|
Bone bone = skeleton.bones.get(boneIndex);
|
||||||
if (time >= frames[frames.length - ENTRIES]) { // Time is after last frame.
|
if (time >= frames[frames.length - ENTRIES]) { // Time is after last frame.
|
||||||
|
if (setupPose) {
|
||||||
|
bone.shearX = bone.data.shearX + frames[frames.length + PREV_X] * alpha;
|
||||||
|
bone.shearY = bone.data.shearY + frames[frames.length + PREV_Y] * alpha;
|
||||||
|
} else {
|
||||||
bone.shearX += (bone.data.shearX + frames[frames.length + PREV_X] - bone.shearX) * alpha;
|
bone.shearX += (bone.data.shearX + frames[frames.length + PREV_X] - bone.shearX) * alpha;
|
||||||
bone.shearY += (bone.data.shearY + frames[frames.length + PREV_Y] - bone.shearY) * alpha;
|
bone.shearY += (bone.data.shearY + frames[frames.length + PREV_Y] - bone.shearY) * alpha;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -476,8 +483,15 @@ public class Animation {
|
|||||||
float frameTime = frames[frame];
|
float frameTime = frames[frame];
|
||||||
float percent = getCurvePercent(frame / ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
|
float percent = getCurvePercent(frame / ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime));
|
||||||
|
|
||||||
bone.shearX += (bone.data.shearX + (prevX + (frames[frame + X] - prevX) * percent) - bone.shearX) * alpha;
|
float x = prevX + (frames[frame + X] - prevX) * percent;
|
||||||
bone.shearY += (bone.data.shearY + (prevY + (frames[frame + Y] - prevY) * percent) - bone.shearY) * alpha;
|
float y = prevY + (frames[frame + Y] - prevY) * percent;
|
||||||
|
if (setupPose) {
|
||||||
|
bone.shearX = bone.data.shearX + x * alpha;
|
||||||
|
bone.shearY = bone.data.shearY + y * alpha;
|
||||||
|
} else {
|
||||||
|
bone.shearX += (bone.data.shearX + x - bone.shearX) * alpha;
|
||||||
|
bone.shearY += (bone.data.shearY + y - bone.shearY) * alpha;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -549,11 +563,14 @@ public class Animation {
|
|||||||
b += (frames[frame + B] - b) * percent;
|
b += (frames[frame + B] - b) * percent;
|
||||||
a += (frames[frame + A] - a) * percent;
|
a += (frames[frame + A] - a) * percent;
|
||||||
}
|
}
|
||||||
Color color = skeleton.slots.get(slotIndex).color;
|
Slot slot = skeleton.slots.get(slotIndex);
|
||||||
if (alpha < 1)
|
if (alpha == 1)
|
||||||
|
slot.color.set(r, g, b, a);
|
||||||
|
else {
|
||||||
|
Color color = slot.color;
|
||||||
|
if (setupPose) color.set(slot.data.color);
|
||||||
color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha);
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -600,6 +617,13 @@ public class Animation {
|
|||||||
|
|
||||||
public void apply (Skeleton skeleton, float lastTime, float time, Array<Event> events, float alpha, boolean setupPose,
|
public void apply (Skeleton skeleton, float lastTime, float time, Array<Event> events, float alpha, boolean setupPose,
|
||||||
boolean mixingOut) {
|
boolean mixingOut) {
|
||||||
|
if (mixingOut && setupPose) {
|
||||||
|
Slot slot = skeleton.slots.get(slotIndex);
|
||||||
|
String attachmentName = slot.data.attachmentName;
|
||||||
|
slot.setAttachment(attachmentName == null ? null : skeleton.getAttachment(slotIndex, attachmentName));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
float[] frames = this.frames;
|
float[] frames = this.frames;
|
||||||
if (time < frames[0]) return; // Time is before first frame.
|
if (time < frames[0]) return; // Time is before first frame.
|
||||||
|
|
||||||
|
|||||||
@ -399,7 +399,7 @@ public class AnimationState {
|
|||||||
entry.loop = loop;
|
entry.loop = loop;
|
||||||
|
|
||||||
entry.eventThreshold = 0;
|
entry.eventThreshold = 0;
|
||||||
entry.attachmentThreshold = 0;
|
entry.attachmentThreshold = 1;
|
||||||
entry.drawOrderThreshold = 0;
|
entry.drawOrderThreshold = 0;
|
||||||
|
|
||||||
entry.delay = 0;
|
entry.delay = 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user