Hampton

I am having trouble trying to animate my own skeletons and animations in libgdx, and I think it may have to do with how I make my skeletons in Spine.

I was able to successfully animate the spine boy example in my libgdx application. And the same code also works for making the powerup example float across the screen using it's fun animation with the stars.

But when I instead use the exported binaries for my dog skeleton and walk animation, it just shows the dog animated at (0,0) and doesn't move across the screen at all (just animates in place). Also, the scaling methods don't seem to apply.

The way I am trying to move the character and scale it is by using skeleton.getRootBone() and then setX, setY, setScaleX, and setScaleY

Like I said, all this code works great when I export the sample spine projects, but for any of my own skeletons the character is only drawn at (0, 0) and animates fine but I cannot scale the image or move it across the screen. Could I have made a skeleton where the root bone isn't attached to the rest of them or something like that? Any help would be great, though I know you guys are busy. Congrats on the kickstarter so far!
Hampton
  • Сообщения: 3

Nate

Please post your code for moving and drawing the animations. Edit: probably you key your root bone, so when you apply animation to the skeleton it sets the root bone position, rotation, and/or scale.
Аватара пользователя
Nate

Nate
  • Сообщения: 9241

Hampton

Here is the code I was using to move the object left to right across the screen! (and then it repeats)
I think you may be right about me having a key on my root bone. I'll try removing it and exporting the animation again!

package com.hampton.spinegame;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.esotericsoftware.spine.Bone;
import com.esotericsoftware.spine.SkeletonBinary;
import com.esotericsoftware.spine.SkeletonData;

public class Drop implements ApplicationListener {

private OrthographicCamera camera;
private SpriteBatch batch;

private com.esotericsoftware.spine.Skeleton skeleton;
private com.esotericsoftware.spine.Animation anim;
private float rootBoneLeft;
private float spineTotalTime = 0.0f;

@Override
public void create() {
camera = new OrthographicCamera();
camera.setToOrtho(false, 800, 480);

batch = new SpriteBatch();

spineTotalTime = 0.0f;
rootBoneLeft = -500.0f;

SkeletonData skeletonData = null;

TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("data/spinemaki/spinepackmaki.atlas"));
SkeletonBinary skeletonBinary = new SkeletonBinary(atlas);

skeletonData = skeletonBinary.readSkeletonData(
Gdx.files.internal("data/spinemaki/skeleton.skel"));
anim = skeletonBinary.readAnimation(
Gdx.files.internal("data/spinemaki/skeleton-stretch.anim"), skeletonData);

skeleton = new com.esotericsoftware.spine.Skeleton(skeletonData);
skeleton.setToBindPose();

Bone rootBone = skeleton.getRootBone();
rootBone.setX(0);
rootBone.setY(0);
rootBone.setScaleX(0.2f);
rootBone.setScaleY(0.2f);

skeleton.updateWorldTransform();
}

@Override
public void dispose() {
batch.dispose();
}

@Override
public void render() {
Gdx.gl.glClearColor(0, 0, 0.2f, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

camera.update();

spineTotalTime += Gdx.graphics.getDeltaTime();
Bone rootBone = skeleton.getRootBone();
rootBoneLeft += 250 * Gdx.graphics.getDeltaTime();
if (rootBoneLeft > 1000) rootBoneLeft = -500.0f;
rootBone.setX(rootBoneLeft);
anim.apply(skeleton, spineTotalTime, true);
skeleton.updateWorldTransform();
skeleton.update(Gdx.graphics.getDeltaTime());

batch.setProjectionMatrix(camera.combined);
batch.begin();
skeleton.draw(batch); // Spine
batch.end();
}

}
Hampton
  • Сообщения: 3

Hampton

Yep, you were right Nate! Once I took the key frames off the root, and re-exported my animation it was all working great in my app! Thanks!
Hampton
  • Сообщения: 3


Вернуться в Editor