From cee7e3f336324f958e2081aceded4b90fa415d42 Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Wed, 23 Apr 2014 01:06:59 +0200 Subject: [PATCH] setSkin with no previous skin attaches setup pose attachments. No more API gotcha, setSlotsToSetupPose is not needed. --- .../com/esotericsoftware/spine/Skeleton.java | 18 +++++++++++++++--- .../esotericsoftware/spine/SkeletonTest.java | 1 - 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java b/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java index f14a284a8..689b471a4 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java @@ -116,7 +116,7 @@ public class Skeleton { public void setSlotsToSetupPose () { Array slots = this.slots; - System.arraycopy(slots.items, 0, drawOrder.items, 0, slots.size); + System.arraycopy(slots.items, 0, drawOrder.items, 0, slots.size); for (int i = 0, n = slots.size; i < n; i++) slots.get(i).setToSetupPose(i); } @@ -203,10 +203,22 @@ public class Skeleton { } /** Sets the skin used to look up attachments not found in the {@link SkeletonData#getDefaultSkin() default skin}. Attachments - * from the new skin are attached if the corresponding attachment from the old skin was attached. + * from the new skin are attached if the corresponding attachment from the old skin was attached. If there was no old skin, + * each slot's setup mode attachment is attached from the new skin. * @param newSkin May be null. */ public void setSkin (Skin newSkin) { - if (skin != null && newSkin != null) newSkin.attachAll(this, skin); + if (skin == null) { + Array slots = this.slots; + for (int i = 0, n = slots.size; i < n; i++) { + Slot slot = slots.get(i); + String name = slot.data.attachmentName; + if (name != null) { + Attachment attachment = newSkin.getAttachment(i, name); + if (attachment != null) slot.setAttachment(attachment); + } + } + } else if (newSkin != null) // + newSkin.attachAll(this, skin); skin = newSkin; } diff --git a/spine-libgdx/test/com/esotericsoftware/spine/SkeletonTest.java b/spine-libgdx/test/com/esotericsoftware/spine/SkeletonTest.java index 3e486331d..3678dfd5b 100644 --- a/spine-libgdx/test/com/esotericsoftware/spine/SkeletonTest.java +++ b/spine-libgdx/test/com/esotericsoftware/spine/SkeletonTest.java @@ -163,7 +163,6 @@ public class SkeletonTest extends ApplicationAdapter { // Configure skeleton from UI. skeleton.setSkin(ui.skinList.getSelected()); - skeleton.setSlotsToSetupPose(); state.setAnimation(0, ui.animationList.getSelected(), ui.loopCheckbox.isChecked()); }