Hello!
I am making game demo using libgdx & spine runtime.
I successfully imported my skeleton from spine. I can load skeleton, change attachments, play animations.
When he is alone. It's ok.
Now i want to spawn many libgdx Actors, who have own positions, attachment indexes for weapon/armor slots and animations states (but share one Skeleton as a template). It mostly works. But i have trouble setting animation for each of Actor.
I copy some "update" code:
public void applyAnimationState() {
animationState.apply(getSkeleton()); // Poses skeleton using current animations. This sets the bones' local SRT.
animationState.setData(getComponent().animationStateData); // Holds the animation state for a skeleton (current animation, time, etc).
//animationState.setAnimation(0, STATES[heroAnimState], true); // <
---
interrupts animation, so i always see frame 0
}
public void applyAll() {
applyAnimationState();
applyFlip();
applyPosition();
applyAttachments();
getSkeleton().updateWorldTransform(); // Uses the bones' local SRT to compute their world SRT.
}
public void draw(Camera camera) {
applyAll();
batch.getProjectionMatrix().set(camera.combined);
//debugRenderer.getShapeRenderer().setProjectionMatrix(camera.combined);
batch.begin();
//setup skeleton template to view locals
renderer.draw(batch, getSkeleton()); // Draw the skeleton images.
batch.end();
}
My problem is in:
animationState.setAnimation (setting it will reset animation to start)
not setting it i have all Actors playing one animation.
I share one animationState for all Actors. Is it wrong?
So, if i call
animationState.setAnimation in each Actor.draw
for (SkeletonActorComponent actor: actors ) { actor.draw(camera); }
they all have frame 0
how can i apply frame/timeline for each?
Okay, looking through utils sources https://github.com/EsotericSoftware/spine-runtimes/tree/4.0/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/utils
i see in SkeletonActoorPool class, that each Skeleton have animationState pair. So will do i. I will share Template's atlas & data to prevent loading duplicates. Thx 🙂