mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 14:24:53 +08:00
libgdx runtime, attachment loader instead of resolver.
Other minor fixes.
This commit is contained in:
parent
da7f88400e
commit
695db31d71
@ -14,8 +14,7 @@ public:
|
|||||||
AtlasAttachmentLoader (Atlas *atlas);
|
AtlasAttachmentLoader (Atlas *atlas);
|
||||||
|
|
||||||
virtual Attachment* newAttachment (AttachmentType type, const std::string &name);
|
virtual Attachment* newAttachment (AttachmentType type, const std::string &name);
|
||||||
}
|
};
|
||||||
;
|
|
||||||
|
|
||||||
} /* namespace spine */
|
} /* namespace spine */
|
||||||
#endif /* SPINE_ATLASATTACHMENTLOADER_H_ */
|
#endif /* SPINE_ATLASATTACHMENTLOADER_H_ */
|
||||||
|
|||||||
@ -18,6 +18,7 @@ public:
|
|||||||
~Animation();
|
~Animation();
|
||||||
|
|
||||||
void apply (BaseSkeleton *skeleton, float time, bool loop);
|
void apply (BaseSkeleton *skeleton, float time, bool loop);
|
||||||
|
void mix (BaseSkeleton *skeleton, float time, bool loop, float alpha);
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@ -27,7 +27,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
virtual BaseAtlasPage* newAtlasPage (std::string name) = 0;
|
virtual BaseAtlasPage* newAtlasPage (std::string name) = 0;
|
||||||
virtual BaseAtlasRegion* newAtlasRegion (BaseAtlasPage*) = 0;
|
virtual BaseAtlasRegion* newAtlasRegion (BaseAtlasPage *page) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@ -70,20 +70,14 @@ void RegionAttachment::draw (Slot *slot) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RegionAttachment::updateWorldVertices (spine::Bone *bone) {
|
void RegionAttachment::updateWorldVertices (spine::Bone *bone) {
|
||||||
float x = bone->worldX;
|
vertices[0].position.x = offset[0] * bone->m00 + offset[1] * bone->m01 + bone->worldX;
|
||||||
float y = bone->worldY;
|
vertices[0].position.y = offset[0] * bone->m10 + offset[1] * bone->m11 + bone->worldY;
|
||||||
float m00 = bone->m00;
|
vertices[1].position.x = offset[2] * bone->m00 + offset[3] * bone->m01 + bone->worldX;
|
||||||
float m01 = bone->m01;
|
vertices[1].position.y = offset[2] * bone->m10 + offset[3] * bone->m11 + bone->worldY;
|
||||||
float m10 = bone->m10;
|
vertices[2].position.x = offset[4] * bone->m00 + offset[5] * bone->m01 + bone->worldX;
|
||||||
float m11 = bone->m11;
|
vertices[2].position.y = offset[4] * bone->m10 + offset[5] * bone->m11 + bone->worldY;
|
||||||
vertices[0].position.x = offset[0] * m00 + offset[1] * m01 + x;
|
vertices[3].position.x = offset[6] * bone->m00 + offset[7] * bone->m01 + bone->worldX;
|
||||||
vertices[0].position.y = offset[0] * m10 + offset[1] * m11 + y;
|
vertices[3].position.y = offset[6] * bone->m10 + offset[7] * bone->m11 + bone->worldY;
|
||||||
vertices[1].position.x = offset[2] * m00 + offset[3] * m01 + x;
|
|
||||||
vertices[1].position.y = offset[2] * m10 + offset[3] * m11 + y;
|
|
||||||
vertices[2].position.x = offset[4] * m00 + offset[5] * m01 + x;
|
|
||||||
vertices[2].position.y = offset[4] * m10 + offset[5] * m11 + y;
|
|
||||||
vertices[3].position.x = offset[6] * m00 + offset[7] * m01 + x;
|
|
||||||
vertices[3].position.y = offset[6] * m10 + offset[7] * m11 + y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* namespace spine */
|
} /* namespace spine */
|
||||||
|
|||||||
@ -35,6 +35,15 @@ void Animation::apply (BaseSkeleton *skeleton, float time, bool loop) {
|
|||||||
timelines[i]->apply(skeleton, time, 1);
|
timelines[i]->apply(skeleton, time, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Animation::mix (BaseSkeleton *skeleton, float time, bool loop, float alpha) {
|
||||||
|
if (!skeleton) throw std::invalid_argument("skeleton cannot be null.");
|
||||||
|
|
||||||
|
if (loop && duration) time = fmodf(time, duration);
|
||||||
|
|
||||||
|
for (int i = 0, n = timelines.size(); i < n; i++)
|
||||||
|
timelines[i]->apply(skeleton, time, alpha);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
static const float LINEAR = 0;
|
static const float LINEAR = 0;
|
||||||
|
|||||||
@ -45,6 +45,7 @@ BaseSkeleton::BaseSkeleton (SkeletonData *data) :
|
|||||||
drawOrder.reserve(slotCount);
|
drawOrder.reserve(slotCount);
|
||||||
for (int i = 0; i < slotCount; i++) {
|
for (int i = 0; i < slotCount; i++) {
|
||||||
SlotData *slotData = data->slots[i];
|
SlotData *slotData = data->slots[i];
|
||||||
|
// Find bone for the slotData's boneData.
|
||||||
Bone *bone;
|
Bone *bone;
|
||||||
for (int ii = 0; ii < boneCount; ii++) {
|
for (int ii = 0; ii < boneCount; ii++) {
|
||||||
if (data->bones[ii] == slotData->boneData) {
|
if (data->bones[ii] == slotData->boneData) {
|
||||||
|
|||||||
@ -2,8 +2,7 @@
|
|||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
<classpathentry kind="src" path="test"/>
|
<classpathentry kind="src" path="test"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/gdx-backend-jglfw"/>
|
||||||
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/gdx"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||||
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/gdx-backend-lwjgl"/>
|
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|||||||
@ -5,9 +5,9 @@ org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annota
|
|||||||
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
|
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
|
||||||
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
|
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
|
||||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.5
|
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
@ -92,4 +92,4 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enab
|
|||||||
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=ignore
|
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=ignore
|
||||||
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
|
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
|
||||||
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
|
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
|
||||||
org.eclipse.jdt.core.compiler.source=1.5
|
org.eclipse.jdt.core.compiler.source=1.6
|
||||||
|
|||||||
@ -5,25 +5,14 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
|||||||
|
|
||||||
abstract public class Attachment {
|
abstract public class Attachment {
|
||||||
final String name;
|
final String name;
|
||||||
boolean resolved;
|
|
||||||
|
|
||||||
public Attachment (String name) {
|
public Attachment (String name) {
|
||||||
if (name == null) throw new IllegalArgumentException("name cannot be null.");
|
if (name == null) throw new IllegalArgumentException("name cannot be null.");
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public void updateOffset ();
|
|
||||||
|
|
||||||
abstract public void draw (SpriteBatch batch, Slot slot);
|
abstract public void draw (SpriteBatch batch, Slot slot);
|
||||||
|
|
||||||
public boolean isResolved () {
|
|
||||||
return resolved;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResolved (boolean resolved) {
|
|
||||||
this.resolved = resolved;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName () {
|
public String getName () {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
package com.esotericsoftware.spine;
|
||||||
|
|
||||||
|
public interface AttachmentLoader {
|
||||||
|
public Attachment newAttachment (AttachmentType type, String name);
|
||||||
|
}
|
||||||
@ -1,6 +0,0 @@
|
|||||||
|
|
||||||
package com.esotericsoftware.spine;
|
|
||||||
|
|
||||||
public interface AttachmentResolver {
|
|
||||||
public void resolve (Attachment attachment);
|
|
||||||
}
|
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
package com.esotericsoftware.spine;
|
||||||
|
|
||||||
|
public enum AttachmentType {
|
||||||
|
region, regionSequence
|
||||||
|
}
|
||||||
@ -1,14 +1,11 @@
|
|||||||
|
|
||||||
package com.esotericsoftware.spine;
|
package com.esotericsoftware.spine;
|
||||||
|
|
||||||
import com.esotericsoftware.spine.Skin.Key;
|
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.ObjectMap.Entry;
|
|
||||||
|
|
||||||
public class Skeleton {
|
public class Skeleton {
|
||||||
final SkeletonData data;
|
final SkeletonData data;
|
||||||
@ -101,11 +98,7 @@ public class Skeleton {
|
|||||||
for (int i = 0, n = drawOrder.size; i < n; i++) {
|
for (int i = 0, n = drawOrder.size; i < n; i++) {
|
||||||
Slot slot = drawOrder.get(i);
|
Slot slot = drawOrder.get(i);
|
||||||
Attachment attachment = slot.attachment;
|
Attachment attachment = slot.attachment;
|
||||||
if (attachment != null) {
|
if (attachment != null) attachment.draw(batch, slot);
|
||||||
if (!attachment.resolved) data.attachmentResolver.resolve(attachment);
|
|
||||||
attachment.updateOffset();
|
|
||||||
attachment.draw(batch, slot);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,11 +227,16 @@ public class Skeleton {
|
|||||||
/** @param attachmentName May be null. */
|
/** @param attachmentName May be null. */
|
||||||
public void setAttachment (String slotName, String attachmentName) {
|
public void setAttachment (String slotName, String attachmentName) {
|
||||||
if (slotName == null) throw new IllegalArgumentException("slotName cannot be null.");
|
if (slotName == null) throw new IllegalArgumentException("slotName cannot be null.");
|
||||||
if (attachmentName == null) throw new IllegalArgumentException("attachmentName cannot be null.");
|
|
||||||
for (int i = 0, n = slots.size; i < n; i++) {
|
for (int i = 0, n = slots.size; i < n; i++) {
|
||||||
Slot slot = slots.get(i);
|
Slot slot = slots.get(i);
|
||||||
if (slot.data.name.equals(slotName)) {
|
if (slot.data.name.equals(slotName)) {
|
||||||
slot.setAttachment(getAttachment(i, attachmentName));
|
Attachment attachment = null;
|
||||||
|
if (attachmentName != null) {
|
||||||
|
attachment = getAttachment(i, attachmentName);
|
||||||
|
if (attachment == null)
|
||||||
|
throw new IllegalArgumentException("Attachment not found: " + attachmentName + ", for slot: " + slotName);
|
||||||
|
}
|
||||||
|
slot.setAttachment(attachment);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import com.esotericsoftware.spine.Animation.TranslateTimeline;
|
|||||||
import com.esotericsoftware.spine.attachments.RegionAttachment;
|
import com.esotericsoftware.spine.attachments.RegionAttachment;
|
||||||
import com.esotericsoftware.spine.attachments.RegionSequenceAttachment;
|
import com.esotericsoftware.spine.attachments.RegionSequenceAttachment;
|
||||||
import com.esotericsoftware.spine.attachments.RegionSequenceAttachment.Mode;
|
import com.esotericsoftware.spine.attachments.RegionSequenceAttachment.Mode;
|
||||||
import com.esotericsoftware.spine.attachments.TextureAtlasAttachmentResolver;
|
import com.esotericsoftware.spine.attachments.TextureAtlasAttachmentLoader;
|
||||||
|
|
||||||
import com.badlogic.gdx.files.FileHandle;
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
@ -29,22 +29,19 @@ public class SkeletonBinary {
|
|||||||
static public final int TIMELINE_ATTACHMENT = 3;
|
static public final int TIMELINE_ATTACHMENT = 3;
|
||||||
static public final int TIMELINE_COLOR = 4;
|
static public final int TIMELINE_COLOR = 4;
|
||||||
|
|
||||||
static public final int ATTACHMENT_REGION = 0;
|
|
||||||
static public final int ATTACHMENT_REGION_SEQUENCE = 1;
|
|
||||||
|
|
||||||
static public final int CURVE_LINEAR = 0;
|
static public final int CURVE_LINEAR = 0;
|
||||||
static public final int CURVE_STEPPED = 1;
|
static public final int CURVE_STEPPED = 1;
|
||||||
static public final int CURVE_BEZIER = 2;
|
static public final int CURVE_BEZIER = 2;
|
||||||
|
|
||||||
private final AttachmentResolver attachmentResolver;
|
private final AttachmentLoader attachmentLoader;
|
||||||
private float scale = 1;
|
private float scale = 1;
|
||||||
|
|
||||||
public SkeletonBinary (TextureAtlas atlas) {
|
public SkeletonBinary (TextureAtlas atlas) {
|
||||||
attachmentResolver = new TextureAtlasAttachmentResolver(atlas);
|
attachmentLoader = new TextureAtlasAttachmentLoader(atlas);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SkeletonBinary (AttachmentResolver attachmentResolver) {
|
public SkeletonBinary (AttachmentLoader attachmentLoader) {
|
||||||
this.attachmentResolver = attachmentResolver;
|
this.attachmentLoader = attachmentLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getScale () {
|
public float getScale () {
|
||||||
@ -59,7 +56,7 @@ public class SkeletonBinary {
|
|||||||
public SkeletonData readSkeletonData (FileHandle file) {
|
public SkeletonData readSkeletonData (FileHandle file) {
|
||||||
if (file == null) throw new IllegalArgumentException("file cannot be null.");
|
if (file == null) throw new IllegalArgumentException("file cannot be null.");
|
||||||
|
|
||||||
SkeletonData skeletonData = new SkeletonData(attachmentResolver);
|
SkeletonData skeletonData = new SkeletonData();
|
||||||
DataInput input = new DataInput(file.read(512));
|
DataInput input = new DataInput(file.read(512));
|
||||||
try {
|
try {
|
||||||
// Bones.
|
// Bones.
|
||||||
@ -134,19 +131,13 @@ public class SkeletonBinary {
|
|||||||
String name = input.readString();
|
String name = input.readString();
|
||||||
if (name == null) name = attachmentName;
|
if (name == null) name = attachmentName;
|
||||||
|
|
||||||
Attachment attachment;
|
AttachmentType type = AttachmentType.values()[input.readByte()];
|
||||||
int type = input.readByte();
|
Attachment attachment = attachmentLoader.newAttachment(type, name);
|
||||||
switch (type) {
|
|
||||||
case ATTACHMENT_REGION:
|
if (attachment instanceof RegionSequenceAttachment) {
|
||||||
attachment = new RegionAttachment(name);
|
RegionSequenceAttachment regionSequenceAttachment = (RegionSequenceAttachment)attachment;
|
||||||
break;
|
regionSequenceAttachment.setFrameTime(1 / input.readFloat());
|
||||||
case ATTACHMENT_REGION_SEQUENCE:
|
regionSequenceAttachment.setMode(Mode.values()[input.readInt(true)]);
|
||||||
float fps = input.readFloat();
|
|
||||||
Mode mode = Mode.values()[input.readInt(true)];
|
|
||||||
attachment = new RegionSequenceAttachment(name, 1 / fps, mode);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new SerializationException("Unknown attachment type: " + type + " (" + name + ")");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attachment instanceof RegionAttachment) {
|
if (attachment instanceof RegionAttachment) {
|
||||||
@ -158,8 +149,9 @@ public class SkeletonBinary {
|
|||||||
regionAttachment.setRotation(input.readFloat());
|
regionAttachment.setRotation(input.readFloat());
|
||||||
regionAttachment.setWidth(input.readFloat() * scale);
|
regionAttachment.setWidth(input.readFloat() * scale);
|
||||||
regionAttachment.setHeight(input.readFloat() * scale);
|
regionAttachment.setHeight(input.readFloat() * scale);
|
||||||
|
regionAttachment.updateOffset();
|
||||||
}
|
}
|
||||||
|
|
||||||
return attachment;
|
return attachment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,12 +8,6 @@ public class SkeletonData {
|
|||||||
final Array<SlotData> slots = new Array(); // Bind pose draw order.
|
final Array<SlotData> slots = new Array(); // Bind pose draw order.
|
||||||
final Array<Skin> skins = new Array();
|
final Array<Skin> skins = new Array();
|
||||||
Skin defaultSkin;
|
Skin defaultSkin;
|
||||||
final AttachmentResolver attachmentResolver;
|
|
||||||
|
|
||||||
public SkeletonData (AttachmentResolver attachmentResolver) {
|
|
||||||
if (attachmentResolver == null) throw new IllegalArgumentException("attachmentResolver cannot be null.");
|
|
||||||
this.attachmentResolver = attachmentResolver;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clear () {
|
public void clear () {
|
||||||
bones.clear();
|
bones.clear();
|
||||||
@ -22,10 +16,6 @@ public class SkeletonData {
|
|||||||
defaultSkin = null;
|
defaultSkin = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AttachmentResolver getAttachmentResolver () {
|
|
||||||
return attachmentResolver;
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Bones.
|
// --- Bones.
|
||||||
|
|
||||||
public void addBone (BoneData bone) {
|
public void addBone (BoneData bone) {
|
||||||
|
|||||||
@ -8,10 +8,10 @@ import com.esotericsoftware.spine.Animation.RotateTimeline;
|
|||||||
import com.esotericsoftware.spine.Animation.ScaleTimeline;
|
import com.esotericsoftware.spine.Animation.ScaleTimeline;
|
||||||
import com.esotericsoftware.spine.Animation.Timeline;
|
import com.esotericsoftware.spine.Animation.Timeline;
|
||||||
import com.esotericsoftware.spine.Animation.TranslateTimeline;
|
import com.esotericsoftware.spine.Animation.TranslateTimeline;
|
||||||
|
import com.esotericsoftware.spine.attachments.RegionAttachment;
|
||||||
import com.esotericsoftware.spine.attachments.RegionSequenceAttachment;
|
import com.esotericsoftware.spine.attachments.RegionSequenceAttachment;
|
||||||
import com.esotericsoftware.spine.attachments.RegionSequenceAttachment.Mode;
|
import com.esotericsoftware.spine.attachments.RegionSequenceAttachment.Mode;
|
||||||
import com.esotericsoftware.spine.attachments.RegionAttachment;
|
import com.esotericsoftware.spine.attachments.TextureAtlasAttachmentLoader;
|
||||||
import com.esotericsoftware.spine.attachments.TextureAtlasAttachmentResolver;
|
|
||||||
|
|
||||||
import com.badlogic.gdx.files.FileHandle;
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
@ -29,19 +29,16 @@ public class SkeletonJson {
|
|||||||
static public final String TIMELINE_ATTACHMENT = "attachment";
|
static public final String TIMELINE_ATTACHMENT = "attachment";
|
||||||
static public final String TIMELINE_COLOR = "color";
|
static public final String TIMELINE_COLOR = "color";
|
||||||
|
|
||||||
static public final String ATTACHMENT_REGION = "region";
|
|
||||||
static public final String ATTACHMENT_REGION_SEQUENCE = "regionSequence";
|
|
||||||
|
|
||||||
private final Json json = new Json();
|
private final Json json = new Json();
|
||||||
private final AttachmentResolver attachmentResolver;
|
private final AttachmentLoader attachmentLoader;
|
||||||
private float scale = 1;
|
private float scale = 1;
|
||||||
|
|
||||||
public SkeletonJson (TextureAtlas atlas) {
|
public SkeletonJson (TextureAtlas atlas) {
|
||||||
attachmentResolver = new TextureAtlasAttachmentResolver(atlas);
|
attachmentLoader = new TextureAtlasAttachmentLoader(atlas);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SkeletonJson (AttachmentResolver attachmentResolver) {
|
public SkeletonJson (AttachmentLoader attachmentLoader) {
|
||||||
this.attachmentResolver = attachmentResolver;
|
this.attachmentLoader = attachmentLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getScale () {
|
public float getScale () {
|
||||||
@ -56,7 +53,7 @@ public class SkeletonJson {
|
|||||||
public SkeletonData readSkeletonData (FileHandle file) {
|
public SkeletonData readSkeletonData (FileHandle file) {
|
||||||
if (file == null) throw new IllegalArgumentException("file cannot be null.");
|
if (file == null) throw new IllegalArgumentException("file cannot be null.");
|
||||||
|
|
||||||
SkeletonData skeletonData = new SkeletonData(attachmentResolver);
|
SkeletonData skeletonData = new SkeletonData();
|
||||||
|
|
||||||
OrderedMap<String, ?> root = json.fromJson(OrderedMap.class, file);
|
OrderedMap<String, ?> root = json.fromJson(OrderedMap.class, file);
|
||||||
|
|
||||||
@ -122,23 +119,20 @@ public class SkeletonJson {
|
|||||||
|
|
||||||
private Attachment readAttachment (String name, OrderedMap map) {
|
private Attachment readAttachment (String name, OrderedMap map) {
|
||||||
name = (String)map.get("name", name);
|
name = (String)map.get("name", name);
|
||||||
Attachment attachment;
|
|
||||||
String type = (String)map.get("type");
|
|
||||||
if (type == null) type = ATTACHMENT_REGION;
|
|
||||||
if (type.equals(ATTACHMENT_REGION)) {
|
|
||||||
attachment = new RegionAttachment(name);
|
|
||||||
|
|
||||||
} else if (type.equals(ATTACHMENT_REGION_SEQUENCE)) {
|
AttachmentType type = AttachmentType.valueOf((String)map.get("type", AttachmentType.region.name()));
|
||||||
|
Attachment attachment = attachmentLoader.newAttachment(type, name);
|
||||||
|
|
||||||
|
if (attachment instanceof RegionSequenceAttachment) {
|
||||||
|
RegionSequenceAttachment regionSequenceAttachment = (RegionSequenceAttachment)attachment;
|
||||||
|
|
||||||
Float fps = (Float)map.get("fps");
|
Float fps = (Float)map.get("fps");
|
||||||
if (fps == null) throw new SerializationException("Region sequence attachment missing fps: " + name);
|
if (fps == null) throw new SerializationException("Region sequence attachment missing fps: " + name);
|
||||||
|
regionSequenceAttachment.setFrameTime(fps);
|
||||||
|
|
||||||
String modeString = (String)map.get("mode");
|
String modeString = (String)map.get("mode");
|
||||||
Mode mode = modeString == null ? Mode.forward : Mode.valueOf(modeString);
|
regionSequenceAttachment.setMode(modeString == null ? Mode.forward : Mode.valueOf(modeString));
|
||||||
|
}
|
||||||
attachment = new RegionSequenceAttachment(name, 1 / fps, mode);
|
|
||||||
|
|
||||||
} else
|
|
||||||
throw new SerializationException("Unknown attachment type: " + type + " (" + name + ")");
|
|
||||||
|
|
||||||
if (attachment instanceof RegionAttachment) {
|
if (attachment instanceof RegionAttachment) {
|
||||||
RegionAttachment regionAttachment = (RegionAttachment)attachment;
|
RegionAttachment regionAttachment = (RegionAttachment)attachment;
|
||||||
@ -149,6 +143,7 @@ public class SkeletonJson {
|
|||||||
regionAttachment.setRotation(getFloat(map, "rotation", 0));
|
regionAttachment.setRotation(getFloat(map, "rotation", 0));
|
||||||
regionAttachment.setWidth(getFloat(map, "width", 32) * scale);
|
regionAttachment.setWidth(getFloat(map, "width", 32) * scale);
|
||||||
regionAttachment.setHeight(getFloat(map, "height", 32) * scale);
|
regionAttachment.setHeight(getFloat(map, "height", 32) * scale);
|
||||||
|
regionAttachment.updateOffset();
|
||||||
}
|
}
|
||||||
|
|
||||||
return attachment;
|
return attachment;
|
||||||
|
|||||||
@ -9,17 +9,12 @@ import com.badlogic.gdx.math.MathUtils;
|
|||||||
|
|
||||||
/** Attachment that displays various texture regions over time. */
|
/** Attachment that displays various texture regions over time. */
|
||||||
public class RegionSequenceAttachment extends RegionAttachment {
|
public class RegionSequenceAttachment extends RegionAttachment {
|
||||||
private final Mode mode;
|
private Mode mode;
|
||||||
private float frameTime;
|
private float frameTime;
|
||||||
private TextureRegion[] regions;
|
private TextureRegion[] regions;
|
||||||
|
|
||||||
/** @param frameTime Time in seconds each frame is shown. */
|
public RegionSequenceAttachment (String name) {
|
||||||
public RegionSequenceAttachment (String name, float frameTime, Mode mode) {
|
|
||||||
super(name);
|
super(name);
|
||||||
if (mode == null) throw new IllegalArgumentException("mode cannot be null.");
|
|
||||||
|
|
||||||
this.frameTime = frameTime;
|
|
||||||
this.mode = mode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw (SpriteBatch batch, Slot slot) {
|
public void draw (SpriteBatch batch, Slot slot) {
|
||||||
@ -62,6 +57,15 @@ public class RegionSequenceAttachment extends RegionAttachment {
|
|||||||
this.regions = regions;
|
this.regions = regions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Sets the time in seconds each frame is shown. */
|
||||||
|
public void setFrameTime (float frameTime) {
|
||||||
|
this.frameTime = frameTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMode (Mode mode) {
|
||||||
|
this.mode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
static public enum Mode {
|
static public enum Mode {
|
||||||
forward, backward, forwardLoop, backwardLoop, pingPong, random
|
forward, backward, forwardLoop, backwardLoop, pingPong, random
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,41 @@
|
|||||||
|
|
||||||
|
package com.esotericsoftware.spine.attachments;
|
||||||
|
|
||||||
|
import com.esotericsoftware.spine.Attachment;
|
||||||
|
import com.esotericsoftware.spine.AttachmentLoader;
|
||||||
|
import com.esotericsoftware.spine.AttachmentType;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
|
||||||
|
|
||||||
|
public class TextureAtlasAttachmentLoader implements AttachmentLoader {
|
||||||
|
private TextureAtlas atlas;
|
||||||
|
|
||||||
|
public TextureAtlasAttachmentLoader (TextureAtlas atlas) {
|
||||||
|
if (atlas == null) throw new IllegalArgumentException("atlas cannot be null.");
|
||||||
|
this.atlas = atlas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Attachment newAttachment (AttachmentType type, String name) {
|
||||||
|
Attachment attachment = null;
|
||||||
|
switch (type) {
|
||||||
|
case region:
|
||||||
|
attachment = new RegionAttachment(name);
|
||||||
|
break;
|
||||||
|
case regionSequence:
|
||||||
|
attachment = new RegionAttachment(name);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Unknown attachment type: " + type);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attachment instanceof RegionAttachment) {
|
||||||
|
AtlasRegion region = atlas.findRegion(attachment.getName());
|
||||||
|
if (region == null)
|
||||||
|
throw new RuntimeException("Region not found in atlas: " + attachment + " (" + type + " attachment: " + name + ")");
|
||||||
|
((RegionAttachment)attachment).setRegion(region);
|
||||||
|
}
|
||||||
|
|
||||||
|
return attachment;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,29 +0,0 @@
|
|||||||
|
|
||||||
package com.esotericsoftware.spine.attachments;
|
|
||||||
|
|
||||||
import com.esotericsoftware.spine.Attachment;
|
|
||||||
import com.esotericsoftware.spine.AttachmentResolver;
|
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
|
|
||||||
|
|
||||||
public class TextureAtlasAttachmentResolver implements AttachmentResolver {
|
|
||||||
private TextureAtlas atlas;
|
|
||||||
|
|
||||||
public TextureAtlasAttachmentResolver (TextureAtlas atlas) {
|
|
||||||
if (atlas == null) throw new IllegalArgumentException("atlas cannot be null.");
|
|
||||||
this.atlas = atlas;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void resolve (Attachment attachment) {
|
|
||||||
if (attachment instanceof RegionAttachment) {
|
|
||||||
AtlasRegion region = atlas.findRegion(attachment.getName());
|
|
||||||
if (region == null) throw new RuntimeException("Region not found in atlas: " + attachment);
|
|
||||||
((RegionAttachment)attachment).setRegion(region);
|
|
||||||
attachment.setResolved(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new IllegalArgumentException("Unable to resolve attachment of type: " + attachment.getClass().getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -3,10 +3,8 @@ package com.esotericsoftware.spine;
|
|||||||
|
|
||||||
import com.badlogic.gdx.ApplicationAdapter;
|
import com.badlogic.gdx.ApplicationAdapter;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Input.Keys;
|
import com.badlogic.gdx.backends.jglfw.JglfwApplication;
|
||||||
import com.badlogic.gdx.InputAdapter;
|
import com.badlogic.gdx.backends.jglfw.JglfwApplicationConfiguration;
|
||||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
|
|
||||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.GL10;
|
import com.badlogic.gdx.graphics.GL10;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
@ -115,10 +113,10 @@ public class MixTest extends ApplicationAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main (String[] args) throws Exception {
|
public static void main (String[] args) throws Exception {
|
||||||
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
|
JglfwApplicationConfiguration config = new JglfwApplicationConfiguration();
|
||||||
config.title = "Mix Test";
|
config.title = "Mix Test";
|
||||||
config.width = 640;
|
config.width = 640;
|
||||||
config.height = 480;
|
config.height = 480;
|
||||||
new LwjglApplication(new MixTest(), config);
|
new JglfwApplication(new MixTest(), config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,8 +5,8 @@ import com.badlogic.gdx.ApplicationAdapter;
|
|||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Input.Keys;
|
import com.badlogic.gdx.Input.Keys;
|
||||||
import com.badlogic.gdx.InputAdapter;
|
import com.badlogic.gdx.InputAdapter;
|
||||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
|
import com.badlogic.gdx.backends.jglfw.JglfwApplication;
|
||||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
|
import com.badlogic.gdx.backends.jglfw.JglfwApplicationConfiguration;
|
||||||
import com.badlogic.gdx.files.FileHandle;
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.GL10;
|
import com.badlogic.gdx.graphics.GL10;
|
||||||
@ -114,10 +114,10 @@ public class SkeletonTest extends ApplicationAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main (String[] args) throws Exception {
|
public static void main (String[] args) throws Exception {
|
||||||
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
|
JglfwApplicationConfiguration config = new JglfwApplicationConfiguration();
|
||||||
config.title = "Skeleton Test";
|
config.title = "Skeleton Test";
|
||||||
config.width = 640;
|
config.width = 640;
|
||||||
config.height = 480;
|
config.height = 480;
|
||||||
new LwjglApplication(new SkeletonTest(), config);
|
new JglfwApplication(new SkeletonTest(), config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,9 +41,6 @@
|
|||||||
],
|
],
|
||||||
"skins": {
|
"skins": {
|
||||||
"default": {
|
"default": {
|
||||||
"template": {
|
|
||||||
"spineboy": { "y": 167.82, "width": 145, "height": 341 }
|
|
||||||
},
|
|
||||||
"left shoulder": {
|
"left shoulder": {
|
||||||
"left-shoulder": { "x": 23.74, "y": 0.11, "rotation": 62.01, "width": 34, "height": 53 }
|
"left-shoulder": { "x": 23.74, "y": 0.11, "rotation": 62.01, "width": 34, "height": 53 }
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user