diff --git a/spine-libgdx/src/com/esotericsoftware/spine/Animation.java b/spine-libgdx/src/com/esotericsoftware/spine/Animation.java index eee809065..e5f65a689 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/Animation.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/Animation.java @@ -115,8 +115,9 @@ public class Animation { /** Base class for frames that use an interpolation bezier curve. */ abstract static public class CurveTimeline implements Timeline { - static private final float LINEAR = 0; - static private final float STEPPED = -1; + static public final float LINEAR = 0; + static public final float STEPPED = -1; + static public final float BEZIER = -2; static private final int BEZIER_SEGMENTS = 10; private final float[] curves; // dfx, dfy, ddfx, ddfy, dddfx, dddfy, ... @@ -137,6 +138,15 @@ public class Animation { curves[frameIndex * 6] = STEPPED; } + public float getCurveType (int frameIndex) { + int index = frameIndex * 6; + if (index == curves.length) return LINEAR; + float type = curves[index]; + if (type == LINEAR) return LINEAR; + if (type == STEPPED) return STEPPED; + return BEZIER; + } + /** Sets the control handle positions for an interpolation bezier curve used to transition from this keyframe to the next. * cx1 and cx2 are from 0 to 1, representing the percent of time between the two keyframes. cy1 and cy2 are the percent of * the difference between the keyframe's values. */ diff --git a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java index 80074efce..971e9b416 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java @@ -215,9 +215,9 @@ public class SkeletonBinary { case TIMELINE_ROTATE: { RotateTimeline timeline = new RotateTimeline(keyCount); timeline.setBoneIndex(boneIndex); - for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) { - timeline.setFrame(keyframeIndex, input.readFloat(), input.readFloat()); - if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline); + for (int frameIndex = 0; frameIndex < keyCount; frameIndex++) { + timeline.setFrame(frameIndex, input.readFloat(), input.readFloat()); + if (frameIndex < keyCount - 1) readCurve(input, frameIndex, timeline); } timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[keyCount * 2 - 2]); @@ -234,10 +234,10 @@ public class SkeletonBinary { timelineScale = scale; } timeline.setBoneIndex(boneIndex); - for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) { - timeline.setFrame(keyframeIndex, input.readFloat(), input.readFloat() * timelineScale, input.readFloat() + for (int frameIndex = 0; frameIndex < keyCount; frameIndex++) { + timeline.setFrame(frameIndex, input.readFloat(), input.readFloat() * timelineScale, input.readFloat() * timelineScale); - if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline); + if (frameIndex < keyCount - 1) readCurve(input, frameIndex, timeline); } timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[keyCount * 3 - 3]); @@ -260,11 +260,11 @@ public class SkeletonBinary { case TIMELINE_COLOR: { ColorTimeline timeline = new ColorTimeline(keyCount); timeline.setSlotIndex(slotIndex); - for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) { + for (int frameIndex = 0; frameIndex < keyCount; frameIndex++) { float time = input.readFloat(); Color.rgba8888ToColor(tempColor, input.readInt()); - timeline.setFrame(keyframeIndex, time, tempColor.r, tempColor.g, tempColor.b, tempColor.a); - if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline); + timeline.setFrame(frameIndex, time, tempColor.r, tempColor.g, tempColor.b, tempColor.a); + if (frameIndex < keyCount - 1) readCurve(input, frameIndex, timeline); } timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[keyCount * 5 - 5]); @@ -273,8 +273,8 @@ public class SkeletonBinary { case TIMELINE_ATTACHMENT: AttachmentTimeline timeline = new AttachmentTimeline(keyCount); timeline.setSlotIndex(slotIndex); - for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) - timeline.setFrame(keyframeIndex, input.readFloat(), input.readString()); + for (int frameIndex = 0; frameIndex < keyCount; frameIndex++) + timeline.setFrame(frameIndex, input.readFloat(), input.readString()); timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[keyCount - 1]); break; @@ -291,14 +291,18 @@ public class SkeletonBinary { skeletonData.addAnimation(new Animation(name, timelines, duration)); } - private void readCurve (DataInput input, int keyframeIndex, CurveTimeline timeline) throws IOException { + private void readCurve (DataInput input, int frameIndex, CurveTimeline timeline) throws IOException { switch (input.readByte()) { case CURVE_STEPPED: - timeline.setStepped(keyframeIndex); + timeline.setStepped(frameIndex); break; case CURVE_BEZIER: - timeline.setCurve(keyframeIndex, input.readFloat(), input.readFloat(), input.readFloat(), input.readFloat()); + setCurve(timeline, frameIndex, input.readFloat(), input.readFloat(), input.readFloat(), input.readFloat()); break; } } + + void setCurve (CurveTimeline timeline, int frameIndex, float cx1, float cy1, float cx2, float cy2) { + timeline.setCurve(frameIndex, cx1, cy1, cx2, cy2); + } } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java index e111bff61..dd8358b5f 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java @@ -269,7 +269,7 @@ public class SkeletonJson { skeletonData.addAnimation(new Animation(name, timelines, duration)); } - private void readCurve (CurveTimeline timeline, int frameIndex, JsonValue valueMap) { + void readCurve (CurveTimeline timeline, int frameIndex, JsonValue valueMap) { JsonValue curve = valueMap.get("curve"); if (curve == null) return; if (curve.isString() && curve.asString().equals("stepped"))