Names for animation and skeleton.

This commit is contained in:
NathanSweet 2013-03-22 12:57:03 +01:00
parent d07321c9e7
commit 159d076f79
7 changed files with 50 additions and 2 deletions

View File

@ -30,6 +30,7 @@ import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.utils.Array;
public class Animation {
private String name;
private final Array<Timeline> timelines;
private float duration;
@ -76,6 +77,20 @@ public class Animation {
timelines.get(i).apply(skeleton, time, alpha);
}
/** @return May be null. */
public String getName () {
return name;
}
/** @param name May be null. */
public void setName (String name) {
this.name = name;
}
public String toString () {
return name != null ? name : super.toString();
}
/** @param target After the first and before the last entry. */
static int binarySearch (float[] values, float target, int step) {
int low = 0;

View File

@ -95,4 +95,8 @@ public class AnimationState {
public AnimationStateData getData () {
return data;
}
public String toString () {
return (current != null && current.getName() != null) ? current.getName() : super.toString();
}
}

View File

@ -298,4 +298,8 @@ public class Skeleton {
public void update (float delta) {
time += delta;
}
public String toString () {
return data.name != null ? data.name : super.toString();
}
}

View File

@ -81,6 +81,8 @@ public class SkeletonBinary {
if (file == null) throw new IllegalArgumentException("file cannot be null.");
SkeletonData skeletonData = new SkeletonData();
skeletonData.setName(file.nameWithoutExtension());
DataInput input = new DataInput(file.read(512));
try {
// Bones.
@ -274,7 +276,9 @@ public class SkeletonBinary {
}
timelines.shrink();
return new Animation(timelines, duration);
Animation animation = new Animation(timelines, duration);
animation.setName(file.nameWithoutExtension());
return animation;
}
private void readCurve (DataInput input, int keyframeIndex, CurveTimeline timeline) throws IOException {

View File

@ -28,6 +28,7 @@ package com.esotericsoftware.spine;
import com.badlogic.gdx.utils.Array;
public class SkeletonData {
String name;
final Array<BoneData> bones = new Array(); // Ordered parents first.
final Array<SlotData> slots = new Array(); // Bind pose draw order.
final Array<Skin> skins = new Array();
@ -131,4 +132,20 @@ public class SkeletonData {
public Array<Skin> getSkins () {
return skins;
}
// ---
/** @return May be null. */
public String getName () {
return name;
}
/** @param name May be null. */
public void setName (String name) {
this.name = name;
}
public String toString () {
return name != null ? name : super.toString();
}
}

View File

@ -78,6 +78,7 @@ public class SkeletonJson {
if (file == null) throw new IllegalArgumentException("file cannot be null.");
SkeletonData skeletonData = new SkeletonData();
skeletonData.setName(file.nameWithoutExtension());
OrderedMap<String, ?> root = json.fromJson(OrderedMap.class, file);
@ -284,7 +285,9 @@ public class SkeletonJson {
}
timelines.shrink();
return new Animation(timelines, duration);
Animation animation = new Animation(timelines, duration);
animation.setName(file.nameWithoutExtension());
return animation;
}
private void readCurve (CurveTimeline timeline, int keyframeIndex, OrderedMap valueMap) {

View File

@ -76,6 +76,7 @@ public class AnimationStateTest extends ApplicationAdapter {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.begin();
System.out.println(skeleton);
state.apply(skeleton);
// After one second, change the current animation. Mixing is done by AnimationState for you.
if (state.getTime() > 1 && state.getAnimation() == walkAnimation) state.setAnimation(jumpAnimation, false);