From 23e04c3b083694f57758305311333ffdfa5ca5a5 Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Tue, 16 Apr 2013 12:44:55 +0200 Subject: [PATCH] Refactoring to bring spine-libgdx up to date with spine-csharp and spine-xna. --- .../src/Attachments/AtlasAttachmentLoader.cs | 2 +- .../src/Attachments/AttachmentLoader.cs | 2 +- spine-csharp/src/SkeletonJson.cs | 6 +- .../com/esotericsoftware/spine/Skeleton.java | 33 +--------- .../spine/SkeletonBinary.java | 3 + .../esotericsoftware/spine/SkeletonJson.java | 36 ++++++---- .../spine/SkeletonRenderer.java | 24 +++++++ .../spine/SkeletonRendererDebug.java | 65 +++++++++++++++++++ .../src/com/esotericsoftware/spine/Skin.java | 2 + .../src/com/esotericsoftware/spine/Slot.java | 2 + .../attachments/AtlasAttachmentLoader.java | 3 - .../spine/{ => attachments}/Attachment.java | 6 +- .../{ => attachments}/AttachmentLoader.java | 4 +- .../{ => attachments}/AttachmentType.java | 2 +- .../spine/attachments/RegionAttachment.java | 17 ++--- .../attachments/RegionSequenceAttachment.java | 10 +-- .../spine/AnimationStateTest.java | 16 +++-- .../com/esotericsoftware/spine/MixTest.java | 17 ++--- .../esotericsoftware/spine/SkeletonTest.java | 15 +++-- .../Assets/Plugins/Spine/SkeletonComponent.cs | 2 + 20 files changed, 173 insertions(+), 94 deletions(-) create mode 100644 spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java create mode 100644 spine-libgdx/src/com/esotericsoftware/spine/SkeletonRendererDebug.java rename spine-libgdx/src/com/esotericsoftware/spine/{ => attachments}/Attachment.java (95%) rename spine-libgdx/src/com/esotericsoftware/spine/{ => attachments}/AttachmentLoader.java (95%) rename spine-libgdx/src/com/esotericsoftware/spine/{ => attachments}/AttachmentType.java (97%) diff --git a/spine-csharp/src/Attachments/AtlasAttachmentLoader.cs b/spine-csharp/src/Attachments/AtlasAttachmentLoader.cs index 58a0fd5fc..28f44658f 100644 --- a/spine-csharp/src/Attachments/AtlasAttachmentLoader.cs +++ b/spine-csharp/src/Attachments/AtlasAttachmentLoader.cs @@ -34,7 +34,7 @@ namespace Spine { this.atlas = atlas; } - public Attachment NewAttachment (AttachmentType type, String name) { + public Attachment NewAttachment (Skin skin, AttachmentType type, String name) { switch (type) { case AttachmentType.region: AtlasRegion region = atlas.FindRegion(name); diff --git a/spine-csharp/src/Attachments/AttachmentLoader.cs b/spine-csharp/src/Attachments/AttachmentLoader.cs index 5e95f85ea..d926dfc80 100644 --- a/spine-csharp/src/Attachments/AttachmentLoader.cs +++ b/spine-csharp/src/Attachments/AttachmentLoader.cs @@ -28,6 +28,6 @@ using System; namespace Spine { public interface AttachmentLoader { /** @return May be null to not load any attachment. */ - Attachment NewAttachment (AttachmentType type, String name); + Attachment NewAttachment (Skin skin, AttachmentType type, String name); } } diff --git a/spine-csharp/src/SkeletonJson.cs b/spine-csharp/src/SkeletonJson.cs index 725c1f10a..46fb0dae5 100644 --- a/spine-csharp/src/SkeletonJson.cs +++ b/spine-csharp/src/SkeletonJson.cs @@ -119,7 +119,7 @@ namespace Spine { foreach (KeyValuePair slotEntry in (Dictionary)entry.Value) { int slotIndex = skeletonData.FindSlotIndex(slotEntry.Key); foreach (KeyValuePair attachmentEntry in ((Dictionary)slotEntry.Value)) { - Attachment attachment = readAttachment(attachmentEntry.Key, (Dictionary)attachmentEntry.Value); + Attachment attachment = readAttachment(skin, attachmentEntry.Key, (Dictionary)attachmentEntry.Value); skin.AddAttachment(slotIndex, attachmentEntry.Key, attachment); } } @@ -144,14 +144,14 @@ namespace Spine { return skeletonData; } - private Attachment readAttachment (String name, Dictionary map) { + private Attachment readAttachment (Skin skin, String name, Dictionary map) { if (map.ContainsKey("name")) name = (String)map["name"]; AttachmentType type = AttachmentType.region; if (map.ContainsKey("type")) type = (AttachmentType)Enum.Parse(typeof(AttachmentType), (String)map["type"], false); - Attachment attachment = attachmentLoader.NewAttachment(type, name); + Attachment attachment = attachmentLoader.NewAttachment(skin, type, name); if (attachment is RegionAttachment) { RegionAttachment regionAttachment = (RegionAttachment)attachment; diff --git a/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java b/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java index 6fd499126..304a82319 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java @@ -25,6 +25,8 @@ package com.esotericsoftware.spine; +import com.esotericsoftware.spine.attachments.Attachment; + import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; @@ -117,37 +119,6 @@ public class Skeleton { slots.get(i).setToBindPose(i); } - public void draw (SpriteBatch batch) { - Array drawOrder = this.drawOrder; - for (int i = 0, n = drawOrder.size; i < n; i++) { - Slot slot = drawOrder.get(i); - Attachment attachment = slot.attachment; - if (attachment != null) attachment.draw(batch, slot); - } - } - - public void drawDebug (ShapeRenderer renderer) { - renderer.setColor(Color.RED); - renderer.begin(ShapeType.Line); - for (int i = 0, n = bones.size; i < n; i++) { - Bone bone = bones.get(i); - if (bone.parent == null) continue; - float x = bone.data.length * bone.m00 + bone.worldX; - float y = bone.data.length * bone.m10 + bone.worldY; - renderer.line(bone.worldX, bone.worldY, x, y); - } - renderer.end(); - - renderer.setColor(Color.GREEN); - renderer.begin(ShapeType.Filled); - for (int i = 0, n = bones.size; i < n; i++) { - Bone bone = bones.get(i); - renderer.setColor(Color.GREEN); - renderer.circle(bone.worldX, bone.worldY, 3); - } - renderer.end(); - } - public SkeletonData getData () { return data; } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java index 9eb46b3d4..76cb96321 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java @@ -32,6 +32,9 @@ import com.esotericsoftware.spine.Animation.RotateTimeline; import com.esotericsoftware.spine.Animation.ScaleTimeline; import com.esotericsoftware.spine.Animation.Timeline; import com.esotericsoftware.spine.Animation.TranslateTimeline; +import com.esotericsoftware.spine.attachments.Attachment; +import com.esotericsoftware.spine.attachments.AttachmentLoader; +import com.esotericsoftware.spine.attachments.AttachmentType; import com.esotericsoftware.spine.attachments.RegionAttachment; import com.esotericsoftware.spine.attachments.RegionSequenceAttachment; import com.esotericsoftware.spine.attachments.RegionSequenceAttachment.Mode; diff --git a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java index 60efe7cdf..b5e09a534 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java @@ -32,10 +32,13 @@ import com.esotericsoftware.spine.Animation.RotateTimeline; import com.esotericsoftware.spine.Animation.ScaleTimeline; import com.esotericsoftware.spine.Animation.Timeline; import com.esotericsoftware.spine.Animation.TranslateTimeline; +import com.esotericsoftware.spine.attachments.AtlasAttachmentLoader; +import com.esotericsoftware.spine.attachments.Attachment; +import com.esotericsoftware.spine.attachments.AttachmentLoader; +import com.esotericsoftware.spine.attachments.AttachmentType; import com.esotericsoftware.spine.attachments.RegionAttachment; import com.esotericsoftware.spine.attachments.RegionSequenceAttachment; import com.esotericsoftware.spine.attachments.RegionSequenceAttachment.Mode; -import com.esotericsoftware.spine.attachments.AtlasAttachmentLoader; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.Color; @@ -46,8 +49,6 @@ import com.badlogic.gdx.utils.ObjectMap.Entry; import com.badlogic.gdx.utils.OrderedMap; import com.badlogic.gdx.utils.SerializationException; -import java.io.StringWriter; - public class SkeletonJson { static public final String TIMELINE_SCALE = "scale"; static public final String TIMELINE_ROTATE = "rotate"; @@ -161,7 +162,7 @@ public class SkeletonJson { if (attachment instanceof RegionSequenceAttachment) { RegionSequenceAttachment regionSequenceAttachment = (RegionSequenceAttachment)attachment; - Float fps = (Float)map.get("fps"); + Float fps = getFloat(map, "fps"); if (fps == null) throw new SerializationException("Region sequence attachment missing fps: " + name); regionSequenceAttachment.setFrameTime(fps); @@ -187,6 +188,19 @@ public class SkeletonJson { private float getFloat (OrderedMap map, String name, float defaultValue) { Object value = map.get(name); if (value == null) return defaultValue; + if (value instanceof Long) return (Long)value; + return (Float)value; + } + + private float getFloat (OrderedMap map, String name) { + Object value = map.get(name); + if (value instanceof Long) return (Long)value; + return (Float)value; + } + + private float getFloat (Array array, int index) { + Object value = array.get(index); + if (value instanceof Long) return (Long)value; return (Float)value; } @@ -211,8 +225,8 @@ public class SkeletonJson { int frameIndex = 0; for (OrderedMap valueMap : values) { - float time = (Float)valueMap.get("time"); - timeline.setFrame(frameIndex, time, (Float)valueMap.get("angle")); + float time = getFloat(valueMap, "time"); + timeline.setFrame(frameIndex, time, getFloat(valueMap, "angle")); readCurve(timeline, frameIndex, valueMap); frameIndex++; } @@ -232,8 +246,8 @@ public class SkeletonJson { int frameIndex = 0; for (OrderedMap valueMap : values) { - float time = (Float)valueMap.get("time"); - Float x = (Float)valueMap.get("x"), y = (Float)valueMap.get("y"); + float time = getFloat(valueMap, "time"); + Float x = getFloat(valueMap, "x"), y = getFloat(valueMap, "y"); timeline .setFrame(frameIndex, time, x == null ? 0 : (x * timelineScale), y == null ? 0 : (y * timelineScale)); readCurve(timeline, frameIndex, valueMap); @@ -264,7 +278,7 @@ public class SkeletonJson { int frameIndex = 0; for (OrderedMap valueMap : values) { - float time = (Float)valueMap.get("time"); + float time = getFloat(valueMap, "time"); Color color = Color.valueOf((String)valueMap.get("color")); timeline.setFrame(frameIndex, time, color.r, color.g, color.b, color.a); readCurve(timeline, frameIndex, valueMap); @@ -279,7 +293,7 @@ public class SkeletonJson { int frameIndex = 0; for (OrderedMap valueMap : values) { - float time = (Float)valueMap.get("time"); + float time = getFloat(valueMap, "time"); timeline.setFrame(frameIndex++, time, (String)valueMap.get("name")); } timelines.add(timeline); @@ -302,7 +316,7 @@ public class SkeletonJson { timeline.setStepped(frameIndex); else if (curveObject instanceof Array) { Array curve = (Array)curveObject; - timeline.setCurve(frameIndex, (Float)curve.get(0), (Float)curve.get(1), (Float)curve.get(2), (Float)curve.get(3)); + timeline.setCurve(frameIndex, getFloat(curve, 0), getFloat(curve, 1), getFloat(curve, 2), getFloat(curve, 3)); } } } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java new file mode 100644 index 000000000..b5f32359e --- /dev/null +++ b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java @@ -0,0 +1,24 @@ + +package com.esotericsoftware.spine; + +import com.esotericsoftware.spine.attachments.Attachment; +import com.esotericsoftware.spine.attachments.RegionAttachment; + +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.utils.Array; + +public class SkeletonRenderer { + public void draw (SpriteBatch batch, Skeleton skeleton) { + Array drawOrder = skeleton.drawOrder; + for (int i = 0, n = drawOrder.size; i < n; i++) { + Slot slot = drawOrder.get(i); + Attachment attachment = slot.attachment; + if (attachment instanceof RegionAttachment) { + RegionAttachment regionAttachment = (RegionAttachment)attachment; + regionAttachment.updateVertices(slot); + float[] vertices = regionAttachment.getVertices(); + batch.draw(regionAttachment.getRegion().getTexture(), vertices, 0, vertices.length); + } + } + } +} diff --git a/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRendererDebug.java b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRendererDebug.java new file mode 100644 index 000000000..f7b6c6555 --- /dev/null +++ b/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRendererDebug.java @@ -0,0 +1,65 @@ + +package com.esotericsoftware.spine; + +import com.esotericsoftware.spine.attachments.Attachment; +import com.esotericsoftware.spine.attachments.RegionAttachment; + +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import static com.badlogic.gdx.graphics.g2d.SpriteBatch.*; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType; +import com.badlogic.gdx.utils.Array; + +public class SkeletonRendererDebug { + private ShapeRenderer renderer; + + public SkeletonRendererDebug () { + renderer = new ShapeRenderer(); + } + + public void draw (SpriteBatch batch, Skeleton skeleton) { + renderer.begin(ShapeType.Line); + + renderer.setColor(Color.RED); + Array bones = skeleton.getBones(); + for (int i = 0, n = bones.size; i < n; i++) { + Bone bone = bones.get(i); + if (bone.parent == null) continue; + float x = bone.data.length * bone.m00 + bone.worldX; + float y = bone.data.length * bone.m10 + bone.worldY; + renderer.line(bone.worldX, bone.worldY, x, y); + } + + renderer.setColor(Color.BLUE); + Array slots = skeleton.getSlots(); + for (int i = 0, n = slots.size; i < n; i++) { + Slot slot = slots.get(i); + Attachment attachment = slot.attachment; + if (attachment instanceof RegionAttachment) { + RegionAttachment regionAttachment = (RegionAttachment)attachment; + regionAttachment.updateVertices(slot); + float[] vertices = regionAttachment.getVertices(); + renderer.line(vertices[X1], vertices[Y1], vertices[X2], vertices[Y2]); + renderer.line(vertices[X2], vertices[Y2], vertices[X3], vertices[Y3]); + renderer.line(vertices[X3], vertices[Y3], vertices[X4], vertices[Y4]); + renderer.line(vertices[X4], vertices[Y4], vertices[X1], vertices[Y1]); + } + } + + renderer.end(); + + renderer.setColor(Color.GREEN); + renderer.begin(ShapeType.Filled); + for (int i = 0, n = bones.size; i < n; i++) { + Bone bone = bones.get(i); + renderer.setColor(Color.GREEN); + renderer.circle(bone.worldX, bone.worldY, 3); + } + renderer.end(); + } + + public ShapeRenderer getShapeRenderer () { + return renderer; + } +} diff --git a/spine-libgdx/src/com/esotericsoftware/spine/Skin.java b/spine-libgdx/src/com/esotericsoftware/spine/Skin.java index 5c61992d1..5e7505e98 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/Skin.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/Skin.java @@ -25,6 +25,8 @@ package com.esotericsoftware.spine; +import com.esotericsoftware.spine.attachments.Attachment; + import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.ObjectMap; import com.badlogic.gdx.utils.ObjectMap.Entry; diff --git a/spine-libgdx/src/com/esotericsoftware/spine/Slot.java b/spine-libgdx/src/com/esotericsoftware/spine/Slot.java index 0109bcbfd..98ba2f11b 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/Slot.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/Slot.java @@ -25,6 +25,8 @@ package com.esotericsoftware.spine; +import com.esotericsoftware.spine.attachments.Attachment; + import com.badlogic.gdx.graphics.Color; public class Slot { diff --git a/spine-libgdx/src/com/esotericsoftware/spine/attachments/AtlasAttachmentLoader.java b/spine-libgdx/src/com/esotericsoftware/spine/attachments/AtlasAttachmentLoader.java index eca5700a3..cad145f0e 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/attachments/AtlasAttachmentLoader.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/attachments/AtlasAttachmentLoader.java @@ -25,9 +25,6 @@ package com.esotericsoftware.spine.attachments; -import com.esotericsoftware.spine.Attachment; -import com.esotericsoftware.spine.AttachmentLoader; -import com.esotericsoftware.spine.AttachmentType; import com.esotericsoftware.spine.Skin; import com.badlogic.gdx.graphics.g2d.TextureAtlas; diff --git a/spine-libgdx/src/com/esotericsoftware/spine/Attachment.java b/spine-libgdx/src/com/esotericsoftware/spine/attachments/Attachment.java similarity index 95% rename from spine-libgdx/src/com/esotericsoftware/spine/Attachment.java rename to spine-libgdx/src/com/esotericsoftware/spine/attachments/Attachment.java index 9f27aaf21..c0b128cea 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/Attachment.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/attachments/Attachment.java @@ -23,7 +23,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ -package com.esotericsoftware.spine; +package com.esotericsoftware.spine.attachments; + +import com.esotericsoftware.spine.Slot; import com.badlogic.gdx.graphics.g2d.SpriteBatch; @@ -35,8 +37,6 @@ abstract public class Attachment { this.name = name; } - abstract public void draw (SpriteBatch batch, Slot slot); - public String getName () { return name; } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/AttachmentLoader.java b/spine-libgdx/src/com/esotericsoftware/spine/attachments/AttachmentLoader.java similarity index 95% rename from spine-libgdx/src/com/esotericsoftware/spine/AttachmentLoader.java rename to spine-libgdx/src/com/esotericsoftware/spine/attachments/AttachmentLoader.java index 49bc1107e..ae93d1072 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/AttachmentLoader.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/attachments/AttachmentLoader.java @@ -23,7 +23,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ -package com.esotericsoftware.spine; +package com.esotericsoftware.spine.attachments; + +import com.esotericsoftware.spine.Skin; public interface AttachmentLoader { /** @return May be null to not load any attachment. */ diff --git a/spine-libgdx/src/com/esotericsoftware/spine/AttachmentType.java b/spine-libgdx/src/com/esotericsoftware/spine/attachments/AttachmentType.java similarity index 97% rename from spine-libgdx/src/com/esotericsoftware/spine/AttachmentType.java rename to spine-libgdx/src/com/esotericsoftware/spine/attachments/AttachmentType.java index 6d2170739..78329c3bd 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/AttachmentType.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/attachments/AttachmentType.java @@ -23,7 +23,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ -package com.esotericsoftware.spine; +package com.esotericsoftware.spine.attachments; public enum AttachmentType { region, regionSequence diff --git a/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionAttachment.java b/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionAttachment.java index 40fdcf0fa..a55307311 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionAttachment.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionAttachment.java @@ -25,7 +25,6 @@ package com.esotericsoftware.spine.attachments; -import com.esotericsoftware.spine.Attachment; import com.esotericsoftware.spine.Bone; import com.esotericsoftware.spine.Slot; @@ -128,13 +127,11 @@ public class RegionAttachment extends Attachment { } public TextureRegion getRegion () { - if (region == null) throw new IllegalStateException("RegionAttachment is not resolved: " + this); + if (region == null) throw new IllegalStateException("Region has not been set: " + this); return region; } - public void draw (SpriteBatch batch, Slot slot) { - if (region == null) throw new IllegalStateException("RegionAttachment is not resolved: " + this); - + public void updateVertices (Slot slot) { Color skeletonColor = slot.getSkeleton().getColor(); Color slotColor = slot.getColor(); float color = NumberUtils.intToFloatColor( // @@ -148,14 +145,8 @@ public class RegionAttachment extends Attachment { vertices[C3] = color; vertices[C4] = color; - updateWorldVertices(slot.getBone()); - - batch.draw(region.getTexture(), vertices, 0, vertices.length); - } - - public void updateWorldVertices (Bone bone) { - float[] vertices = this.vertices; float[] offset = this.offset; + Bone bone = slot.getBone(); float x = bone.getWorldX(); float y = bone.getWorldY(); float m00 = bone.getM00(); @@ -172,7 +163,7 @@ public class RegionAttachment extends Attachment { vertices[Y4] = offset[6] * m10 + offset[7] * m11 + y; } - public float[] getWorldVertices () { + public float[] getVertices () { return vertices; } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionSequenceAttachment.java b/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionSequenceAttachment.java index 244a17815..7c762332c 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionSequenceAttachment.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionSequenceAttachment.java @@ -41,8 +41,8 @@ public class RegionSequenceAttachment extends RegionAttachment { super(name); } - public void draw (SpriteBatch batch, Slot slot) { - if (regions == null) throw new IllegalStateException("RegionSequenceAttachment is not resolved: " + this); + public void updateVertices (Slot slot) { + if (regions == null) throw new IllegalStateException("Regions have not been set: " + this); int frameIndex = (int)(slot.getAttachmentTime() / frameTime); switch (mode) { @@ -68,12 +68,12 @@ public class RegionSequenceAttachment extends RegionAttachment { break; } setRegion(regions[frameIndex]); - super.draw(batch, slot); + + super.updateVertices(slot); } - /** May be null if the attachment is not resolved. */ public TextureRegion[] getRegions () { - if (regions == null) throw new IllegalStateException("RegionSequenceAttachment is not resolved: " + this); + if (regions == null) throw new IllegalStateException("Regions have not been set: " + this); return regions; } diff --git a/spine-libgdx/test/com/esotericsoftware/spine/AnimationStateTest.java b/spine-libgdx/test/com/esotericsoftware/spine/AnimationStateTest.java index 921c563e5..0c5d5660e 100644 --- a/spine-libgdx/test/com/esotericsoftware/spine/AnimationStateTest.java +++ b/spine-libgdx/test/com/esotericsoftware/spine/AnimationStateTest.java @@ -35,7 +35,8 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer; public class AnimationStateTest extends ApplicationAdapter { SpriteBatch batch; - ShapeRenderer renderer; + SkeletonRenderer renderer; + SkeletonRendererDebug debugRenderer; TextureAtlas atlas; Skeleton skeleton; @@ -44,11 +45,12 @@ public class AnimationStateTest extends ApplicationAdapter { public void create () { batch = new SpriteBatch(); - renderer = new ShapeRenderer(); + renderer = new SkeletonRenderer(); + debugRenderer = new SkeletonRendererDebug(); atlas = new TextureAtlas(Gdx.files.internal("spineboy.atlas")); SkeletonJson json = new SkeletonJson(atlas); - SkeletonData skeletonData = json.readSkeletonData(Gdx.files.internal("spineboy-skeleton.json")); + SkeletonData skeletonData = json.readSkeletonData(Gdx.files.internal("spineboy.json")); // Define mixing between animations. AnimationStateData stateData = new AnimationStateData(skeletonData); @@ -71,7 +73,6 @@ public class AnimationStateTest extends ApplicationAdapter { state.update(Gdx.graphics.getDeltaTime() / 3); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); - batch.begin(); state.apply(skeleton); if (state.getAnimation().getName().equals("walk")) { @@ -81,14 +82,17 @@ public class AnimationStateTest extends ApplicationAdapter { if (state.getTime() > 1) state.setAnimation("walk", true); } skeleton.updateWorldTransform(); - skeleton.draw(batch); + batch.begin(); + renderer.draw(batch, skeleton); batch.end(); + + debugRenderer.draw(batch, skeleton); } public void resize (int width, int height) { batch.getProjectionMatrix().setToOrtho2D(0, 0, width, height); - renderer.setProjectionMatrix(batch.getProjectionMatrix()); + debugRenderer.getShapeRenderer().setProjectionMatrix(batch.getProjectionMatrix()); } public void dispose () { diff --git a/spine-libgdx/test/com/esotericsoftware/spine/MixTest.java b/spine-libgdx/test/com/esotericsoftware/spine/MixTest.java index 61ff393cd..6537ea9bc 100644 --- a/spine-libgdx/test/com/esotericsoftware/spine/MixTest.java +++ b/spine-libgdx/test/com/esotericsoftware/spine/MixTest.java @@ -38,7 +38,8 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer; public class MixTest extends ApplicationAdapter { SpriteBatch batch; float time; - ShapeRenderer renderer; + SkeletonRenderer renderer; + SkeletonRendererDebug debugRenderer; SkeletonData skeletonData; Skeleton skeleton; @@ -47,7 +48,8 @@ public class MixTest extends ApplicationAdapter { public void create () { batch = new SpriteBatch(); - renderer = new ShapeRenderer(); + renderer = new SkeletonRenderer(); + debugRenderer = new SkeletonRendererDebug(); final String name = "spineboy"; @@ -56,7 +58,7 @@ public class MixTest extends ApplicationAdapter { if (true) { SkeletonJson json = new SkeletonJson(atlas); // json.setScale(2); - skeletonData = json.readSkeletonData(Gdx.files.internal(name + "-skeleton.json")); + skeletonData = json.readSkeletonData(Gdx.files.internal(name + ".json")); } else { SkeletonBinary binary = new SkeletonBinary(atlas); // binary.setScale(2); @@ -94,8 +96,6 @@ public class MixTest extends ApplicationAdapter { root.setX(root.getX() + speed * delta); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); - batch.begin(); - batch.setColor(Color.GRAY); // This shows how to manage state manually. See AnimationStatesTest. if (time > total) { @@ -123,16 +123,17 @@ public class MixTest extends ApplicationAdapter { skeleton.updateWorldTransform(); skeleton.update(Gdx.graphics.getDeltaTime()); - skeleton.draw(batch); + batch.begin(); + renderer.draw(batch, skeleton); batch.end(); - // skeleton.drawDebug(renderer); + debugRenderer.draw(batch, skeleton); } public void resize (int width, int height) { batch.getProjectionMatrix().setToOrtho2D(0, 0, width, height); - renderer.setProjectionMatrix(batch.getProjectionMatrix()); + debugRenderer.getShapeRenderer().setProjectionMatrix(batch.getProjectionMatrix()); } public static void main (String[] args) throws Exception { diff --git a/spine-libgdx/test/com/esotericsoftware/spine/SkeletonTest.java b/spine-libgdx/test/com/esotericsoftware/spine/SkeletonTest.java index 300190b13..d8b45f786 100644 --- a/spine-libgdx/test/com/esotericsoftware/spine/SkeletonTest.java +++ b/spine-libgdx/test/com/esotericsoftware/spine/SkeletonTest.java @@ -46,7 +46,8 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer; public class SkeletonTest extends ApplicationAdapter { SpriteBatch batch; float time; - ShapeRenderer renderer; + SkeletonRenderer renderer; + SkeletonRendererDebug debugRenderer; SkeletonData skeletonData; Skeleton skeleton; @@ -54,7 +55,8 @@ public class SkeletonTest extends ApplicationAdapter { public void create () { batch = new SpriteBatch(); - renderer = new ShapeRenderer(); + renderer = new SkeletonRenderer(); + debugRenderer = new SkeletonRendererDebug(); final String name = "goblins"; // "spineboy"; @@ -118,22 +120,21 @@ public class SkeletonTest extends ApplicationAdapter { root.setX(x); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); - batch.begin(); - batch.setColor(Color.GRAY); animation.apply(skeleton, time, true); skeleton.updateWorldTransform(); skeleton.update(Gdx.graphics.getDeltaTime()); - skeleton.draw(batch); + batch.begin(); + renderer.draw(batch, skeleton); batch.end(); - skeleton.drawDebug(renderer); + debugRenderer.draw(batch, skeleton); } public void resize (int width, int height) { batch.getProjectionMatrix().setToOrtho2D(0, 0, width, height); - renderer.setProjectionMatrix(batch.getProjectionMatrix()); + debugRenderer.getShapeRenderer().setProjectionMatrix(batch.getProjectionMatrix()); } public static void main (String[] args) throws Exception { diff --git a/spine-unity/Assets/Plugins/Spine/SkeletonComponent.cs b/spine-unity/Assets/Plugins/Spine/SkeletonComponent.cs index 485334fbd..87ba8d1bd 100644 --- a/spine-unity/Assets/Plugins/Spine/SkeletonComponent.cs +++ b/spine-unity/Assets/Plugins/Spine/SkeletonComponent.cs @@ -61,6 +61,7 @@ public class SkeletonComponent : MonoBehaviour { skeleton = new Skeleton(skeletonDataAsset.GetSkeletonData(false)); } + public void Update () { // Clear fields if missing information to render. if (skeletonDataAsset == null || skeletonDataAsset.GetSkeletonData(false) == null) { @@ -83,6 +84,7 @@ public class SkeletonComponent : MonoBehaviour { state.Loop = loop; // Apply animation. + skeleton.Update(Time.deltaTime * timeScale); state.Update(Time.deltaTime * timeScale); state.Apply(skeleton); skeleton.UpdateWorldTransform();