The code makes sense:
state = new AnimationState(stateData);
// set the animation to walk
state.setAnimation(0, "walk", true);
// pose skeleton with walk animation
state.apply(skeleton);
// update skeleton's world SRT, which will be for the walk animation pose
skeleton.updateWorldTransform();
// new bounds and update it with the skeleton's world SRT
bounds = new SkeletonBounds();
bounds.update(skeleton, true);
// new animation state with no animation
state = new AnimationState(stateData);
// does nothing, the animation state has no animation
state.apply(skeleton);
// update skeleton's world SRT, which will be for the setup pose
skeleton.updateWorldTransform();
// new bounds and update it with the skeleton's world SRT
bounds = new SkeletonBounds();
bounds.update(skeleton, true);
// set animation to walk, won't affect the skeleton until state.apply(skeleton) later
state.setAnimation(0, "walk", true);
Now, back to making your BB show up in the right place. 🙂
BoundingBoxAttachment bb = ...
float[] polygon = new float[bb.getVertices().length];
bb.computeWorldVertices(skeleton.getX(), skeleton.getY(), slot.getBone(), polygon);
PolygonShape shape = new PolygonShape();
shape.set(polygon);
This computes the world vertices for a BB and creates a shape. This is going to show up in the correct place for the current skeleton pose, which is probably the setup pose. However, it is probably not what you want. Let's say one of the BB world vertices is at 50,100. When you position the PolygonShape at 0,0 then the vertex is at 50,100. When you position the PolygonShape at 100,100 then the vertex is at 150,200. This makes it hard to position and rotate the shape to match the BB, which is relative to a bone.
BoundingBoxAttachment bb = ...
PolygonShape shape = new PolygonShape();
shape.set(bb.getVertices());
This creates a shape using the BB local vertices. I steered you away from this initial, my apologies. :$ Next you should use setTransform(boneWorldX, boneWorldY, boneWorldRotation). This will position the shape at the bone's world position. The shape's vertices that we specified when we create the shape are relative to this position, which is exactly what we want. setTransform also rotates the shape around the position, and since the position is the bone location, this is also exactly what we want.
Have you seen this? It creates bodies for region attachments, but the concept is the same.
https://github.com/EsotericSoftware/spi ... ample.java
I hope you get it working!