Hey Nate and everyone else!
I need a bit of help with pooling resources mainly skeletons and animations. in a past thread Nate said:
To take up less CPU, you could of course use fewer bones. However, with so many soldiers, maybe you can have them share both an animation and skeleton. Eg, for simplicity imagine you have a single skeleton for walking and each frame you apply the walk animation to it. Any soldier walking is given this skeleton. When you go to draw, you just need to draw the walking skeleton at the soldier's location. This is waaaay more efficient because you only apply an animation to a single skeleton and you only compute the world SRT of a single skeleton.
Of course it looks bad because all soldiers are animated the same. So, now you use a pool of skeletons which you randomly assign when a soldier begins walking. You could use maybe 5-20, whatever looks good. Maybe even do it dynamically, eg if you have 100 soldiers in the same state, use 10 animations. This would reduce your CPU by 90%. I have a feeling no one is going to notice that 400 soliders don't have perfectly unique animation.
I get how pooling works with sprites I think, but I cant wrap my head around pooling these spine animations. I created a helper class to deal with these spine animations called AnimatedSprites therefore I haven't really studied the underlying code because all I have to do to create a spine animation is one line of code away.
My questions are these: what do I pool? and what do I create multiple times? for example imagine I want to create a dog that runs, what makes up the image of the dog (the spriteAtlas?), if so, say I want 100 dogs on the screen, do I create a 100 spriteAtlas's? and only create one skeletonJson, SkeletonData, animationState for all 100 dogs? or 100 animationState's?
Another question is if i changed the rotation or position of these dogs wouldn't all of them change at the same time? since they are all using the same skeletondata or whatever will be pooled?
In short what needs to be pooled?
1)skeletondata
2)animationstate
3)skeletonJson
4) spriteAtlas
5) or spriteSkeleton
or am I completely confused of what pooling is? can anybody explain to me in as few words possible what it means?
this is the code I use:
public void createsprite(String atlas, String json, float x, float y){
spriteAtlas = new TextureAtlas(Gdx.files.internal(atlas));
skeletonJson = new SkeletonJson(spriteAtlas);
skeletonData = skeletonJson.readSkeletonData(Gdx.files.internal(json));
spriteSkeleton = new Skeleton(skeletonData);
spriteSkeleton.setX(x); //can be overridden immediately
spriteSkeleton.setY(y); //can be overridden immediately
spriteSkeleton.updateWorldTransform();
stateData = new AnimationStateData(skeletonData);
setAnimationState(new AnimationState(stateData));
// mix animations so they look natural
//stateData.setMix("walk", "jump", .2f);
//stateData.setMix("jump", "walk", .4f);
}
//update method
public void update(float dt){
spriteSkeleton.update(dt);
getAnimationState().update(dt);
getAnimationState().apply(spriteSkeleton); // Poses skeleton using current animations. This sets the bone's local SRT.
spriteSkeleton.updateWorldTransform();
}