- Изменено
[libGDX] Get skeleton width/height?
Hello!
I am currently replacing UIs static elements with animated elements. For exemple I am replacing Scene2D.Image with a custom Scene2D.Widget using skeleton and animated State.
But I can't figure out how to get skeletal width/height like I did with image. I though I could do that with SkeletalBounds, but the result are strange, or at least I do not understand it.
In the constructor of my custom widget id do the following;
mAnimationState = new AnimationState(new AnimationStateData(Assets.ninjaHeadsSkeletonData));
mSkeleton = new Skeleton(Assets.ninjaHeadsSkeletonData);
mSkeleton.setToSetupPose();
mAnimationState.setAnimation(0, ANIMATION_IDLE, false);
mAnimationState.apply(mSkeleton);
mSkeleton.updateWorldTransform();
mSkeletonBounds = new SkeletonBounds();
mSkeletonBounds.update(mSkeleton, true); //I tried with false as well
Then I try to retrieve width and height with the following code:
public float getWidth() {
return mSkeletonBounds.getWidth();
}
public float getHeight() {
return mSkeletonBounds.getHeight();
}
Can someone point out what I am doing wrong?
hi. im new to spine but from my understanding skeletalBounds is exported with the spine data only if bounding boxes are manually defined. I could be wrong but thats just from looking at boundingbox attachment and the json/bin loading code.
Try manually placing them in the Spine editor>select bone>new attachment>bounding box
Wow I did not understand that at all. I'll try ASAP, thank you very much.
Yep, SkeletonBounds is for bounding boxes. You can get the AABB of a skeleton by finding the min and max x and y for each corner of the region and mesh attachments, but keep in mind the bounds of a skeleton depend on how that skeleton is posed. If you are just looking for the bounds for the setup pose, this could be ok. You could also note the size of your skeleton in Spine and use that at runtime.
Hello,
I added a bounding box to my Animation, it's working now :rock: .
Thanks a lot!