diff --git a/spine-libgdx/src/com/esotericsoftware/spine/Animation.java b/spine-libgdx/src/com/esotericsoftware/spine/Animation.java index 92b9b119f..759e9a613 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/Animation.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/Animation.java @@ -103,10 +103,8 @@ public class Animation { } static int linearSearch (float[] values, float target, int step) { - for (int i = 0, last = values.length - step; i <= last; i += step) { - if (values[i] <= target) continue; - return i; - } + for (int i = 0, last = values.length - step; i <= last; i += step) + if (values[i] > target) return i; return -1; } @@ -116,7 +114,7 @@ public class Animation { } /** Base class for frames that use an interpolation bezier curve. */ - static public abstract class CurveTimeline implements Timeline { + abstract static public class CurveTimeline implements Timeline { static private final float LINEAR = 0; static private final float STEPPED = -1; static private final int BEZIER_SEGMENTS = 10; @@ -220,11 +218,11 @@ public class Animation { return frames; } - /** Sets the time and value of the specified keyframe. */ - public void setFrame (int frameIndex, float time, float value) { + /** Sets the time and angle of the specified keyframe. */ + public void setFrame (int frameIndex, float time, float angle) { frameIndex *= 2; frames[frameIndex] = time; - frames[frameIndex + 1] = value; + frames[frameIndex + 1] = angle; } public void apply (Skeleton skeleton, float time, float alpha) { diff --git a/spine-libgdx/src/com/esotericsoftware/spine/Bone.java b/spine-libgdx/src/com/esotericsoftware/spine/Bone.java index 967e6e3d6..2c58cd820 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/Bone.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/Bone.java @@ -35,7 +35,7 @@ public class Bone { final Bone parent; float x, y; float rotation; - float scaleX = 1, scaleY = 1; + float scaleX, scaleY; float m00, m01, worldX; // a b x float m10, m11, worldY; // c d y diff --git a/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java b/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java index 864133e60..6fd499126 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java @@ -251,6 +251,7 @@ public class Skeleton { /** @param attachmentName May be null. */ public void setAttachment (String slotName, String attachmentName) { if (slotName == null) throw new IllegalArgumentException("slotName cannot be null."); + Array slots = this.slots; for (int i = 0, n = slots.size; i < n; i++) { Slot slot = slots.get(i); if (slot.data.name.equals(slotName)) { diff --git a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonData.java b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonData.java index ba30bec4c..40899802a 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonData.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonData.java @@ -39,6 +39,7 @@ public class SkeletonData { bones.clear(); slots.clear(); skins.clear(); + animations.clear(); defaultSkin = null; } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java index 4e490802f..38d856b4b 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java @@ -122,9 +122,9 @@ public class SkeletonJson { } // Skins. - OrderedMap slotMap = (OrderedMap)root.get("skins"); - if (slotMap != null) { - for (Entry entry : slotMap.entries()) { + OrderedMap skinsMap = (OrderedMap)root.get("skins"); + if (skinsMap != null) { + for (Entry entry : skinsMap.entries()) { Skin skin = new Skin(entry.key); for (Entry slotEntry : ((OrderedMap)entry.value).entries()) { int slotIndex = skeletonData.findSlotIndex(slotEntry.key); @@ -209,12 +209,12 @@ public class SkeletonJson { RotateTimeline timeline = new RotateTimeline(values.size); timeline.setBoneIndex(boneIndex); - int keyframeIndex = 0; + int frameIndex = 0; for (OrderedMap valueMap : values) { float time = (Float)valueMap.get("time"); - timeline.setFrame(keyframeIndex, time, (Float)valueMap.get("angle")); - readCurve(timeline, keyframeIndex, valueMap); - keyframeIndex++; + timeline.setFrame(frameIndex, time, (Float)valueMap.get("angle")); + readCurve(timeline, frameIndex, valueMap); + frameIndex++; } timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() * 2 - 2]); @@ -230,14 +230,14 @@ public class SkeletonJson { } timeline.setBoneIndex(boneIndex); - int keyframeIndex = 0; + int frameIndex = 0; for (OrderedMap valueMap : values) { float time = (Float)valueMap.get("time"); Float x = (Float)valueMap.get("x"), y = (Float)valueMap.get("y"); - timeline.setFrame(keyframeIndex, time, x == null ? 0 : (x * timelineScale), y == null ? 0 - : (y * timelineScale)); - readCurve(timeline, keyframeIndex, valueMap); - keyframeIndex++; + timeline + .setFrame(frameIndex, time, x == null ? 0 : (x * timelineScale), y == null ? 0 : (y * timelineScale)); + readCurve(timeline, frameIndex, valueMap); + frameIndex++; } timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() * 3 - 3]); @@ -262,13 +262,13 @@ public class SkeletonJson { ColorTimeline timeline = new ColorTimeline(values.size); timeline.setSlotIndex(slotIndex); - int keyframeIndex = 0; + int frameIndex = 0; for (OrderedMap valueMap : values) { float time = (Float)valueMap.get("time"); Color color = Color.valueOf((String)valueMap.get("color")); - timeline.setFrame(keyframeIndex, time, color.r, color.g, color.b, color.a); - readCurve(timeline, keyframeIndex, valueMap); - keyframeIndex++; + timeline.setFrame(frameIndex, time, color.r, color.g, color.b, color.a); + readCurve(timeline, frameIndex, valueMap); + frameIndex++; } timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() * 5 - 5]); @@ -277,10 +277,10 @@ public class SkeletonJson { AttachmentTimeline timeline = new AttachmentTimeline(values.size); timeline.setSlotIndex(slotIndex); - int keyframeIndex = 0; + int frameIndex = 0; for (OrderedMap valueMap : values) { float time = (Float)valueMap.get("time"); - timeline.setFrame(keyframeIndex++, time, (String)valueMap.get("name")); + timeline.setFrame(frameIndex++, time, (String)valueMap.get("name")); } timelines.add(timeline); duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() - 1]); @@ -295,14 +295,14 @@ public class SkeletonJson { skeletonData.addAnimation(new Animation(name, timelines, duration)); } - private void readCurve (CurveTimeline timeline, int keyframeIndex, OrderedMap valueMap) { + private void readCurve (CurveTimeline timeline, int frameIndex, OrderedMap valueMap) { Object curveObject = valueMap.get("curve"); if (curveObject == null) return; if (curveObject.equals("stepped")) - timeline.setStepped(keyframeIndex); + timeline.setStepped(frameIndex); else if (curveObject instanceof Array) { Array curve = (Array)curveObject; - timeline.setCurve(keyframeIndex, (Float)curve.get(0), (Float)curve.get(1), (Float)curve.get(2), (Float)curve.get(3)); + timeline.setCurve(frameIndex, (Float)curve.get(0), (Float)curve.get(1), (Float)curve.get(2), (Float)curve.get(3)); } } } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/Skin.java b/spine-libgdx/src/com/esotericsoftware/spine/Skin.java index ba9951f62..5c61992d1 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/Skin.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/Skin.java @@ -78,13 +78,25 @@ public class Skin { return name; } + /** Attach each attachment in this skin if the corresponding attachment in the old skin is currently attached. */ + void attachAll (Skeleton skeleton, Skin oldSkin) { + for (Entry entry : oldSkin.attachments.entries()) { + int slotIndex = entry.key.slotIndex; + Slot slot = skeleton.slots.get(slotIndex); + if (slot.attachment == entry.value) { + Attachment attachment = getAttachment(slotIndex, entry.key.name); + if (attachment != null) slot.setAttachment(attachment); + } + } + } + static class Key { int slotIndex; String name; int hashCode; public void set (int slotName, String name) { - if (name == null) throw new IllegalArgumentException("attachmentName cannot be null."); + if (name == null) throw new IllegalArgumentException("name cannot be null."); this.slotIndex = slotName; this.name = name; hashCode = 31 * (31 + name.hashCode()) + slotIndex; @@ -106,16 +118,4 @@ public class Skin { return slotIndex + ":" + name; } } - - /** Attach each attachment in this skin if the corresponding attachment in the old skin is currently attached. */ - void attachAll (Skeleton skeleton, Skin oldSkin) { - for (Entry entry : oldSkin.attachments.entries()) { - int slotIndex = entry.key.slotIndex; - Slot slot = skeleton.slots.get(slotIndex); - if (slot.attachment == entry.value) { - Attachment attachment = getAttachment(slotIndex, entry.key.name); - if (attachment != null) slot.setAttachment(attachment); - } - } - } } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/Slot.java b/spine-libgdx/src/com/esotericsoftware/spine/Slot.java index 6f1af9653..0109bcbfd 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/Slot.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/Slot.java @@ -49,7 +49,7 @@ public class Slot { this.data = data; this.skeleton = skeleton; this.bone = bone; - color = new Color(1, 1, 1, 1); + color = new Color(); setToBindPose(); }