From 1c2554c178f4027d55254f257ad79bb5c5723224 Mon Sep 17 00:00:00 2001 From: Disk1of5 Date: Thu, 14 Mar 2013 22:32:25 -0600 Subject: [PATCH 1/2] Added: *AnimationState.java *AnimationStateTest.java Updated: *Git ignore to ignore all LibGDX libs. *MixTest.Java -- Reverted back to LWJGL *SkeletonTest.java -- Reverted back to LWJGL A few Idea project files where added. I left these in for easy future development with Intellij Idea. --- .gitignore | 7 +- spine-libgdx/.classpath | 13 +- spine-libgdx/spine-libgdx.iml | 24 + spine-libgdx/spine-libgdx.ipr | 169 ++++ spine-libgdx/spine-libgdx.iws | 828 ++++++++++++++++++ .../spine/AnimationState.java | 97 ++ .../spine/AnimationStatesTest.java | 77 ++ .../com/esotericsoftware/spine/MixTest.java | 8 +- .../esotericsoftware/spine/SkeletonTest.java | 8 +- 9 files changed, 1212 insertions(+), 19 deletions(-) create mode 100644 spine-libgdx/spine-libgdx.iml create mode 100644 spine-libgdx/spine-libgdx.ipr create mode 100644 spine-libgdx/spine-libgdx.iws create mode 100644 spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java create mode 100644 spine-libgdx/test/com/esotericsoftware/spine/AnimationStatesTest.java diff --git a/.gitignore b/.gitignore index c32fc32a5..a0f781753 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,4 @@ spine-cpp/Debug/* spine-libgdx/bin/* -spine-libgdx/libs/gdx-backend-lwjgl-natives.jar -spine-libgdx/libs/gdx-backend-lwjgl.jar -spine-libgdx/libs/gdx-natives.jar -spine-libgdx/libs/gdx.jar -target \ No newline at end of file +spine-libgdx/libs/* +target diff --git a/spine-libgdx/.classpath b/spine-libgdx/.classpath index 962e3a64c..1aaca62e4 100644 --- a/spine-libgdx/.classpath +++ b/spine-libgdx/.classpath @@ -1,8 +1,9 @@ - + - - - - - + + + + + + diff --git a/spine-libgdx/spine-libgdx.iml b/spine-libgdx/spine-libgdx.iml new file mode 100644 index 000000000..0a96da4fc --- /dev/null +++ b/spine-libgdx/spine-libgdx.iml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spine-libgdx/spine-libgdx.ipr b/spine-libgdx/spine-libgdx.ipr new file mode 100644 index 000000000..8055423e4 --- /dev/null +++ b/spine-libgdx/spine-libgdx.ipr @@ -0,0 +1,169 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spine-libgdx/spine-libgdx.iws b/spine-libgdx/spine-libgdx.iws new file mode 100644 index 000000000..dc9a382e9 --- /dev/null +++ b/spine-libgdx/spine-libgdx.iws @@ -0,0 +1,828 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Android Lint + + + GSPGrailsGroovy + + + Google Web Toolkit issues + + + GrailsGroovy + + + Groovy + + + J2ME Plugin + + + OSGi + + + Plugin DevKit + + + XPath + + + + + Abstraction issues + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + localhost + 5050 + + + + + + + + + 1363316179454 + 1363316179454 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No facets are configured + + + + + + + + jQuery + + + + + + + + 1.7 + + + + + + + + spine-libgdx + + + + + + + + 1.7 + + + + + + + + + + + + + + + + diff --git a/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java b/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java new file mode 100644 index 000000000..3e706e500 --- /dev/null +++ b/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java @@ -0,0 +1,97 @@ + +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; + +public class AnimationState { + Animation current; + float currentTime; + boolean currentLoop; + Animation previous; + float previousTime; + boolean previousLoop; + float mixTime, mixDuration; + Key tempKey = new Key(); + ObjectMap animationToMixTime = new ObjectMap(); + + public void apply (Skeleton skeleton) { + if (current == null) return; + if (previous != null) { + previous.apply(skeleton, previousTime, previousLoop); + float alpha = MathUtils.clamp(mixTime / mixDuration, 0, 1); + current.mix(skeleton, currentTime, currentLoop, alpha); + if (alpha == 1) previous = null; + } else { + current.apply(skeleton, currentTime, currentLoop); + } + } + + public void update (float delta) { + currentTime += delta; + previousTime += delta; + mixTime += delta; + } + + 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."); + Key key = new Key(); + key.a1 = from; + key.a2 = to; + animationToMixTime.put(key, duration); + } + + public void setAnimation (Animation animation, boolean loop) { + setAnimation(animation, loop, 0); + } + + public void setAnimation (Animation animation, boolean loop, float time) { + previous = null; + if (animation != null && current != null) { + tempKey.a1 = current; + tempKey.a2 = animation; + if (animationToMixTime.containsKey(tempKey)) { + mixDuration = animationToMixTime.get(tempKey); + mixTime = 0; + previous = current; + } + } + current = animation; + currentLoop = loop; + currentTime = time; + } + + /** @return May be null. */ + public Animation getAnimation () { + return current; + } + + public float getTime () { + return currentTime; + } + + static class Key { + Animation a1, a2; + + public int hashCode () { + return 31 * (31 + a1.hashCode()) + a2.hashCode(); + } + + public boolean equals (Object obj) { + if (this == obj) return true; + if (obj == null) return false; + Key other = (Key)obj; + if (a1 == null) { + if (other.a1 != null) return false; + } else if (!a1.equals(other.a1)) return false; + if (a2 == null) { + if (other.a2 != null) return false; + } else if (!a2.equals(other.a2)) return false; + return true; + } + } +} diff --git a/spine-libgdx/test/com/esotericsoftware/spine/AnimationStatesTest.java b/spine-libgdx/test/com/esotericsoftware/spine/AnimationStatesTest.java new file mode 100644 index 000000000..64348428c --- /dev/null +++ b/spine-libgdx/test/com/esotericsoftware/spine/AnimationStatesTest.java @@ -0,0 +1,77 @@ + +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 { + SpriteBatch batch; + ShapeRenderer renderer; + + TextureAtlas atlas; + Skeleton skeleton; + Animation walkAnimation; + Animation jumpAnimation; + Bone root; + AnimationState state; + + public void create () { + batch = new SpriteBatch(); + renderer = new ShapeRenderer(); + + atlas = new TextureAtlas(Gdx.files.internal("spineboy.atlas")); + SkeletonJson json = new SkeletonJson(atlas); + SkeletonData skeletonData = json.readSkeletonData(Gdx.files.internal("spineboy-skeleton.json")); + walkAnimation = json.readAnimation(Gdx.files.internal("spineboy-walk.json"), skeletonData); + jumpAnimation = json.readAnimation(Gdx.files.internal("spineboy-jump.json"), skeletonData); + + state = new AnimationState(); + state.setMixing(walkAnimation, jumpAnimation, 0.4f); + state.setAnimation(walkAnimation, true); + + skeleton = new Skeleton(skeletonData); + + root = skeleton.getRootBone(); + root.setX(250); + root.setY(20); + + skeleton.updateWorldTransform(); + } + + public void render () { + state.update(Gdx.graphics.getDeltaTime() / 1); //Change the value of the integer to modify animation speed. Increase to slow Speed. + + Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); + batch.begin(); + + state.apply(skeleton); + if (state.getTime() > 1 && state.getAnimation() == walkAnimation) state.setAnimation(jumpAnimation, false); + skeleton.updateWorldTransform(); + skeleton.draw(batch); + + batch.end(); + } + + public void resize (int width, int height) { + batch.getProjectionMatrix().setToOrtho2D(0, 0, width, height); + renderer.setProjectionMatrix(batch.getProjectionMatrix()); + } + + public void dispose () { + atlas.dispose(); + } + + public static void main (String[] args) throws Exception { + LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); + config.title = "AnimationStates - Spine"; + config.width = 640; + config.height = 480; + new LwjglApplication(new AnimationStatesTest(), config); + } +} diff --git a/spine-libgdx/test/com/esotericsoftware/spine/MixTest.java b/spine-libgdx/test/com/esotericsoftware/spine/MixTest.java index 85e987e6f..aca01dce8 100644 --- a/spine-libgdx/test/com/esotericsoftware/spine/MixTest.java +++ b/spine-libgdx/test/com/esotericsoftware/spine/MixTest.java @@ -3,8 +3,8 @@ package com.esotericsoftware.spine; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.backends.jglfw.JglfwApplication; -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.GL10; import com.badlogic.gdx.graphics.g2d.SpriteBatch; @@ -113,10 +113,10 @@ public class MixTest extends ApplicationAdapter { } public static void main (String[] args) throws Exception { - JglfwApplicationConfiguration config = new JglfwApplicationConfiguration(); + LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); config.title = "Mix Test"; config.width = 640; config.height = 480; - new JglfwApplication(new MixTest(), config); + new LwjglApplication(new MixTest(), config); } } diff --git a/spine-libgdx/test/com/esotericsoftware/spine/SkeletonTest.java b/spine-libgdx/test/com/esotericsoftware/spine/SkeletonTest.java index 71cc84453..b011b7915 100644 --- a/spine-libgdx/test/com/esotericsoftware/spine/SkeletonTest.java +++ b/spine-libgdx/test/com/esotericsoftware/spine/SkeletonTest.java @@ -5,8 +5,8 @@ import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.InputAdapter; -import com.badlogic.gdx.backends.jglfw.JglfwApplication; -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.files.FileHandle; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL10; @@ -114,10 +114,10 @@ public class SkeletonTest extends ApplicationAdapter { } public static void main (String[] args) throws Exception { - JglfwApplicationConfiguration config = new JglfwApplicationConfiguration(); + LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); config.title = "Skeleton Test"; config.width = 640; config.height = 480; - new JglfwApplication(new SkeletonTest(), config); + new LwjglApplication(new SkeletonTest(), config); } } From 827cb592c95e2fbc3fbfe02d35f12cca744b5635 Mon Sep 17 00:00:00 2001 From: Disk1of5 Date: Fri, 15 Mar 2013 12:02:15 -0600 Subject: [PATCH 2/2] **Updated AnimationStatesTest.Java to match the LwjglApplication launcher of the other examples. -Disk1of5 --- spine-libgdx/spine-libgdx.iws | 84 +++++++++---------- .../spine/AnimationStatesTest.java | 5 +- 2 files changed, 43 insertions(+), 46 deletions(-) diff --git a/spine-libgdx/spine-libgdx.iws b/spine-libgdx/spine-libgdx.iws index aea8c1e03..829444bc1 100644 --- a/spine-libgdx/spine-libgdx.iws +++ b/spine-libgdx/spine-libgdx.iws @@ -22,6 +22,7 @@ + - @@ -75,10 +75,10 @@ - + - + @@ -86,10 +86,10 @@ - + - + @@ -98,7 +98,7 @@ - + @@ -152,7 +152,7 @@ - + @@ -176,10 +176,10 @@ - @@ -338,9 +338,9 @@ - - + + @@ -363,19 +363,6 @@ - - + + @@ -543,19 +543,19 @@ + - - - + + - + @@ -670,7 +670,7 @@ - + @@ -708,29 +708,29 @@ - - - - - - - - + - + + + + + + + + diff --git a/spine-libgdx/test/com/esotericsoftware/spine/AnimationStatesTest.java b/spine-libgdx/test/com/esotericsoftware/spine/AnimationStatesTest.java index 64348428c..fcfbe67b3 100644 --- a/spine-libgdx/test/com/esotericsoftware/spine/AnimationStatesTest.java +++ b/spine-libgdx/test/com/esotericsoftware/spine/AnimationStatesTest.java @@ -69,9 +69,6 @@ public class AnimationStatesTest extends ApplicationAdapter { public static void main (String[] args) throws Exception { LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); - config.title = "AnimationStates - Spine"; - config.width = 640; - config.height = 480; - new LwjglApplication(new AnimationStatesTest(), config); + new LwjglApplication(new AnimationStatesTest()); } }