mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Allow customizing file to load from CLI.
This commit is contained in:
parent
fa52abc780
commit
3ab08eadd2
@ -30,6 +30,7 @@ package com.esotericsoftware.spine;
|
|||||||
|
|
||||||
import com.badlogic.gdx.ApplicationAdapter;
|
import com.badlogic.gdx.ApplicationAdapter;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.InputAdapter;
|
||||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
|
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
|
||||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
|
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
|
||||||
import com.badlogic.gdx.graphics.GL10;
|
import com.badlogic.gdx.graphics.GL10;
|
||||||
@ -41,6 +42,7 @@ import com.badlogic.gdx.math.Vector2;
|
|||||||
import com.badlogic.gdx.math.Vector3;
|
import com.badlogic.gdx.math.Vector3;
|
||||||
|
|
||||||
public class NormalMapTest extends ApplicationAdapter {
|
public class NormalMapTest extends ApplicationAdapter {
|
||||||
|
String skeletonPath, animationName;
|
||||||
SpriteBatch batch;
|
SpriteBatch batch;
|
||||||
float time;
|
float time;
|
||||||
SkeletonRenderer renderer;
|
SkeletonRenderer renderer;
|
||||||
@ -62,33 +64,52 @@ public class NormalMapTest extends ApplicationAdapter {
|
|||||||
boolean useNormals = true;
|
boolean useNormals = true;
|
||||||
boolean flipY = false;
|
boolean flipY = false;
|
||||||
|
|
||||||
|
public NormalMapTest (String skeletonPath, String animationName) {
|
||||||
|
this.skeletonPath = skeletonPath;
|
||||||
|
this.animationName = animationName;
|
||||||
|
}
|
||||||
|
|
||||||
public void create () {
|
public void create () {
|
||||||
program = createShader();
|
program = createShader();
|
||||||
batch = new SpriteBatch();
|
batch = new SpriteBatch();
|
||||||
batch.setShader(program);
|
batch.setShader(program);
|
||||||
renderer = new SkeletonRenderer();
|
renderer = new SkeletonRenderer();
|
||||||
|
|
||||||
TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("spineboy/spineboy-diffuse.atlas"));
|
TextureAtlas atlas = new TextureAtlas(Gdx.files.internal(skeletonPath + "-diffuse.atlas"));
|
||||||
atlasTexture = atlas.getRegions().first().getTexture();
|
atlasTexture = atlas.getRegions().first().getTexture();
|
||||||
normalMapTexture = new Texture(Gdx.files.internal("spineboy/spineboy-normal.png"));
|
normalMapTexture = new Texture(Gdx.files.internal(skeletonPath + "-normal.png"));
|
||||||
|
|
||||||
SkeletonJson json = new SkeletonJson(atlas);
|
SkeletonJson json = new SkeletonJson(atlas);
|
||||||
// json.setScale(2);
|
// json.setScale(2);
|
||||||
skeletonData = json.readSkeletonData(Gdx.files.internal("spineboy/spineboy.json"));
|
skeletonData = json.readSkeletonData(Gdx.files.internal(skeletonPath + ".json"));
|
||||||
animation = skeletonData.findAnimation("walk");
|
if (animationName != null) animation = skeletonData.findAnimation(animationName);
|
||||||
|
if (animation == null) animation = skeletonData.getAnimations().first();
|
||||||
|
|
||||||
skeleton = new Skeleton(skeletonData);
|
skeleton = new Skeleton(skeletonData);
|
||||||
skeleton.setToSetupPose();
|
skeleton.setToSetupPose();
|
||||||
skeleton = new Skeleton(skeleton);
|
skeleton = new Skeleton(skeleton);
|
||||||
skeleton.setX(200);
|
skeleton.setX(Gdx.graphics.getWidth() / 2);
|
||||||
skeleton.setY(100);
|
skeleton.setY(Gdx.graphics.getHeight() / 4);
|
||||||
skeleton.updateWorldTransform();
|
skeleton.updateWorldTransform();
|
||||||
|
|
||||||
|
Gdx.input.setInputProcessor(new InputAdapter() {
|
||||||
|
public boolean touchDown (int screenX, int screenY, int pointer, int button) {
|
||||||
|
touchDragged(screenX, screenY, pointer);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean touchDragged (int screenX, int screenY, int pointer) {
|
||||||
|
skeleton.setX(screenX);
|
||||||
|
skeleton.setY(Gdx.graphics.getHeight() - screenY);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render () {
|
public void render () {
|
||||||
float lastTime = time;
|
float lastTime = time;
|
||||||
time += Gdx.graphics.getDeltaTime();
|
time += Gdx.graphics.getDeltaTime();
|
||||||
animation.apply(skeleton, lastTime, time, true, null);
|
if (animation != null) animation.apply(skeleton, lastTime, time, true, null);
|
||||||
skeleton.updateWorldTransform();
|
skeleton.updateWorldTransform();
|
||||||
skeleton.update(Gdx.graphics.getDeltaTime());
|
skeleton.update(Gdx.graphics.getDeltaTime());
|
||||||
|
|
||||||
@ -208,8 +229,13 @@ public class NormalMapTest extends ApplicationAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main (String[] args) throws Exception {
|
public static void main (String[] args) throws Exception {
|
||||||
|
if (args.length == 0)
|
||||||
|
args = new String[] {"spineboy/spineboy", "walk"};
|
||||||
|
else if (args.length == 1) //
|
||||||
|
args = new String[] {args[0], null};
|
||||||
|
|
||||||
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
|
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
|
||||||
config.useGL20 = true;
|
config.useGL20 = true;
|
||||||
new LwjglApplication(new NormalMapTest(), config);
|
new LwjglApplication(new NormalMapTest(args[0], args[1]), config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user