-
-
-
-
-
-
-
diff --git a/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java b/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java
index 3e706e500..07cd2073f 100644
--- a/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java
+++ b/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java
@@ -1,22 +1,17 @@
package com.esotericsoftware.spine;
-import com.esotericsoftware.spine.Animation;
-import com.esotericsoftware.spine.Skeleton;
-
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.utils.ObjectMap;
+/** Stores mixing times between animations and automatically mixes them as animations change. */
public class AnimationState {
- Animation current;
- float currentTime;
- boolean currentLoop;
- Animation previous;
- float previousTime;
- boolean previousLoop;
+ Animation current, previous;
+ float currentTime, previousTime;
+ boolean currentLoop, previousLoop;
float mixTime, mixDuration;
- Key tempKey = new Key();
- ObjectMap animationToMixTime = new ObjectMap();
+ final ObjectMap animationToMixTime = new ObjectMap();
+ final Key tempKey = new Key();
public void apply (Skeleton skeleton) {
if (current == null) return;
@@ -36,6 +31,7 @@ public class AnimationState {
mixTime += delta;
}
+ /** Set the mixing duration between two animations. */
public void setMixing (Animation from, Animation to, float duration) {
if (from == null) throw new IllegalArgumentException("from cannot be null.");
if (to == null) throw new IllegalArgumentException("to cannot be null.");
@@ -45,10 +41,13 @@ public class AnimationState {
animationToMixTime.put(key, duration);
}
+ /** Set the current animation. */
public void setAnimation (Animation animation, boolean loop) {
setAnimation(animation, loop, 0);
}
+ /** Set the current animation.
+ * @param time The time within the animation to start. */
public void setAnimation (Animation animation, boolean loop, float time) {
previous = null;
if (animation != null && current != null) {
@@ -70,6 +69,7 @@ public class AnimationState {
return current;
}
+ /** Returns the time within the current animation. */
public float getTime () {
return currentTime;
}
diff --git a/spine-libgdx/test/com/esotericsoftware/spine/AnimationStatesTest.java b/spine-libgdx/test/com/esotericsoftware/spine/AnimationStateTest.java
similarity index 82%
rename from spine-libgdx/test/com/esotericsoftware/spine/AnimationStatesTest.java
rename to spine-libgdx/test/com/esotericsoftware/spine/AnimationStateTest.java
index fcfbe67b3..1d1ea8f35 100644
--- a/spine-libgdx/test/com/esotericsoftware/spine/AnimationStatesTest.java
+++ b/spine-libgdx/test/com/esotericsoftware/spine/AnimationStateTest.java
@@ -4,13 +4,12 @@ package com.esotericsoftware.spine;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
-import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
-public class AnimationStatesTest extends ApplicationAdapter {
+public class AnimationStateTest extends ApplicationAdapter {
SpriteBatch batch;
ShapeRenderer renderer;
@@ -32,7 +31,9 @@ public class AnimationStatesTest extends ApplicationAdapter {
jumpAnimation = json.readAnimation(Gdx.files.internal("spineboy-jump.json"), skeletonData);
state = new AnimationState();
+ // Define mixing from one animation to another.
state.setMixing(walkAnimation, jumpAnimation, 0.4f);
+ // Set current animation.
state.setAnimation(walkAnimation, true);
skeleton = new Skeleton(skeletonData);
@@ -45,12 +46,13 @@ public class AnimationStatesTest extends ApplicationAdapter {
}
public void render () {
- state.update(Gdx.graphics.getDeltaTime() / 1); //Change the value of the integer to modify animation speed. Increase to slow Speed.
+ state.update(Gdx.graphics.getDeltaTime());
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.begin();
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);
skeleton.updateWorldTransform();
skeleton.draw(batch);
@@ -68,7 +70,6 @@ public class AnimationStatesTest extends ApplicationAdapter {
}
public static void main (String[] args) throws Exception {
- LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
- new LwjglApplication(new AnimationStatesTest());
+ new LwjglApplication(new AnimationStateTest());
}
}
diff --git a/spine-libgdx/test/com/esotericsoftware/spine/MixTest.java b/spine-libgdx/test/com/esotericsoftware/spine/MixTest.java
index c63be69cc..6e70dd44a 100644
--- a/spine-libgdx/test/com/esotericsoftware/spine/MixTest.java
+++ b/spine-libgdx/test/com/esotericsoftware/spine/MixTest.java
@@ -75,6 +75,7 @@ public class MixTest extends ApplicationAdapter {
batch.begin();
batch.setColor(Color.GRAY);
+ // This shows how to manage state manually. See AnimationStatesTest.
if (time > total) {
// restart
time = 0;