Gr3ymatter

Hey guys,

Im trying to use an animation i made with spine. I get the image on the screen but the root is positioned at 0,0 and I try to set the root bone position based on my world coordinates by using root.setX() method. However that doesnt work as everytime skel.updateWorldTransform() is called in the render method the positioning gets reset to 0,0 again.

Here is the code i am using. Areas of interest would be my constructor and the jaxRender(float delta) method.
public class WorldRenderer {

World world;

public static final float CAMERA_WIDTH = 10f;
public static final float CAMERA_HEIGHT = 7f;

OrthographicCamera camera;
Texture jaxTexture;
Texture blockTexture;

SpriteBatch spriteBatch;
Animation anim;
Skeleton skel;
Bone root;


int width;
int height;

private boolean debug = false;

ShapeRenderer debugRenderer = new ShapeRenderer();

public WorldRenderer(World world, boolean debug){
this.world = world;
this.camera = new OrthographicCamera(CAMERA_WIDTH, CAMERA_HEIGHT);
this.camera.position.set(CAMERA_WIDTH/2, CAMERA_HEIGHT/2, 0);
this.camera.update();
this.debug = debug;
spriteBatch = new SpriteBatch();

TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("data/Me.pack"));
SkeletonBinary sb = new SkeletonBinary(atlas);
SkeletonData sd = sb.readSkeletonData(Gdx.files.internal("data/skeleton.skel"));

anim = sb.readAnimation(Gdx.files.internal("data/skeleton-Walking.anim"), sd);

skel = new com.esotericsoftware.spine.Skeleton(sd);
skel.setToBindPose();

root = skel.getRootBone();
root.setScaleX(.0025f);
root.setScaleY(.0025f);
root.setX(1);
root.setY(1);

Gdx.app.log("Root", "" + root.getWorldScaleX()+ " "+ root.getWorldX());
skel.updateWorldTransform();
}

public void debugRender(){

debugRenderer.setProjectionMatrix(camera.combined);
debugRenderer.begin(ShapeType.Line);
for(Block blocks : world.getBlocks()){
Rectangle rect = blocks.getBounds();
debugRenderer.setColor(1, 0, 0, 1);
debugRenderer.rect(blocks.getPosition().x, blocks.getPosition().y, rect.width, rect.height);
}

debugRenderer.end();

/* Rectangle rect = world.getJax().getBounds();
debugRenderer.setColor(0, 1, 1, 1);
debugRenderer.rect(world.getJax().getPosition().x, world.getJax().getPosition().y, rect.width, rect.height);
debugRenderer.end();*/

}

public void render(float delta){
debugRender();
jaxRender(delta);
Gdx.app.log("Root", "" + root.getWorldScaleX()+ " "+ root.getWorldX());

}

float totalTime = 0f;

public void jaxRender(float delta){
totalTime += delta;
anim.apply(skel, totalTime, true);
skel.update(delta);
spriteBatch.begin();
skel.draw(spriteBatch);
spriteBatch.end();
skel.updateWorldTransform();
}

}
Any help would be greatly appreciated. Spine is an awesome software, it just sucks that i cant use it with Libgdx at the moment. I also tried setting the projection matrix of the spriteBatch class to the camera, however that doesnt change anything. If i remove the skel.updateWorldTransform() from my jaxRender() method i can position the image properly but it no longer animates since its not updating???

Edit:

Here are some pics to illustrate the point. If i have set my Orthographic cameras projection matrix to be (10 , 7) then commenting out the skel.updateWorldTransform() method positions the guy properly since sprite batches projection matrix is also set to the cameras. Shown here...

Thanks in advance.
Nemaš dopuštenje za pregledavanje privit(a)ka dodan(og)ih postu.
Gr3ymatter
  • Postovi: 3

Gr3ymatter

Bump
Gr3ymatter
  • Postovi: 3

Søren

No need to bump your thread :)
Do you have any keys on the root bone ? If so, you should delete them.
Avatar
Søren

Shiu
  • Postovi: 2448

Nate

Yup, a translation key on the root bone will cause applying the animation to change the position of the root bone. You can set the root bone position after you apply the animation, before you call updateWorldTransform, or you can remove the translation keys on the root bone.
Avatar
Nate

Nate
  • Postovi: 11875

Gr3ymatter

That worked!

Thank you guys for your awesomeness!
Gr3ymatter
  • Postovi: 3


Natrag na Editor