diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Animation.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Animation.java index 14e792302..403fdbbfb 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Animation.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Animation.java @@ -531,18 +531,16 @@ public class Animation { public void apply (Skeleton skeleton, float lastTime, float time, Array events, float alpha) { float[] frames = this.frames; - if (time < frames[0]) { - if (lastTime > time) apply(skeleton, lastTime, Integer.MAX_VALUE, null, 0); - return; - } else if (lastTime > time) // - lastTime = -1; + if (time < frames[0]) return; // Time is before first frame. - int frame = (time >= frames[frames.length - 1] ? frames.length : binarySearch(frames, time)) - 1; - if (frames[frame] < lastTime) return; + int frameIndex; + if (time >= frames[frames.length - 1]) // Time is after last frame. + frameIndex = frames.length - 1; + else + frameIndex = binarySearch(frames, time, 1) - 1; - String attachmentName = attachmentNames[frame]; - skeleton.slots.get(slotIndex) - .setAttachment(attachmentName == null ? null : skeleton.getAttachment(slotIndex, attachmentName)); + String attachmentName = attachmentNames[frameIndex]; + skeleton.slots.get(slotIndex).attachmentName = attachmentName; } } diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java index 063c4efce..a0dcc8fe9 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java @@ -530,7 +530,7 @@ public class Skeleton { for (int i = 0, n = drawOrder.size; i < n; i++) { Slot slot = drawOrder.get(i); float[] vertices = null; - Attachment attachment = slot.attachment; + Attachment attachment = slot.getAttachment(); if (attachment instanceof RegionAttachment) vertices = ((RegionAttachment)attachment).updateWorldVertices(slot, false); else if (attachment instanceof MeshAttachment) // diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBounds.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBounds.java index 7ff9d0f86..d7e951714 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBounds.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBounds.java @@ -61,7 +61,7 @@ public class SkeletonBounds { for (int i = 0; i < slotCount; i++) { Slot slot = slots.get(i); - Attachment attachment = slot.attachment; + Attachment attachment = slot.getAttachment(); if (attachment instanceof BoundingBoxAttachment) { BoundingBoxAttachment boundingBox = (BoundingBoxAttachment)attachment; boundingBoxes.add(boundingBox); diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonMeshRenderer.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonMeshRenderer.java index e6db7b114..b1cd887e5 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonMeshRenderer.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonMeshRenderer.java @@ -52,7 +52,7 @@ public class SkeletonMeshRenderer extends SkeletonRenderer { Array drawOrder = skeleton.drawOrder; for (int i = 0, n = drawOrder.size; i < n; i++) { Slot slot = drawOrder.get(i); - Attachment attachment = slot.attachment; + Attachment attachment = slot.getAttachment(); Texture texture = null; if (attachment instanceof RegionAttachment) { RegionAttachment region = (RegionAttachment)attachment; diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java index 5a4321727..0a2ac34c5 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java @@ -48,7 +48,7 @@ public class SkeletonRenderer { Array drawOrder = skeleton.drawOrder; for (int i = 0, n = drawOrder.size; i < n; i++) { Slot slot = drawOrder.get(i); - Attachment attachment = slot.attachment; + Attachment attachment = slot.getAttachment(); if (attachment instanceof RegionAttachment) { RegionAttachment regionAttachment = (RegionAttachment)attachment; float[] vertices = regionAttachment.updateWorldVertices(slot, premultipliedAlpha); diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRendererDebug.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRendererDebug.java index 9aabd2662..cda014304 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRendererDebug.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRendererDebug.java @@ -102,7 +102,7 @@ public class SkeletonRendererDebug { Array slots = skeleton.getSlots(); for (int i = 0, n = slots.size; i < n; i++) { Slot slot = slots.get(i); - Attachment attachment = slot.attachment; + Attachment attachment = slot.getAttachment(); if (attachment instanceof RegionAttachment) { RegionAttachment regionAttachment = (RegionAttachment)attachment; float[] vertices = regionAttachment.updateWorldVertices(slot, false); @@ -118,7 +118,7 @@ public class SkeletonRendererDebug { Array slots = skeleton.getSlots(); for (int i = 0, n = slots.size; i < n; i++) { Slot slot = slots.get(i); - Attachment attachment = slot.attachment; + Attachment attachment = slot.getAttachment(); if (!(attachment instanceof MeshAttachment)) continue; MeshAttachment mesh = (MeshAttachment)attachment; mesh.updateWorldVertices(slot, false); @@ -167,7 +167,7 @@ public class SkeletonRendererDebug { Array slots = skeleton.getSlots(); for (int i = 0, n = slots.size; i < n; i++) { Slot slot = slots.get(i); - Attachment attachment = slot.attachment; + Attachment attachment = slot.getAttachment(); if (!(attachment instanceof PathAttachment)) continue; PathAttachment path = (PathAttachment)attachment; int nn = path.getWorldVerticesLength(); diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skin.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skin.java index b42dff56f..39fc4af64 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skin.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skin.java @@ -102,7 +102,7 @@ public class Skin { for (Entry entry : oldSkin.attachments.entries()) { int slotIndex = entry.key.slotIndex; Slot slot = skeleton.slots.get(slotIndex); - if (slot.attachment == entry.value) { + if (slot.getAttachment() == entry.value) { Attachment attachment = getAttachment(slotIndex, entry.key.name); if (attachment != null) slot.setAttachment(attachment); } diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Slot.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Slot.java index f93478018..6922c3569 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Slot.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Slot.java @@ -31,18 +31,18 @@ package com.esotericsoftware.spine; -import com.esotericsoftware.spine.attachments.Attachment; - import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.utils.FloatArray; +import com.esotericsoftware.spine.attachments.Attachment; public class Slot { final SlotData data; final Bone bone; final Color color; - Attachment attachment; + private Attachment attachment; private float attachmentTime; private FloatArray attachmentVertices = new FloatArray(); + String attachmentName; public Slot (SlotData data, Bone bone) { if (data == null) throw new IllegalArgumentException("data cannot be null."); @@ -82,6 +82,10 @@ public class Slot { /** @return May be null. */ public Attachment getAttachment () { + if (attachmentName != null) { + attachment = bone.skeleton.getAttachment(data.index, attachmentName); + attachmentName = null; + } return attachment; }