mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
[libgdx] Added skeleton.update(delta) to examples, even when physics is not used.
This commit is contained in:
parent
d03f535ed8
commit
55550c3490
@ -84,6 +84,7 @@ public class BonePlotting {
|
|||||||
float time = 0;
|
float time = 0;
|
||||||
while (time < animation.getDuration()) {
|
while (time < animation.getDuration()) {
|
||||||
animation.apply(skeleton, time, time, false, null, 1, MixBlend.first, MixDirection.in);
|
animation.apply(skeleton, time, time, false, null, 1, MixBlend.first, MixDirection.in);
|
||||||
|
skeleton.update(fps);
|
||||||
skeleton.updateWorldTransform(Physics.update);
|
skeleton.updateWorldTransform(Physics.update);
|
||||||
|
|
||||||
System.out.println(animation.getName() + "," //
|
System.out.println(animation.getName() + "," //
|
||||||
|
|||||||
@ -151,6 +151,7 @@ public class Box2DExample extends ApplicationAdapter {
|
|||||||
|
|
||||||
animation.apply(skeleton, time, time, true, events, 1, MixBlend.first, MixDirection.in);
|
animation.apply(skeleton, time, time, true, events, 1, MixBlend.first, MixDirection.in);
|
||||||
skeleton.x += 8 * delta;
|
skeleton.x += 8 * delta;
|
||||||
|
skeleton.update(delta);
|
||||||
skeleton.updateWorldTransform(Physics.update);
|
skeleton.updateWorldTransform(Physics.update);
|
||||||
skeletonRenderer.draw(batch, skeleton);
|
skeletonRenderer.draw(batch, skeleton);
|
||||||
|
|
||||||
|
|||||||
@ -79,39 +79,29 @@ public class IKTest extends ApplicationAdapter {
|
|||||||
// Queue the "walk" animation on the first track.
|
// Queue the "walk" animation on the first track.
|
||||||
state.setAnimation(0, "walk", true);
|
state.setAnimation(0, "walk", true);
|
||||||
|
|
||||||
// Queue the "aim" animation on a higher track.
|
// Queue the "aim" animation on a higher track. It consists of a single frame that positions the back arm and gun such that
|
||||||
// It consists of a single frame that positions
|
// they point at the "crosshair" bone. By setting this animation on a higher track, it overrides any changes to the back arm
|
||||||
// the back arm and gun such that they point at
|
// and gun made by the walk animation, allowing us to mix the two. The mouse position following is performed in the render()
|
||||||
// the "crosshair" bone. By setting this
|
// method below.
|
||||||
// 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);
|
state.setAnimation(1, "aim", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render () {
|
public void render () {
|
||||||
// Update and apply the animations to the skeleton,
|
// Update and apply the animations to the skeleton, then calculate the world transforms of every bone. This is needed so we
|
||||||
// then calculate the world transforms of every bone.
|
// can call Bone#worldToLocal() later.
|
||||||
// This is needed so we can call Bone#worldToLocal()
|
float delta = Gdx.graphics.getDeltaTime();
|
||||||
// later.
|
state.update(delta);
|
||||||
state.update(Gdx.graphics.getDeltaTime());
|
|
||||||
state.apply(skeleton);
|
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
|
// Position the "crosshair" bone at the mouse location. We do this before calling skeleton.updateWorldTransform() below, so
|
||||||
// location. We do this before calling
|
// our change is incorporated before the IK constraint is applied.
|
||||||
// skeleton.updateWorldTransform() below, so
|
|
||||||
// our change is incorporated before the IK
|
|
||||||
// constraint is applied.
|
|
||||||
//
|
//
|
||||||
// When setting the crosshair bone position
|
// When setting the crosshair bone position to the mouse position, we need to translate from "mouse space" to "camera space"
|
||||||
// to the mouse position, we need to translate
|
// and then to "local bone space". Note that the local bone space is calculated using the bone's parent worldToLocal()
|
||||||
// from "mouse space" to "camera space"
|
// function!
|
||||||
// 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);
|
cameraCoords.set(Gdx.input.getX(), Gdx.input.getY(), 0);
|
||||||
camera.unproject(cameraCoords); // mouse space to camera space
|
camera.unproject(cameraCoords); // mouse space to camera space
|
||||||
|
|
||||||
@ -120,13 +110,10 @@ public class IKTest extends ApplicationAdapter {
|
|||||||
crosshair.getParent().worldToLocal(boneCoords); // camera space to local bone space
|
crosshair.getParent().worldToLocal(boneCoords); // camera space to local bone space
|
||||||
crosshair.setPosition(boneCoords.x, boneCoords.y); // override the crosshair position
|
crosshair.setPosition(boneCoords.x, boneCoords.y); // override the crosshair position
|
||||||
|
|
||||||
// Calculate final world transform with the
|
// Calculate final world transform with the crosshair bone set to the mouse cursor position. Update physics this time.
|
||||||
// crosshair bone set to the mouse cursor
|
|
||||||
// position.
|
|
||||||
skeleton.updateWorldTransform(Physics.update);
|
skeleton.updateWorldTransform(Physics.update);
|
||||||
|
|
||||||
// Clear the screen, update the camera and
|
// Clear the screen, update the camera and render the skeleton.
|
||||||
// render the skeleton.
|
|
||||||
ScreenUtils.clear(0, 0, 0, 0);
|
ScreenUtils.clear(0, 0, 0, 0);
|
||||||
camera.update();
|
camera.update();
|
||||||
|
|
||||||
|
|||||||
@ -89,11 +89,13 @@ public class MixAndMatchTest extends ApplicationAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void render () {
|
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);
|
ScreenUtils.clear(0, 0, 0, 0);
|
||||||
|
|
||||||
state.apply(skeleton); // Poses skeleton using current animations. This sets the bones' local SRT.
|
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.
|
skeleton.updateWorldTransform(Physics.update); // Uses the bones' local SRT to compute their world SRT.
|
||||||
|
|
||||||
// Configure the camera, and PolygonSpriteBatch
|
// Configure the camera, and PolygonSpriteBatch
|
||||||
|
|||||||
@ -135,8 +135,10 @@ public class NormalMapTest extends ApplicationAdapter {
|
|||||||
|
|
||||||
public void render () {
|
public void render () {
|
||||||
float lastTime = time;
|
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);
|
if (animation != null) animation.apply(skeleton, lastTime, time, true, null, 1, MixBlend.first, MixDirection.in);
|
||||||
|
skeleton.update(delta);
|
||||||
skeleton.updateWorldTransform(Physics.update);
|
skeleton.updateWorldTransform(Physics.update);
|
||||||
|
|
||||||
lightPosition.x = Gdx.input.getX();
|
lightPosition.x = Gdx.input.getX();
|
||||||
|
|||||||
@ -105,6 +105,7 @@ public class PngExportTest extends ApplicationAdapter {
|
|||||||
int frame = 1;
|
int frame = 1;
|
||||||
while (time < animation.getDuration()) {
|
while (time < animation.getDuration()) {
|
||||||
animation.apply(skeleton, time, time, false, null, 1, MixBlend.first, MixDirection.in);
|
animation.apply(skeleton, time, time, false, null, 1, MixBlend.first, MixDirection.in);
|
||||||
|
skeleton.update(fps);
|
||||||
skeleton.updateWorldTransform(Physics.update);
|
skeleton.updateWorldTransform(Physics.update);
|
||||||
|
|
||||||
// Render the skeleton to the FBO.
|
// Render the skeleton to the FBO.
|
||||||
|
|||||||
@ -82,11 +82,13 @@ public class SimpleTest1 extends ApplicationAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void render () {
|
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);
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
state.apply(skeleton); // Poses skeleton using current animations. This sets the bones' local SRT.
|
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.
|
skeleton.updateWorldTransform(Physics.update); // Uses the bones' local SRT to compute their world SRT.
|
||||||
|
|
||||||
// Configure the camera, SpriteBatch, and SkeletonRendererDebug.
|
// Configure the camera, SpriteBatch, and SkeletonRendererDebug.
|
||||||
|
|||||||
@ -81,10 +81,12 @@ public class SimpleTest3 extends ApplicationAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void render () {
|
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);
|
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.
|
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.
|
skeleton.updateWorldTransform(Physics.update); // Uses the bones' local SRT to compute their world SRT.
|
||||||
|
|
||||||
|
|||||||
@ -100,9 +100,11 @@ public class SkeletonAssetManagerTest extends ApplicationAdapter {
|
|||||||
state.addAnimation(0, "run", true, 0); // Run after the jump.
|
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.
|
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.
|
skeleton.updateWorldTransform(Physics.update); // Uses the bones' local SRT to compute their world SRT.
|
||||||
|
|
||||||
// Configure the camera, SpriteBatch, and SkeletonRendererDebug.
|
// Configure the camera, SpriteBatch, and SkeletonRendererDebug.
|
||||||
|
|||||||
@ -92,12 +92,15 @@ public class SkeletonAttachmentTest extends ApplicationAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void render () {
|
public void render () {
|
||||||
spineboyState.update(Gdx.graphics.getDeltaTime());
|
float delta = Gdx.graphics.getDeltaTime();
|
||||||
|
spineboyState.update(delta);
|
||||||
spineboyState.apply(spineboy);
|
spineboyState.apply(spineboy);
|
||||||
|
spineboy.update(delta);
|
||||||
spineboy.updateWorldTransform(Physics.update);
|
spineboy.updateWorldTransform(Physics.update);
|
||||||
|
|
||||||
goblinState.update(Gdx.graphics.getDeltaTime());
|
goblinState.update(Gdx.graphics.getDeltaTime());
|
||||||
goblinState.apply(goblin);
|
goblinState.apply(goblin);
|
||||||
|
goblin.update(delta);
|
||||||
goblin.updateWorldTransform(Physics.update, attachmentBone);
|
goblin.updateWorldTransform(Physics.update, attachmentBone);
|
||||||
|
|
||||||
ScreenUtils.clear(0, 0, 0, 0);
|
ScreenUtils.clear(0, 0, 0, 0);
|
||||||
|
|||||||
@ -43,9 +43,6 @@ import com.esotericsoftware.spine.Skeleton.Physics;
|
|||||||
|
|
||||||
/** Boilerplate for basic skeleton rendering, used for various testing. */
|
/** Boilerplate for basic skeleton rendering, used for various testing. */
|
||||||
public class TestHarness extends ApplicationAdapter {
|
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 JSON = "raptor/raptor-pro.json";
|
||||||
static String ATLAS = "raptor/raptor-pma.atlas";
|
static String ATLAS = "raptor/raptor-pma.atlas";
|
||||||
|
|
||||||
@ -85,10 +82,11 @@ public class TestHarness extends ApplicationAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void render () {
|
public void render () {
|
||||||
if (Gdx.input.justTouched()) {
|
float delta = 0;
|
||||||
state.update(0.25f); // Update the animation time.
|
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.
|
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.
|
skeleton.updateWorldTransform(Physics.update); // Uses the bones' local SRT to compute their world SRT.
|
||||||
|
|
||||||
ScreenUtils.clear(0, 0, 0, 0);
|
ScreenUtils.clear(0, 0, 0, 0);
|
||||||
|
|||||||
@ -128,6 +128,7 @@ public class TimelineApiTest extends ApplicationAdapter {
|
|||||||
walkAnimation.apply(skeleton, time, time, true, events, 1, MixBlend.first, MixDirection.in);
|
walkAnimation.apply(skeleton, time, time, true, events, 1, MixBlend.first, MixDirection.in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
skeleton.update(delta);
|
||||||
skeleton.updateWorldTransform(Physics.update);
|
skeleton.updateWorldTransform(Physics.update);
|
||||||
|
|
||||||
batch.begin();
|
batch.begin();
|
||||||
|
|||||||
@ -108,6 +108,9 @@ public class PhysicsConstraint implements Updatable {
|
|||||||
mix = data.mix;
|
mix = data.mix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void translate () {
|
||||||
|
}
|
||||||
|
|
||||||
/** Applies the constraint to the constrained bones. */
|
/** Applies the constraint to the constrained bones. */
|
||||||
public void update (Physics physics) {
|
public void update (Physics physics) {
|
||||||
float mix = this.mix;
|
float mix = this.mix;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user