Hi all,
I have a problem that I did not succeed in resoving for several days… Let me explain my case.
I use Spine SkeletonAnimation (which are very cool !), but when you instanciate such an animation with a json + atlas exported file, you obtain a Node with an anchor point set to (0, 0), but a bounding box with a negative origin (in x and in y) : the animation render goes "around the anchor point… OK, for the moment, that’s not a problem… But, in my game, I need to present my animation with a title, so to do that, I just created a parent node with the required size (title + animation size), and then I add as child the title, and the SkeletonAnimation… It works well. But, my problem is that in my use case I need to call the utils::getCascadeBoundingBox (to put this new node some UI Widget)… And I think this function is not working in this case, probably due due to this “negative values bounding box origin” : when I call the utils::getCascadeBoundingBox on my new created node, I obtain a bounding box which is not the one I can see on the screen ! Its origin coordinates are negative while I have been careful that it does not happen by offseting the animation child node to compensate the bounding box negative origin.
I copy here the lines which are problematic
I took a look to the implementation of getCascadeBoundingBox and I think there is a problem in it : Let’s see that code : the last line of the function permits to take into account the current node bouding box
// merge content size
if (contentSize.width > 0 && contentSize.height > 0)
{
const Rect box = RectApplyAffineTransform(Rect(0, 0, contentSize.width, contentSize.height), node->getNodeToWorldAffineTransform());
if (!merge)
{
cbb = box;
}
else
{
cbb.merge(box);
}
}
I think it can not work since when you have graphical data outside the area (0,0, width, height), and that is the case when the bouding box has a negative origin, it returns the bounding box corresponding to the area (0,0, width, height) ! So I created my own getCascadeBoundingBox with this correction
// merge content size
if (contentSize.width > 0 && contentSize.height > 0)
{
Vec2 localOrigin = node->getBoundingBox().origin - node->getPosition() + node->getAnchorPointInPoints();
const Rect box = RectApplyAffineTransform(Rect(localOrigin.x, localOrigin.y, contentSize.width, contentSize.height), node->getNodeToWorldAffineTransform());
if (!merge)
{
cbb = box;
}
else
{
cbb.merge(box);
}
}
The result is better (near to the correct bounding box) but the resulting bounding box is still not the correct one !
Does anybody have an idea ? I hope somebody understand my problem (since it is difficult to explain with my frenchy english ).
Thanks for your help !
Olivier.