mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
Names for animation and skeleton.
This commit is contained in:
parent
d07321c9e7
commit
159d076f79
@ -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;
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user