From 55550c3490f9c54d24b5f6e102c04e4bba001d3c Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Thu, 18 Jan 2024 09:57:15 -0400 Subject: [PATCH] [libgdx] Added skeleton.update(delta) to examples, even when physics is not used. --- .../esotericsoftware/spine/BonePlotting.java | 1 + .../esotericsoftware/spine/Box2DExample.java | 1 + .../com/esotericsoftware/spine/IKTest.java | 49 +++++++------------ .../spine/MixAndMatchTest.java | 4 +- .../esotericsoftware/spine/NormalMapTest.java | 4 +- .../esotericsoftware/spine/PngExportTest.java | 1 + .../esotericsoftware/spine/SimpleTest1.java | 4 +- .../esotericsoftware/spine/SimpleTest3.java | 4 +- .../spine/SkeletonAssetManagerTest.java | 4 +- .../spine/SkeletonAttachmentTest.java | 5 +- .../esotericsoftware/spine/TestHarness.java | 10 ++-- .../spine/TimelineApiTest.java | 1 + .../spine/PhysicsConstraint.java | 3 ++ 13 files changed, 48 insertions(+), 43 deletions(-) diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/BonePlotting.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/BonePlotting.java index 6451ae162..6d1c23688 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/BonePlotting.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/BonePlotting.java @@ -84,6 +84,7 @@ public PointAttachment newPointAttachment (Skin skin, String name) { float time = 0; while (time < animation.getDuration()) { animation.apply(skeleton, time, time, false, null, 1, MixBlend.first, MixDirection.in); + skeleton.update(fps); skeleton.updateWorldTransform(Physics.update); System.out.println(animation.getName() + "," // diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/Box2DExample.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/Box2DExample.java index caf1c4b63..a67d130d1 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/Box2DExample.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/Box2DExample.java @@ -151,6 +151,7 @@ public void render () { animation.apply(skeleton, time, time, true, events, 1, MixBlend.first, MixDirection.in); skeleton.x += 8 * delta; + skeleton.update(delta); skeleton.updateWorldTransform(Physics.update); skeletonRenderer.draw(batch, skeleton); diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/IKTest.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/IKTest.java index 0ea9f26de..085f6073a 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/IKTest.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/IKTest.java @@ -79,39 +79,29 @@ public void create () { // Queue the "walk" animation on the first track. state.setAnimation(0, "walk", true); - // Queue the "aim" animation on a higher track. - // It consists of a single frame that positions - // the back arm and gun such that they point at - // the "crosshair" bone. By setting this - // animation on a higher track, it overrides - // any changes to the back arm and gun made - // by the walk animation, allowing us to - // mix the two. The mouse position following - // is performed in the render() method below. + // Queue the "aim" animation on a higher track. It consists of a single frame that positions the back arm and gun such that + // they point at the "crosshair" bone. By setting this animation on a higher track, it overrides any changes to the back arm + // and gun made by the walk animation, allowing us to mix the two. The mouse position following is performed in the render() + // method below. state.setAnimation(1, "aim", true); } public void render () { - // Update and apply the animations to the skeleton, - // then calculate the world transforms of every bone. - // This is needed so we can call Bone#worldToLocal() - // later. - state.update(Gdx.graphics.getDeltaTime()); + // Update and apply the animations to the skeleton, then calculate the world transforms of every bone. This is needed so we + // can call Bone#worldToLocal() later. + float delta = Gdx.graphics.getDeltaTime(); + state.update(delta); state.apply(skeleton); - skeleton.updateWorldTransform(Physics.update); + skeleton.update(delta); + // This example has no physics, but if it did we first pose the skeleton without physics. + skeleton.updateWorldTransform(Physics.pose); - // Position the "crosshair" bone at the mouse - // location. We do this before calling - // skeleton.updateWorldTransform() below, so - // our change is incorporated before the IK - // constraint is applied. + // Position the "crosshair" bone at the mouse location. We do this before calling skeleton.updateWorldTransform() below, so + // our change is incorporated before the IK constraint is applied. // - // When setting the crosshair bone position - // to the mouse position, we need to translate - // from "mouse space" to "camera space" - // and then to "local bone space". Note that the local - // bone space is calculated using the bone's parent - // worldToLocal() function! + // When setting the crosshair bone position to the mouse position, we need to translate from "mouse space" to "camera space" + // and then to "local bone space". Note that the local bone space is calculated using the bone's parent worldToLocal() + // function! cameraCoords.set(Gdx.input.getX(), Gdx.input.getY(), 0); camera.unproject(cameraCoords); // mouse space to camera space @@ -120,13 +110,10 @@ public void render () { crosshair.getParent().worldToLocal(boneCoords); // camera space to local bone space crosshair.setPosition(boneCoords.x, boneCoords.y); // override the crosshair position - // Calculate final world transform with the - // crosshair bone set to the mouse cursor - // position. + // Calculate final world transform with the crosshair bone set to the mouse cursor position. Update physics this time. skeleton.updateWorldTransform(Physics.update); - // Clear the screen, update the camera and - // render the skeleton. + // Clear the screen, update the camera and render the skeleton. ScreenUtils.clear(0, 0, 0, 0); camera.update(); diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/MixAndMatchTest.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/MixAndMatchTest.java index 34fccbe31..ce1939f98 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/MixAndMatchTest.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/MixAndMatchTest.java @@ -89,11 +89,13 @@ public void create () { } public void render () { - state.update(Gdx.graphics.getDeltaTime()); // Update the animation time. + float delta = Gdx.graphics.getDeltaTime(); + state.update(delta); // Update the animation time. ScreenUtils.clear(0, 0, 0, 0); state.apply(skeleton); // Poses skeleton using current animations. This sets the bones' local SRT. + skeleton.update(delta); skeleton.updateWorldTransform(Physics.update); // Uses the bones' local SRT to compute their world SRT. // Configure the camera, and PolygonSpriteBatch diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/NormalMapTest.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/NormalMapTest.java index 0743ef562..4830a6b4e 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/NormalMapTest.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/NormalMapTest.java @@ -135,8 +135,10 @@ public boolean touchUp (int screenX, int screenY, int pointer, int button) { public void render () { float lastTime = time; - time += Gdx.graphics.getDeltaTime(); + float delta = Gdx.graphics.getDeltaTime(); + time += delta; if (animation != null) animation.apply(skeleton, lastTime, time, true, null, 1, MixBlend.first, MixDirection.in); + skeleton.update(delta); skeleton.updateWorldTransform(Physics.update); lightPosition.x = Gdx.input.getX(); diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/PngExportTest.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/PngExportTest.java index 4259e0c42..a13a94c32 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/PngExportTest.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/PngExportTest.java @@ -105,6 +105,7 @@ public void create () { int frame = 1; while (time < animation.getDuration()) { animation.apply(skeleton, time, time, false, null, 1, MixBlend.first, MixDirection.in); + skeleton.update(fps); skeleton.updateWorldTransform(Physics.update); // Render the skeleton to the FBO. diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest1.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest1.java index 01da7087c..65777d75b 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest1.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest1.java @@ -82,11 +82,13 @@ public void create () { } public void render () { - state.update(Gdx.graphics.getDeltaTime()); // Update the animation time. + float delta = Gdx.graphics.getDeltaTime(); + state.update(delta); // Update the animation time. Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); state.apply(skeleton); // Poses skeleton using current animations. This sets the bones' local SRT. + skeleton.update(delta); // Advance the skeleton time. This is needed when the skeleton has physics. skeleton.updateWorldTransform(Physics.update); // Uses the bones' local SRT to compute their world SRT. // Configure the camera, SpriteBatch, and SkeletonRendererDebug. diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest3.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest3.java index 90aa9fda2..7111290e4 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest3.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest3.java @@ -81,10 +81,12 @@ public void create () { } public void render () { - state.update(Gdx.graphics.getDeltaTime()); // Update the animation time. + float delta = Gdx.graphics.getDeltaTime(); + state.update(delta); // Update the animation time. ScreenUtils.clear(0, 0, 0, 0); + skeleton.update(delta); // Advance the skeleton time. This is needed when the skeleton has physics. if (state.apply(skeleton)) // Poses skeleton using current animations. This sets the bones' local SRT. skeleton.updateWorldTransform(Physics.update); // Uses the bones' local SRT to compute their world SRT. diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SkeletonAssetManagerTest.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SkeletonAssetManagerTest.java index e5738d9f9..a18919e82 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SkeletonAssetManagerTest.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SkeletonAssetManagerTest.java @@ -100,9 +100,11 @@ public void render () { state.addAnimation(0, "run", true, 0); // Run after the jump. } - state.update(Gdx.graphics.getDeltaTime()); // Update the animation time. + float delta = Gdx.graphics.getDeltaTime(); + state.update(delta); // Update the animation time. state.apply(skeleton); // Poses skeleton using current animations. This sets the bones' local SRT. + skeleton.update(delta); // Advance the skeleton time. This is needed when the skeleton has physics. skeleton.updateWorldTransform(Physics.update); // Uses the bones' local SRT to compute their world SRT. // Configure the camera, SpriteBatch, and SkeletonRendererDebug. diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SkeletonAttachmentTest.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SkeletonAttachmentTest.java index b176bfa1f..06206bd99 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SkeletonAttachmentTest.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SkeletonAttachmentTest.java @@ -92,12 +92,15 @@ public void create () { } public void render () { - spineboyState.update(Gdx.graphics.getDeltaTime()); + float delta = Gdx.graphics.getDeltaTime(); + spineboyState.update(delta); spineboyState.apply(spineboy); + spineboy.update(delta); spineboy.updateWorldTransform(Physics.update); goblinState.update(Gdx.graphics.getDeltaTime()); goblinState.apply(goblin); + goblin.update(delta); goblin.updateWorldTransform(Physics.update, attachmentBone); ScreenUtils.clear(0, 0, 0, 0); diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/TestHarness.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/TestHarness.java index dc3fd1399..9e8d0e2c1 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/TestHarness.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/TestHarness.java @@ -43,9 +43,6 @@ /** Boilerplate for basic skeleton rendering, used for various testing. */ public class TestHarness extends ApplicationAdapter { -// static String JSON = "coin/coin-pro.json"; -// static String ATLAS = "coin/coin-pma.atlas"; - static String JSON = "raptor/raptor-pro.json"; static String ATLAS = "raptor/raptor-pma.atlas"; @@ -85,10 +82,11 @@ public void create () { } public void render () { - if (Gdx.input.justTouched()) { - state.update(0.25f); // Update the animation time. - } + float delta = 0; + if (Gdx.input.justTouched()) delta = 0.25f; + state.update(delta); // Update the animation time. state.apply(skeleton); // Poses skeleton using current animations. This sets the bones' local SRT. + skeleton.update(delta); // Advance the skeleton time. This is needed when the skeleton has physics. skeleton.updateWorldTransform(Physics.update); // Uses the bones' local SRT to compute their world SRT. ScreenUtils.clear(0, 0, 0, 0); diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/TimelineApiTest.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/TimelineApiTest.java index 8d493779e..dc3f8be13 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/TimelineApiTest.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/TimelineApiTest.java @@ -128,6 +128,7 @@ public void render () { walkAnimation.apply(skeleton, time, time, true, events, 1, MixBlend.first, MixDirection.in); } + skeleton.update(delta); skeleton.updateWorldTransform(Physics.update); batch.begin(); diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java index 9557f415a..61e12d231 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java @@ -108,6 +108,9 @@ public void setToSetupPose () { mix = data.mix; } + public void translate () { + } + /** Applies the constraint to the constrained bones. */ public void update (Physics physics) { float mix = this.mix;