The animationState can follow this translate, but the skeleton cannot follow the translate
This doesn't make sense. AnimationState
doesn't have a position.
In general, you probably don't want to use a Stage for your entire game. It makes sense for your UI, but I would draw the game world without scene2d.
I don't understand the problem you are having. A SkeletonActor
can be placed in a group and will translate with the parent group. I've added ActorTest
:
EsotericSoftware/spine-runtimesblob/4.2/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/ActorTest.java
Here I've modified it to show a parent group that is translated, rotated, and scaled, and I've used ShapeRenderer to make the positions of the group, label, and SkeletonActor
:
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.esotericsoftware.spine.Skeleton.Physics;
import com.esotericsoftware.spine.utils.SkeletonActor;
import com.esotericsoftware.spine.utils.TwoColorPolygonBatch;
public class ActorTest extends ApplicationAdapter {
Stage stage;
TwoColorPolygonBatch batch;
ShapeRenderer shapes;
SkeletonRenderer renderer;
TextureAtlas atlas;
Skeleton skeleton;
AnimationState state;
SkeletonActor skeletonActor;
Group group;
Label label;
Vector2 position = new Vector2();
public void create () {
batch = new TwoColorPolygonBatch();
shapes = new ShapeRenderer();
stage = new Stage(new ScreenViewport(), batch);
Gdx.input.setInputProcessor(stage);
renderer = new SkeletonRenderer();
renderer.setPremultipliedAlpha(true);
atlas = new TextureAtlas(Gdx.files.internal("spineboy/spineboy-pma.atlas"));
SkeletonJson json = new SkeletonJson(atlas);
json.setScale(0.6f);
SkeletonData skeletonData = json.readSkeletonData(Gdx.files.internal("spineboy/spineboy-pro.json"));
skeleton = new Skeleton(skeletonData);
AnimationStateData stateData = new AnimationStateData(skeletonData);
stateData.setMix("run", "jump", 0.2f);
stateData.setMix("jump", "run", 0.2f);
state = new AnimationState(stateData);
state.setTimeScale(0.5f);
state.setAnimation(0, "run", true);
state.addAnimation(0, "jump", false, 2);
state.addAnimation(0, "run", true, 0);
skeletonActor = new SkeletonActor(renderer, skeleton, state);
LabelStyle style = new LabelStyle();
style.font = new BitmapFont();
label = new Label("test", style);
group = new Group();
group.addActor(skeletonActor);
group.addActor(label);
stage.addActor(group);
group.setScale(1.3f, 1);
group.setRotation(30);
group.setPosition(120, 20);
label.setPosition(30, 30);
skeletonActor.setPosition(150, 10);
}
public void render () {
float delta = Gdx.graphics.getDeltaTime();
state.update(delta);
state.apply(skeleton);
skeleton.update(delta);
skeleton.updateWorldTransform(Physics.update);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.draw();
shapes.begin(ShapeType.Line);
shapes.setColor(Color.RED);
group.localToStageCoordinates(position.set(0, 0));
shapes.x(position, 10);
shapes.setColor(Color.GREEN);
skeletonActor.localToStageCoordinates(position.set(0, 0));
shapes.x(position, 10);
shapes.setColor(Color.YELLOW);
label.localToStageCoordinates(position.set(0, 0));
shapes.x(position, 10);
shapes.end();
}
public void resize (int width, int height) {
stage.getViewport().update(width, height, true);
}
public void dispose () {
atlas.dispose();
}
public static void main (String[] args) throws Exception {
new Lwjgl3Application(new ActorTest());
}
}
Note if you don't use rotate or scale you should use group.setTransform(false);
. See:
https://libgdx.com/wiki/graphics/2d/scene2d/scene2d#group-transform