• Runtimes
  • Spine - libGDX - Multiple instances of same skeleton

I recently purchased Spine and created an animated character for a libGDX game. I set the animated character on the screen using setPosition to define the location.

beachballSkeleton = new Skeleton(spriteData);
beachballSkeleton.setPosition(900,200); // Setup sprite position on the canvas
beachballstateData = new AnimationStateData(spriteData);
beachballState = new AnimationState(beachballstateData);
beachballState.setAnimation(2, "beachballroll", true);

Now, I want to duplicate and place multiple instances of this same character (beachball) on the screen simultaneously; however, since setPosition is a function of Skeleton, it renders all the instances of the character in the same spot.

For some reason, I can’t seem to find an example of how to implement this simple function without recreating the Skeleton for each instance.

Could you point me to an example or a tutorial that explains the best method to solve my problem?

Thank you

Related Discussions
...
  • Modifié
jeh a écrit

setPosition is a function of Skeleton, it renders all the instances of the character in the same spot

The Skeleton instance is one instance of the character. If you need multiple instances of the character that need to animate separately then you would create multiple skeletons. Note you'd still have a single SkeletonData that each skeleton instance would use.

If you just need to render the skeleton with the exact same pose (ie not animating separately), you can set the position, render it, set the position elsewhere, and render it again.

I am not very good coding, but since you only want test multiple balls at diferent positions, just create a method with a loop using your code, just remplace the positions numbers with a random number generator.

so at render: batch.begin;
mymethod(batch)
batch.end;

later yout method:
mymethod(Batch batch){
for......{
creation logic....

batch.draw(item created in each loop iteraction)
}

}

Thanks Nate & quarzoq for your replies.

I now have multiple beachballs on the screen simultaneously. I also made several skeletons from the same SleletonData for another character since I need to change the timescale and the animation. It works great.