As Absinthe said, poundev23 code really only checks BB around a rotated sprite. I wrote the correct code (but in Cocos2dx - C ++) - I hope that it helps someone:
CCSize size = this->getContentSize(); CCRect rect = CCRect(0, 0, size.width, size.height); CCPoint pt = touch->locationInView(); pt = CCDirector::sharedDirector()->convertToGL(pt); pt = CCPointApplyAffineTransform(pt, this->worldToNodeTransform()); bool b = CCRect::CCRectContainsPoint(rect, pt);
have a good code!
Edit: Good solution! I converted it to Objective C.
- (BOOL) containsTouchLocation:(UITouch *) touch { CGSize size = self.contentSize; CGRect rect = CGRectMake(0, 0, size.width, size.height); CGPoint touchLocation = [touch locationInView: [touch view]]; touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation]; touchLocation = CGPointApplyAffineTransform(touchLocation, self.worldToNodeTransform); bool containsPoint = CGRectContainsPoint(rect, touchLocation); return containsPoint; }
source share