When a bounding box is put on the root bone it follows the character perfectly. When the bounding box is attached to any other bone, it acts as if the bone and/or animation is directly in the center of the spine editor. When I out my character there to try and fix the issue, it throws of my x and y coordinates.
I am posting pictures to try and clarify things, both are when the bounding box is attached to bone2 not the root bone. The picture where he is not centered causes the bounding box issues, and if I set the player x and y value to 0 he appears fully on screen at the bottom-left edge, which is what I want.
The picture where he is centered causes the x and y value to be directly in the center and cuts off part of the picture of the player, but this fixes the bounding box.
I finally solved the issue I believe the BoundingBoxAttachment class is missing code that applies any scale in the SkeletonJson class via SkeletonJson.setScale(); Specifically it is in the computeWorldVertices method. Here is the line in the computeWorldVertices Method I believe is the root of all evil!:
float x = skeleton.getX() + bone.getWorldX(), y = skeleton.getY() + bone.getWorldY(); // Does not take scale into account
Here is my adjusted code to get the bounding box in its appropriate place.
bb = (BoundingBoxAttachment) skeleton.getAttachment("bb", "bb") ; // called in constructor
polygon = new Polygon(bb.getVertices()); // called in constructor
// All of below is called in render method
Array<Slot> slots = skeleton.getSlots();
int slotCount = slots.size;
for (int i = 0; i < slotCount; i++) {
Slot slot = slots.get(i);
Attachment attachment = slot.getAttachment();
if (attachment instanceof BoundingBoxAttachment) {
float[] vertices = new float[bb.getVertices().length];
bb.computeWorldVertices(slot.getBone(), vertices); // bb is a BoundingBoxAttachment
polygon.setVertices(vertices); // polygon is a Polygon
float x1 = slot.getBone().getX() * scale, y1 = slot.getBone().getY() * scale; // Here I multiply by the same scale that I set my assets
polygon.setPosition(x1,y1);
}
}
Repositioning the x and y by multiplying by the scale fixed my issue 🙂
I hope this helps someone as it took me forever to figure out.
Also should I post this in bugs?