mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 17:56:04 +08:00
[skeletonviewer] Uses camera instead of reload + scale. Allows to debug runtime issues more easily
This commit is contained in:
parent
4415cc456b
commit
011aca7b25
@ -47,6 +47,7 @@ import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
|
|||||||
import com.badlogic.gdx.files.FileHandle;
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
import com.badlogic.gdx.graphics.Pixmap;
|
import com.badlogic.gdx.graphics.Pixmap;
|
||||||
import com.badlogic.gdx.graphics.Pixmap.Format;
|
import com.badlogic.gdx.graphics.Pixmap.Format;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
@ -88,13 +89,13 @@ public class SkeletonViewer extends ApplicationAdapter {
|
|||||||
|
|
||||||
UI ui;
|
UI ui;
|
||||||
|
|
||||||
|
OrthographicCamera camera;
|
||||||
TwoColorPolygonBatch batch;
|
TwoColorPolygonBatch batch;
|
||||||
SkeletonRenderer renderer;
|
SkeletonRenderer renderer;
|
||||||
SkeletonRendererDebug debugRenderer;
|
SkeletonRendererDebug debugRenderer;
|
||||||
SkeletonData skeletonData;
|
SkeletonData skeletonData;
|
||||||
Skeleton skeleton;
|
Skeleton skeleton;
|
||||||
AnimationState state;
|
AnimationState state;
|
||||||
int skeletonX, skeletonY;
|
|
||||||
FileHandle skeletonFile;
|
FileHandle skeletonFile;
|
||||||
long lastModified;
|
long lastModified;
|
||||||
float lastModifiedCheck, reloadTimer;
|
float lastModifiedCheck, reloadTimer;
|
||||||
@ -112,10 +113,11 @@ public class SkeletonViewer extends ApplicationAdapter {
|
|||||||
prefs = Gdx.app.getPreferences("spine-skeletonviewer");
|
prefs = Gdx.app.getPreferences("spine-skeletonviewer");
|
||||||
ui = new UI();
|
ui = new UI();
|
||||||
batch = new TwoColorPolygonBatch(3100);
|
batch = new TwoColorPolygonBatch(3100);
|
||||||
|
camera = new OrthographicCamera();
|
||||||
renderer = new SkeletonRenderer();
|
renderer = new SkeletonRenderer();
|
||||||
debugRenderer = new SkeletonRendererDebug();
|
debugRenderer = new SkeletonRendererDebug();
|
||||||
skeletonX = (int)(ui.window.getWidth() + (Gdx.graphics.getWidth() - ui.window.getWidth()) / 2);
|
camera.position.x = (int)(ui.window.getWidth() + (Gdx.graphics.getWidth() - ui.window.getWidth()) / 2);
|
||||||
skeletonY = Gdx.graphics.getHeight() / 4;
|
camera.position.y = Gdx.graphics.getHeight() / 4;
|
||||||
ui.loadPrefs();
|
ui.loadPrefs();
|
||||||
|
|
||||||
loadSkeleton(
|
loadSkeleton(
|
||||||
@ -161,11 +163,11 @@ public class SkeletonViewer extends ApplicationAdapter {
|
|||||||
String extension = skeletonFile.extension();
|
String extension = skeletonFile.extension();
|
||||||
if (extension.equalsIgnoreCase("json") || extension.equalsIgnoreCase("txt")) {
|
if (extension.equalsIgnoreCase("json") || extension.equalsIgnoreCase("txt")) {
|
||||||
SkeletonJson json = new SkeletonJson(atlas);
|
SkeletonJson json = new SkeletonJson(atlas);
|
||||||
json.setScale(ui.scaleSlider.getValue());
|
json.setScale(1);
|
||||||
skeletonData = json.readSkeletonData(skeletonFile);
|
skeletonData = json.readSkeletonData(skeletonFile);
|
||||||
} else {
|
} else {
|
||||||
SkeletonBinary binary = new SkeletonBinary(atlas);
|
SkeletonBinary binary = new SkeletonBinary(atlas);
|
||||||
binary.setScale(ui.scaleSlider.getValue());
|
binary.setScale(1);
|
||||||
skeletonData = binary.readSkeletonData(skeletonFile);
|
skeletonData = binary.readSkeletonData(skeletonFile);
|
||||||
if (skeletonData.getBones().size == 0) throw new Exception("No bones in skeleton data.");
|
if (skeletonData.getBones().size == 0) throw new Exception("No bones in skeleton data.");
|
||||||
}
|
}
|
||||||
@ -237,17 +239,21 @@ public class SkeletonViewer extends ApplicationAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void render () {
|
public void render () {
|
||||||
|
Gdx.gl.glClearColor(0.3f, 0.3f, 0.3f, 1);
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
float delta = Gdx.graphics.getDeltaTime();
|
float delta = Gdx.graphics.getDeltaTime();
|
||||||
|
camera.update();
|
||||||
|
batch.getProjectionMatrix().set(camera.combined);
|
||||||
|
debugRenderer.getShapeRenderer().setProjectionMatrix(camera.combined);
|
||||||
|
|
||||||
// Draw skeleton origin lines.
|
// Draw skeleton origin lines.
|
||||||
ShapeRenderer shapes = debugRenderer.getShapeRenderer();
|
ShapeRenderer shapes = debugRenderer.getShapeRenderer();
|
||||||
if (state != null) {
|
if (state != null) {
|
||||||
shapes.setColor(Color.DARK_GRAY);
|
shapes.setColor(Color.DARK_GRAY);
|
||||||
shapes.begin(ShapeType.Line);
|
shapes.begin(ShapeType.Line);
|
||||||
shapes.line(skeleton.x, -99999, skeleton.x, 99999);
|
shapes.line(0, -99999, 0, 99999);
|
||||||
shapes.line(-99999, skeleton.y, 99999, skeleton.y);
|
shapes.line(-99999, 0, 99999, 0);
|
||||||
shapes.end();
|
shapes.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +279,6 @@ public class SkeletonViewer extends ApplicationAdapter {
|
|||||||
renderer.setPremultipliedAlpha(ui.premultipliedCheckbox.isChecked());
|
renderer.setPremultipliedAlpha(ui.premultipliedCheckbox.isChecked());
|
||||||
|
|
||||||
skeleton.setFlip(ui.flipXCheckbox.isChecked(), ui.flipYCheckbox.isChecked());
|
skeleton.setFlip(ui.flipXCheckbox.isChecked(), ui.flipYCheckbox.isChecked());
|
||||||
skeleton.setPosition(skeletonX, skeletonY);
|
|
||||||
|
|
||||||
delta = Math.min(delta, 0.032f) * ui.speedSlider.getValue();
|
delta = Math.min(delta, 0.032f) * ui.speedSlider.getValue();
|
||||||
skeleton.update(delta);
|
skeleton.update(delta);
|
||||||
@ -318,6 +323,8 @@ public class SkeletonViewer extends ApplicationAdapter {
|
|||||||
if (state != null) {
|
if (state != null) {
|
||||||
TrackEntry entry = state.getCurrent(0);
|
TrackEntry entry = state.getCurrent(0);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
|
shapes.getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
|
shapes.updateMatrices();
|
||||||
shapes.begin(ShapeType.Line);
|
shapes.begin(ShapeType.Line);
|
||||||
|
|
||||||
float percent = entry.getAnimationTime() / entry.getAnimationEnd();
|
float percent = entry.getAnimationTime() / entry.getAnimationEnd();
|
||||||
@ -346,8 +353,10 @@ public class SkeletonViewer extends ApplicationAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void resize (int width, int height) {
|
public void resize (int width, int height) {
|
||||||
batch.getProjectionMatrix().setToOrtho2D(0, 0, width, height);
|
float x = camera.position.x;
|
||||||
debugRenderer.getShapeRenderer().setProjectionMatrix(batch.getProjectionMatrix());
|
float y = camera.position.y;
|
||||||
|
camera.setToOrtho(false);
|
||||||
|
camera.position.set(x, y, 0);
|
||||||
ui.stage.getViewport().update(width, height, true);
|
ui.stage.getViewport().update(width, height, true);
|
||||||
if (!ui.minimizeButton.isChecked()) ui.window.setHeight(height + 8);
|
if (!ui.minimizeButton.isChecked()) ui.window.setHeight(height + 8);
|
||||||
}
|
}
|
||||||
@ -585,7 +594,8 @@ public class SkeletonViewer extends ApplicationAdapter {
|
|||||||
scaleSlider.addListener(new ChangeListener() {
|
scaleSlider.addListener(new ChangeListener() {
|
||||||
public void changed (ChangeEvent event, Actor actor) {
|
public void changed (ChangeEvent event, Actor actor) {
|
||||||
scaleLabel.setText(Float.toString((int)(scaleSlider.getValue() * 100) / 100f));
|
scaleLabel.setText(Float.toString((int)(scaleSlider.getValue() * 100) / 100f));
|
||||||
if (!scaleSlider.isDragging()) loadSkeleton(skeletonFile);
|
camera.zoom = 1 / scaleSlider.getValue();
|
||||||
|
// if (!scaleSlider.isDragging()) loadSkeleton(skeletonFile);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -677,8 +687,8 @@ public class SkeletonViewer extends ApplicationAdapter {
|
|||||||
float deltaX = screenX - offsetX;
|
float deltaX = screenX - offsetX;
|
||||||
float deltaY = Gdx.graphics.getHeight() - screenY - offsetY;
|
float deltaY = Gdx.graphics.getHeight() - screenY - offsetY;
|
||||||
|
|
||||||
skeletonX += deltaX;
|
camera.position.x -= deltaX * camera.zoom;
|
||||||
skeletonY += deltaY;
|
camera.position.y -= deltaY * camera.zoom;
|
||||||
|
|
||||||
offsetX = screenX;
|
offsetX = screenX;
|
||||||
offsetY = Gdx.graphics.getHeight() - screenY;
|
offsetY = Gdx.graphics.getHeight() - screenY;
|
||||||
@ -767,8 +777,8 @@ public class SkeletonViewer extends ApplicationAdapter {
|
|||||||
prefs.putFloat("speed", speedSlider.getValue());
|
prefs.putFloat("speed", speedSlider.getValue());
|
||||||
prefs.putFloat("mix", mixSlider.getValue());
|
prefs.putFloat("mix", mixSlider.getValue());
|
||||||
prefs.putFloat("scale", scaleSlider.getValue());
|
prefs.putFloat("scale", scaleSlider.getValue());
|
||||||
prefs.putInteger("x", skeletonX);
|
prefs.putFloat("x", camera.position.x);
|
||||||
prefs.putInteger("y", skeletonY);
|
prefs.putFloat("y", camera.position.y);
|
||||||
TrackEntry current = state.getCurrent(0);
|
TrackEntry current = state.getCurrent(0);
|
||||||
if (current != null) {
|
if (current != null) {
|
||||||
String name = current.animation.name;
|
String name = current.animation.name;
|
||||||
@ -791,8 +801,9 @@ public class SkeletonViewer extends ApplicationAdapter {
|
|||||||
speedSlider.setValue(prefs.getFloat("speed", 0.3f));
|
speedSlider.setValue(prefs.getFloat("speed", 0.3f));
|
||||||
mixSlider.setValue(prefs.getFloat("mix", 0.3f));
|
mixSlider.setValue(prefs.getFloat("mix", 0.3f));
|
||||||
scaleSlider.setValue(prefs.getFloat("scale", 1));
|
scaleSlider.setValue(prefs.getFloat("scale", 1));
|
||||||
skeletonX = prefs.getInteger("x", 0);
|
camera.zoom = 1 / prefs.getFloat("scale", 1);
|
||||||
skeletonY = prefs.getInteger("y", 0);
|
camera.position.x = prefs.getFloat("x", 0);
|
||||||
|
camera.position.y = prefs.getFloat("y", 0);
|
||||||
animationList.setSelected(prefs.getString("animationName", null));
|
animationList.setSelected(prefs.getString("animationName", null));
|
||||||
skinList.setSelected(prefs.getString("skinName", null));
|
skinList.setSelected(prefs.getString("skinName", null));
|
||||||
prefsLoaded = true;
|
prefsLoaded = true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user