You can use CGMutablePathRef to make non-rectangular sprite collision detection.
//checking
CGPoint loc =[mySprite convertToNodeSpace:touchPoint];
if([mySprite isPointInsideMap:loc])
{
//touched inside..
}
//Add this method in your MySprite class derived from CCSprite.
-(bool)isPointInsideMap:(CGPoint)inPoint
{
if (CGPathContainsPoint(mCollisionPath, NULL, inPoint, NO) )
{
return true;
}
return false;
}
////Create Path
CGMutablePathRef mCollisionPath = CGPathCreateMutable();
CGPathMoveToPoint(mCollisionPath, NULL, 0, 0 );
CGPathAddLineToPoint(mCollisionPath, NULL, 11, 82 );
CGPathAddLineToPoint(mCollisionPath, NULL, 42, 152 );
CGPathAddLineToPoint(mCollisionPath, NULL, 86, 202 );
CGPathAddLineToPoint(mCollisionPath, NULL, 169, 13 );
CGPathCloseSubpath(mCollisionPath);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…