• Editor
  • Set bounds of Spine Actor (Libgdx)

I have some libgdx Actors walking around being all Spine-ish and awesome with Skeleton, SkeletonData, rootBone and Animation. I am, however, having trouble finding some way to set the bounds of the Actor from the Skeleton to make the Actor clickable. Is it possible to do this? I could of course hard code some approximate bounds, but with scaling and stuff it may be hard to implement. I guess setting the bounds from a skeleton might be hard as well since the actual size of the Actor may change over time (in my current case it is not).

What is the best way to achieve this?

Related Discussions
...

When Spine has bounding boxes, you could use those for hit detection. Could you just choose an appropriate size for your actor? You could go through the slots, get any attachments, if they are region attachments you can get their vertices, then you can do point-polygon hit detection to see if the point hit any of the images.

I think I'll just set a hard coded bounding box for now, maybe use the slots to see how it works. My game will not be ready before Spine hit detection anyways, so I guess such workaround is more than enough for the current testing and development. Thanks!

Another way you can do it for now is. Create an image with the right bounds size that is 100% transparent and attach it to a bone parented to the root. Then use that single attachment as your bounds. This way you can animate the scale etc. of it.

Yeah, that is a better temporary workaround. Thanks 🙂

That's a good idea Shiu, I was going to ask this question myself (just need a general bounding box depending on the scale, for the first pose in the animation).

I might still just scale a box in Spine to see how big it should be, then use that times the scale set in the runtime to figure out where the bounding box is.

I can't take credit for it though, it was another user who needed to export PNG's at a specific size who thought of it. I merely extended on it a bit to also be used for bounds 🙂 Glad you find it useful.

3 mois plus tard
Nate a écrit

When Spine has bounding boxes, you could use those for hit detection.

Hey, just wondering if you have any update on the bounding boxes in Spine. As far as I can tell from the forums you can do something like skeleton.boundingBox in the Cocos2d backend. Will something like this be available for libgdx soon? Or maybe I have missed out on where the functionality is?

In libgdx you can compute bounds like spine-cocos2d, but this isn't the bounding boxes feature. That will allow you to attach bounding boxes to bones and check when they are hit. I will start on editor features soon!

Nate a écrit

In libgdx you can compute bounds like spine-cocos2d, but this isn't the bounding boxes feature. That will allow you to attach bounding boxes to bones and check when they are hit. I will start on editor features soon!

Hi Nate, can you explain how to compute the bounds for a skeleton in libgdx (at least for the bind pose, for example), I need to give a width/height to the character so I can order them by "altitude" (just the y position), so right now I'm just doing it the not-so-good-way (assigning values until I think they have the right size 😛). I don't want to attach a transparent image as the box, because it would not be a permanent solution.

Thanks in advance.

un mois plus tard
Nate a écrit

When Spine has bounding boxes, you could use those for hit detection. Could you just choose an appropriate size for your actor? You could go through the slots, get any attachments, if they are region attachments you can get their vertices, then you can do point-polygon hit detection to see if the point hit any of the images.

virtual cocos2d::CCRect boundingBox (); when this function will be called?

if I Inherit CCSkeleton class,and overload the "virtual cocos2d::CCRect boundingBox ();" What
situation this function will be called?

boundingBox is a cocos2d method, see the cocos2d documentation for when it might be called. I think typically it is only called by your application code.