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;
|
||||
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() + "," //
|
||||
|
||||
@ -151,6 +151,7 @@ public class Box2DExample extends ApplicationAdapter {
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@ -79,39 +79,29 @@ public class IKTest extends ApplicationAdapter {
|
||||
// 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 class IKTest extends ApplicationAdapter {
|
||||
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();
|
||||
|
||||
|
||||
@ -89,11 +89,13 @@ public class MixAndMatchTest extends ApplicationAdapter {
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@ -135,8 +135,10 @@ public class NormalMapTest extends ApplicationAdapter {
|
||||
|
||||
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();
|
||||
|
||||
@ -105,6 +105,7 @@ public class PngExportTest extends ApplicationAdapter {
|
||||
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.
|
||||
|
||||
@ -82,11 +82,13 @@ public class SimpleTest1 extends ApplicationAdapter {
|
||||
}
|
||||
|
||||
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.
|
||||
|
||||
@ -81,10 +81,12 @@ public class SimpleTest3 extends ApplicationAdapter {
|
||||
}
|
||||
|
||||
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.
|
||||
|
||||
|
||||
@ -100,9 +100,11 @@ public class SkeletonAssetManagerTest extends ApplicationAdapter {
|
||||
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.
|
||||
|
||||
@ -92,12 +92,15 @@ public class SkeletonAttachmentTest extends ApplicationAdapter {
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@ -43,9 +43,6 @@ import com.esotericsoftware.spine.Skeleton.Physics;
|
||||
|
||||
/** 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 class TestHarness extends ApplicationAdapter {
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@ -128,6 +128,7 @@ public class TimelineApiTest extends ApplicationAdapter {
|
||||
walkAnimation.apply(skeleton, time, time, true, events, 1, MixBlend.first, MixDirection.in);
|
||||
}
|
||||
|
||||
skeleton.update(delta);
|
||||
skeleton.updateWorldTransform(Physics.update);
|
||||
|
||||
batch.begin();
|
||||
|
||||
@ -108,6 +108,9 @@ public class PhysicsConstraint implements Updatable {
|
||||
mix = data.mix;
|
||||
}
|
||||
|
||||
public void translate () {
|
||||
}
|
||||
|
||||
/** Applies the constraint to the constrained bones. */
|
||||
public void update (Physics physics) {
|
||||
float mix = this.mix;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user