When sprite is not rotated it’s simple, just create a rect a check if point is inside, but what about rotated? I’ve found some solution for old cocos2d, but I can’t port it to cocos2d-x.
I dont understand Your problem. If the rotation was made on the object itself, so You have something like this:
auto rotate = RotateBy::create(2.0f, 360);
YourSprite->runAction(rotate);
then You should be able to do something like this:
void YourGameClass::onTouchesBegan(const std::vector<Touch *> &touches, Event *event)
{
for (auto touch: touches)
{
Point location = this->convertTouchToNodeSpace(touch);
if (YourSprite->getBoundingBox().containsPoint(location))
{
// do what You want here
}
}
}
That’s not what I wanted. Anyway I solved it:
bool Item::isTouched(Touch* touch, Event* event){
Point locationInNode = getParent()->convertToNodeSpace(touch->getLocation());
Size size = sprite->getContentSize();
Rect rect = Rect(getPositionX() - size.width / 2 , getPositionY() - size.height / 2, size.width, size.height);
float rad = CC_DEGREES_TO_RADIANS(getRotation());
Vec2 p = locationInNode.rotateByAngle(getPosition(), rad);
return rect.containsPoint(p);
}