Irregular Shape Collision Detection in iOS

enter image description here

Hi guys,

I am working on a drag and drop feature for iPad. I have a .png image rectangle (see Image named obj2). When I drag the obj1 object only onto the black part of the rectangle, it should react.

if (CGRectIntersectsRect(obj1.frame, obj2.frame))
{
    NSLog(@" hit test done!! ");
}

Right now, this piece of code passes the test of hitting even a transparent area. How to prevent this?

Thanks in advance.

Regards, Ranjan

+5
source share
1 answer

For something as simple as your specific example (triangle and circle), the link David Ronquist gives is very useful. You should definitely look at it to see some of the tools available. But for the general case, clipping, drawing, and searching is the best option.

. CGRRect CGPath.

-. .

, CGContextClipToMask().

.

, (. , , ).

- , .


( ) , CGBitmapContext. , - > 128 .

+2

All Articles