Search code examples
c++xcodecocos2d-xbounding-boxspritebatch

Touch detection for SpriteBatchNode


I am curious if anyone knows how to detect when a SpriteBatchNode has been touched since it's BoundingBox is always null. This is how I detect touch for single sprites.

Node *parentNode = event->getCurrentTarget();
Vector<Node *> children = parentNode->getChildren();
Point touchPosition = parentNode->convertTouchToNodeSpace(touch);

for (auto iter = children.rbegin(); iter != children.rend(); ++iter) {
    childObject = *iter;

if (childObject->getBoundingBox().containsPoint(touchPosition)){

   //do something
}

But in most cases I want my sprites to be animated hence using SpriteBatchNode. Any ideas? Can I get the BoundingBox of the grandchildren since they are a series of sprites?


Solution

  • Well I figured it out by getting the BoundingBox of the grandchild, which is a sprite. I was then able to do whatever I wanted to the spritebatchnode.