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/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..829444bc1 --- /dev/null +++ b/spine-libgdx/spine-libgdx.iws @@ -0,0 +1,823 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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..fcfbe67b3 --- /dev/null +++ b/spine-libgdx/test/com/esotericsoftware/spine/AnimationStatesTest.java @@ -0,0 +1,74 @@ + +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(); + new LwjglApplication(new AnimationStatesTest()); + } +}