[libgdx] Added FboTest. Use ScreenUtils#clear.

This commit is contained in:
Nathan Sweet 2021-03-15 12:37:16 +01:00
parent b05422bf0d
commit 4ecca69cff
18 changed files with 194 additions and 83 deletions

View File

@ -30,6 +30,7 @@
package com.esotericsoftware.spine;
import com.badlogic.gdx.utils.Array;
import com.esotericsoftware.spine.Animation.AttachmentTimeline;
import com.esotericsoftware.spine.Animation.Timeline;
import com.esotericsoftware.spine.attachments.Attachment;

View File

@ -30,15 +30,16 @@
package com.esotericsoftware.spine;
import com.badlogic.gdx.files.FileHandle;
import com.esotericsoftware.spine.Animation.MixDirection;
import com.esotericsoftware.spine.Animation.MixBlend;
import com.esotericsoftware.spine.Animation.MixDirection;
import com.esotericsoftware.spine.attachments.AttachmentLoader;
import com.esotericsoftware.spine.attachments.BoundingBoxAttachment;
import com.esotericsoftware.spine.attachments.ClippingAttachment;
import com.esotericsoftware.spine.attachments.RegionAttachment;
import com.esotericsoftware.spine.attachments.MeshAttachment;
import com.esotericsoftware.spine.attachments.PathAttachment;
import com.esotericsoftware.spine.attachments.PointAttachment;
import com.esotericsoftware.spine.attachments.RegionAttachment;
public class BonePlotting {
static public void main (String[] args) throws Exception {

View File

@ -29,16 +29,10 @@
package com.esotericsoftware.spine;
import com.esotericsoftware.spine.Animation.MixDirection;
import com.esotericsoftware.spine.Animation.MixBlend;
import com.esotericsoftware.spine.attachments.AtlasAttachmentLoader;
import com.esotericsoftware.spine.attachments.RegionAttachment;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
@ -55,6 +49,12 @@ import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ScreenUtils;
import com.esotericsoftware.spine.Animation.MixBlend;
import com.esotericsoftware.spine.Animation.MixDirection;
import com.esotericsoftware.spine.attachments.AtlasAttachmentLoader;
import com.esotericsoftware.spine.attachments.RegionAttachment;
public class Box2DExample extends ApplicationAdapter {
SpriteBatch batch;
@ -140,7 +140,7 @@ public class Box2DExample extends ApplicationAdapter {
camera.update();
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
ScreenUtils.clear(0, 0, 0, 0);
batch.setProjectionMatrix(camera.projection);
batch.setTransformMatrix(camera.view);
batch.begin();

View File

@ -29,13 +29,14 @@
package com.esotericsoftware.spine;
import com.esotericsoftware.spine.Animation.EventTimeline;
import com.esotericsoftware.spine.Animation.MixDirection;
import com.esotericsoftware.spine.Animation.MixBlend;
import java.util.Arrays;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.StringBuilder;
import java.util.Arrays;
import com.esotericsoftware.spine.Animation.EventTimeline;
import com.esotericsoftware.spine.Animation.MixBlend;
import com.esotericsoftware.spine.Animation.MixDirection;
/** Unit tests for {@link EventTimeline}. */
public class EventTimelineTests {

View File

@ -0,0 +1,106 @@
package com.esotericsoftware.spine;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import com.badlogic.gdx.utils.ScreenUtils;
import com.esotericsoftware.spine.utils.TwoColorPolygonBatch;
public class FboTest extends ApplicationAdapter {
OrthographicCamera camera;
TwoColorPolygonBatch batch;
SkeletonRenderer renderer;
BitmapFont font;
TextureAtlas atlas;
Skeleton skeleton;
FrameBuffer fbo;
TextureRegion fboRegion;
boolean drawFbo = true;
public void create () {
camera = new OrthographicCamera();
batch = new TwoColorPolygonBatch();
renderer = new SkeletonRenderer();
renderer.setPremultipliedAlpha(true);
font = new BitmapFont();
// Load the atlas and skeleton.
atlas = new TextureAtlas(Gdx.files.internal("spineboy/spineboy-pma.atlas"));
SkeletonJson json = new SkeletonJson(atlas);
json.setScale(0.66f);
SkeletonData skeletonData = json.readSkeletonData(Gdx.files.internal("spineboy/spineboy-ess.json"));
// Create a skeleton instance, set the position of its root bone, and update its world transform.
skeleton = new Skeleton(skeletonData);
skeleton.setPosition(250, 20);
skeleton.updateWorldTransform();
// Create an FBO and a texture region with Y flipped.
fbo = new FrameBuffer(Pixmap.Format.RGBA8888, 512, 512, false);
fboRegion = new TextureRegion(fbo.getColorBufferTexture());
fboRegion.flip(false, true);
// Configure the camera and batch for rendering to the FBO's size.
camera.setToOrtho(false, fbo.getWidth(), fbo.getHeight());
camera.update();
batch.getProjectionMatrix().set(camera.combined);
// Render the skeleton to the FBO.
fbo.begin();
ScreenUtils.clear(0, 0, 0, 0);
batch.begin();
renderer.draw(batch, skeleton);
batch.end();
fbo.end();
// Configure the camera and batch for rendering to the screen's size.
camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.update();
batch.getProjectionMatrix().set(camera.combined);
}
public void render () {
ScreenUtils.clear(1, 1, 1, 1);
batch.begin();
if (drawFbo) {
// Render the FBO color buffer texture to screen.
batch.draw(fboRegion, 0, 0);
} else {
// Render the skeleton directly to the screen.
renderer.draw(batch, skeleton);
}
font.setColor(Color.BLACK);
font.draw(batch, drawFbo ? "Drawing FBO." : "Not drawing FBO.", 10, 10 + font.getCapHeight());
batch.end();
if (Gdx.input.justTouched() || Gdx.input.isKeyJustPressed(Input.Keys.SPACE)) {
drawFbo = !drawFbo;
Gdx.app.log("SpineFBOTest", "Using FBO: " + drawFbo);
}
}
public void resize (int width, int height) {
camera.setToOrtho(false, width, height);
camera.update();
batch.getProjectionMatrix().set(camera.combined);
}
static public void main (String[] args) throws Exception {
new LwjglApplication(new FboTest());
}
}

View File

@ -32,13 +32,13 @@ package com.esotericsoftware.spine;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.Animation.PlayMode;
import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite;
import com.badlogic.gdx.utils.ScreenUtils;
public class FrameByFrameTest extends ApplicationAdapter {
OrthographicCamera camera;
@ -80,7 +80,7 @@ public class FrameByFrameTest extends ApplicationAdapter {
y -= origin[1];
frame.setPosition(x, y);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
ScreenUtils.clear(0, 0, 0, 0);
camera.update();
batch.getProjectionMatrix().set(camera.combined);

View File

@ -32,18 +32,16 @@ package com.esotericsoftware.spine;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.ScreenUtils;
import com.esotericsoftware.spine.utils.TwoColorPolygonBatch;
/** Demonstrates how to let the target bone of an IK constraint
* follow the mouse or touch position, which in turn repositions
* part of the skeleton, in this case Spineboy's back arm including
* his gun.
*/
/** Demonstrates how to let the target bone of an IK constraint follow the mouse or touch position, which in turn repositions part
* of the skeleton, in this case Spineboy's back arm including his gun. */
public class IKTest extends ApplicationAdapter {
OrthographicCamera camera;
TwoColorPolygonBatch batch;
@ -52,7 +50,7 @@ public class IKTest extends ApplicationAdapter {
TextureAtlas atlas;
Skeleton skeleton;
AnimationState state;
Vector3 cameraCoords = new Vector3();
Vector2 boneCoords = new Vector2();
@ -66,21 +64,21 @@ public class IKTest extends ApplicationAdapter {
// Load the texture atlas and skeleton data
atlas = new TextureAtlas(Gdx.files.internal("spineboy/spineboy-pma.atlas"));
SkeletonBinary json = new SkeletonBinary(atlas);
json.setScale(0.6f);
json.setScale(0.6f);
SkeletonData skeletonData = json.readSkeletonData(Gdx.files.internal("spineboy/spineboy-pro.skel"));
// Create a skeleton from the skeleton data
skeleton = new Skeleton(skeletonData);
skeleton.setPosition(250, 20);
// Create an animation satte
AnimationStateData stateData = new AnimationStateData(skeletonData);
state = new AnimationState(stateData);
// Queue the "walk" animation on the first track.
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 they point at
// the "crosshair" bone. By setting this
@ -97,10 +95,10 @@ public class IKTest extends ApplicationAdapter {
// then calculate the world transforms of every bone.
// This is needed so we can call Bone#worldToLocal()
// later.
state.update(Gdx.graphics.getDeltaTime());
state.update(Gdx.graphics.getDeltaTime());
state.apply(skeleton);
skeleton.updateWorldTransform();
// Position the "crosshair" bone at the mouse
// location. We do this before calling
// skeleton.updateWorldTransform() below, so
@ -110,18 +108,18 @@ public class IKTest extends ApplicationAdapter {
// 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
// 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
camera.unproject(cameraCoords); // mouse space to camera space
Bone crosshair = skeleton.findBone("crosshair"); // Should be cached.
boneCoords.set(cameraCoords.x, cameraCoords.y);
crosshair.getParent().worldToLocal(boneCoords); // camera space to local bone space
crosshair.setPosition(boneCoords.x, boneCoords.y); // override the crosshair position
crosshair.setAppliedValid(false);
// Calculate final world transform with the
// crosshair bone set to the mouse cursor
// position.
@ -129,9 +127,9 @@ public class IKTest extends ApplicationAdapter {
// Clear the screen, update the camera and
// render the skeleton.
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
ScreenUtils.clear(0, 0, 0, 0);
camera.update();
batch.getProjectionMatrix().set(camera.combined);
batch.begin();
renderer.draw(batch, skeleton);

View File

@ -32,12 +32,13 @@ package com.esotericsoftware.spine;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.utils.Array;
import com.esotericsoftware.spine.Animation.MixDirection;
import com.badlogic.gdx.utils.ScreenUtils;
import com.esotericsoftware.spine.Animation.MixBlend;
import com.esotericsoftware.spine.Animation.MixDirection;
public class MixTest extends ApplicationAdapter {
SpriteBatch batch;
@ -95,7 +96,7 @@ public class MixTest extends ApplicationAdapter {
if (time > beforeJump + blendIn && time < blendOutStart) speed = 360;
skeleton.setX(skeleton.getX() + speed * delta);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
ScreenUtils.clear(0, 0, 0, 0);
// This shows how to manage state manually. See SimpleTest1 for a higher level API using AnimationState.
if (time > total) {

View File

@ -36,7 +36,6 @@ import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
@ -55,8 +54,10 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.Align;
import com.esotericsoftware.spine.Animation.MixDirection;
import com.badlogic.gdx.utils.ScreenUtils;
import com.esotericsoftware.spine.Animation.MixBlend;
import com.esotericsoftware.spine.Animation.MixDirection;
public class NormalMapTest extends ApplicationAdapter {
String skeletonPath, animationName;
@ -138,7 +139,7 @@ public class NormalMapTest extends ApplicationAdapter {
lightPosition.x = Gdx.input.getX();
lightPosition.y = (Gdx.graphics.getHeight() - 1 - Gdx.input.getY());
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
ScreenUtils.clear(0, 0, 0, 0);
ambientColor.x = ui.ambientColorR.getValue();
ambientColor.y = ui.ambientColorG.getValue();

View File

@ -32,10 +32,10 @@ package com.esotericsoftware.spine;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.utils.ScreenUtils;
public class SimpleTest1 extends ApplicationAdapter {
OrthographicCamera camera;
@ -82,7 +82,7 @@ public class SimpleTest1 extends ApplicationAdapter {
public void render () {
state.update(Gdx.graphics.getDeltaTime()); // Update the animation time.
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
ScreenUtils.clear(0, 0, 0, 0);
state.apply(skeleton); // Poses skeleton using current animations. This sets the bones' local SRT.
skeleton.updateWorldTransform(); // Uses the bones' local SRT to compute their world SRT.

View File

@ -29,20 +29,20 @@
package com.esotericsoftware.spine;
import com.esotericsoftware.spine.AnimationState.AnimationStateListener;
import com.esotericsoftware.spine.AnimationState.TrackEntry;
import com.esotericsoftware.spine.attachments.BoundingBoxAttachment;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.ScreenUtils;
import com.esotericsoftware.spine.AnimationState.AnimationStateListener;
import com.esotericsoftware.spine.AnimationState.TrackEntry;
import com.esotericsoftware.spine.attachments.BoundingBoxAttachment;
public class SimpleTest2 extends ApplicationAdapter {
OrthographicCamera camera;
@ -145,7 +145,7 @@ public class SimpleTest2 extends ApplicationAdapter {
public void render () {
state.update(Gdx.graphics.getDeltaTime()); // Update the animation time.
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
ScreenUtils.clear(0, 0, 0, 0);
if (state.apply(skeleton)) // Poses skeleton using current animations. This sets the bones' local SRT.
skeleton.updateWorldTransform(); // Uses the bones' local SRT to compute their world SRT.

View File

@ -32,10 +32,10 @@ package com.esotericsoftware.spine;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.utils.ScreenUtils;
public class SimpleTest3 extends ApplicationAdapter {
OrthographicCamera camera;
@ -80,7 +80,7 @@ public class SimpleTest3 extends ApplicationAdapter {
public void render () {
state.update(Gdx.graphics.getDeltaTime()); // Update the animation time.
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
ScreenUtils.clear(0, 0, 0, 0);
if (state.apply(skeleton)) // Poses skeleton using current animations. This sets the bones' local SRT.
skeleton.updateWorldTransform(); // Uses the bones' local SRT to compute their world SRT.

View File

@ -32,9 +32,9 @@ package com.esotericsoftware.spine;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.utils.ScreenUtils;
import com.esotericsoftware.spine.utils.TwoColorPolygonBatch;
@ -85,7 +85,7 @@ public class SimpleTest4 extends ApplicationAdapter {
public void render () {
state.update(Gdx.graphics.getDeltaTime()); // Update the animation time.
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
ScreenUtils.clear(0, 0, 0, 0);
state.apply(skeleton); // Poses skeleton using current animations. This sets the bones' local SRT.
skeleton.updateWorldTransform(); // Uses the bones' local SRT to compute their world SRT.

View File

@ -33,10 +33,10 @@ import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.utils.ScreenUtils;
import com.esotericsoftware.spine.utils.SkeletonDataLoader;
import com.esotericsoftware.spine.utils.SkeletonDataLoader.SkeletonDataParameter;
@ -71,7 +71,7 @@ public class SkeletonAssetManagerTest extends ApplicationAdapter {
}
public void render () {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
ScreenUtils.clear(0, 0, 0, 0);
if (skeleton == null) {
// Not loaded yet.

View File

@ -32,10 +32,11 @@ package com.esotericsoftware.spine;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.utils.ScreenUtils;
import com.esotericsoftware.spine.attachments.SkeletonAttachment;
public class SkeletonAttachmentTest extends ApplicationAdapter {
@ -97,7 +98,7 @@ public class SkeletonAttachmentTest extends ApplicationAdapter {
goblinState.apply(goblin);
goblin.updateWorldTransform(attachmentBone);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
ScreenUtils.clear(0, 0, 0, 0);
camera.update();
batch.getProjectionMatrix().set(camera.combined);

View File

@ -32,10 +32,10 @@ package com.esotericsoftware.spine;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.utils.ScreenUtils;
public class SkinBonesMixAndMatchTest extends ApplicationAdapter {
OrthographicCamera camera;
@ -90,7 +90,7 @@ public class SkinBonesMixAndMatchTest extends ApplicationAdapter {
public void render () {
state.update(Gdx.graphics.getDeltaTime()); // Update the animation time.
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
ScreenUtils.clear(0, 0, 0, 0);
state.apply(skeleton); // Poses skeleton using current animations. This sets the bones' local SRT.
skeleton.updateWorldTransform(); // Uses the bones' local SRT to compute their world SRT.

View File

@ -32,42 +32,43 @@ package com.esotericsoftware.spine;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.utils.ScreenUtils;
import com.esotericsoftware.spine.vertexeffects.SwirlEffect;
public class TestHarness extends ApplicationAdapter {
// static String JSON = "coin/coin-pro.json";
// static String ATLAS = "coin/coin-pma.atlas";
// 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";
OrthographicCamera camera;
PolygonSpriteBatch batch;
SkeletonRenderer renderer;
ShapeRenderer shapes;
TextureAtlas atlas;
Skeleton skeleton;
AnimationState state;
SwirlEffect swirl;
float swirlTime;
public void create () {
public void create () {
camera = new OrthographicCamera();
camera.setToOrtho(true);
batch = new PolygonSpriteBatch();
renderer = new SkeletonRenderer();
renderer.setPremultipliedAlpha(true);
renderer.setPremultipliedAlpha(true);
shapes = new ShapeRenderer();
swirl = new SwirlEffect(400);
swirl.setCenterY(-200);
renderer.setVertexEffect(swirl);
@ -76,13 +77,13 @@ public class TestHarness extends ApplicationAdapter {
SkeletonJson json = new SkeletonJson(atlas);
json.setScale(0.5f);
SkeletonData skeletonData = json.readSkeletonData(Gdx.files.internal(JSON));
skeleton = new Skeleton(skeletonData);
skeleton = new Skeleton(skeletonData);
skeleton.setPosition(320, 590);
skeleton.setScaleY(-1);
AnimationStateData stateData = new AnimationStateData(skeletonData);
state = new AnimationState(stateData);
AnimationStateData stateData = new AnimationStateData(skeletonData);
state = new AnimationState(stateData);
// state.setAnimation(0, "rotate", false);
state.update(0);
state.apply(skeleton);
@ -91,30 +92,29 @@ public class TestHarness extends ApplicationAdapter {
public void render () {
if (Gdx.input.justTouched()) {
state.update(0.25f); // Update the animation time.
state.update(0.25f); // Update the animation time.
}
state.apply(skeleton); // Poses skeleton using current animations. This sets the bones' local SRT.
skeleton.updateWorldTransform(); // Uses the bones' local SRT to compute their world SRT.
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
ScreenUtils.clear(0, 0, 0, 0);
swirlTime += Gdx.graphics.getDeltaTime();
float percent = swirlTime % 2;
if (percent > 1) percent = 1 - (percent - 1);
swirl.setAngle(Interpolation.pow2.apply(-60, 60, percent));
// Configure the camera, SpriteBatch, and SkeletonRendererDebug.
camera.update();
batch.getProjectionMatrix().set(camera.combined);
batch.getProjectionMatrix().set(camera.combined);
batch.begin();
renderer.draw(batch, skeleton); // Draw the skeleton images.
batch.end();
batch.end();
}
public void resize (int width, int height) {
camera.setToOrtho(true); // Update camera with new size.
camera.setToOrtho(true); // Update camera with new size.
}
public void dispose () {

View File

@ -33,11 +33,12 @@ import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.utils.ScreenUtils;
import com.esotericsoftware.spine.vertexeffects.SwirlEffect;
public class VertexEffectTest extends ApplicationAdapter {
@ -74,7 +75,7 @@ public class VertexEffectTest extends ApplicationAdapter {
// Queue animations on tracks 0 and 1.
state.setAnimation(0, "walk", true);
state.addAnimation(1, "gun-grab", false, 2); // Keys in higher tracks override the pose from lower tracks.
swirl = new SwirlEffect(400);
swirl.setCenter(0, 200);
renderer.setVertexEffect(swirl);
@ -92,7 +93,7 @@ public class VertexEffectTest extends ApplicationAdapter {
if (percent > 1) percent = 1 - (percent - 1);
swirl.setAngle(Interpolation.pow2.apply(-60, 60, percent));
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
ScreenUtils.clear(0, 0, 0, 0);
state.apply(skeleton); // Poses skeleton using current animations. This sets the bones' local SRT.
skeleton.updateWorldTransform(); // Uses the bones' local SRT to compute their world SRT.