• Runtimes
  • [LIBGDX] Get all bounding boxes from Skeleton?

Is there any way to get all bounding boxes from a skeleton even though its still in setup mode? I basically need to cache the bounding boxes for a particular reason.

I know I can do this:

      Array slots = skeleton.slots;
for(int i = 0; i < slotCount; i++)
      {
         Slot slot = slots.get(i);
         Attachment attachment = slot.attachment;
         if(attachment instanceof BoundingBoxAttachment)
         {
            BoundingBoxAttachment boundingBox = (BoundingBoxAttachment) attachment;
            boundingBoxes.add(boundingBox);
         }
      }

but the problem with this is if there are bounding boxes that aren't "active" (keyed) when I'm running the code, it doesn't recognize them.

Related Discussions
...

All bounding boxes are attachments, which are stored in a skin. Simply fetch the skin(s) from the skeleton and iterate over the attachments in the skin(s).

2 个月 后

Thanks! skeleton.getSkin() returned null because we dont use skins but skeleton.getData().getDefaultSkin() worked.
🙂


I just want to clarify, attachments belong to skins, which belong to SkeletonData.

So if I'm sharing my skeletonData between my Skeleton instances, that means I'm sharing attachments too?