Hi,
I have multiple skeletons on the screen:
for(int i=0; i<4; i++){
auto shark = SkeletonAnimation::createWithData(_sharkSkeletonData, false);
shark->setPosition(sharkData[i].pos);
shark->setScale(sharkData[i].scale);
shark->setAnimation(0, "Swim", true);
sharks.pushBack(shark);
}
These skeletons all have a bounding box and are moved using
setPosition
in coco2d-x. When I try to do hit testing on the bounding boxes, their position does not seem to be taken into account:
// The location of the touch
auto location = touch->getLocation();
for(int i=0; i<sharks.size(); i++){
// We then need to update the bounds to get their current position
spSkeletonBounds* bounds = spSkeletonBounds_create();
spSkeletonBounds_update(bounds, sharks.at(i)->getSkeleton(), true);
// Then we have to do is check if the click was within the bounds!
spBoundingBoxAttachment* attachment = spSkeletonBounds_containsPoint(bounds, location.x, location.y);
if(attachment){
//if we have hit our bounding box called SharkBox
if (strcmp(attachment->super.super.name, "SharkBox") == 0) {
sharks.at(i)->setAnimation(0, "SwimFast", false);
}
}
}
Even though the skeleton animations positions are being set - their bounding boxes are still positioned at 0,0.
Can someone let me know what I am doing wrong/how to get around this?
Thanks!