how to detect collision of image views in a puzzle game
i am doing a simple jigsaw puzzle game.
for that i crop a single image into 9 pieces and display it on 9 image views.
Now i need to detect collision when one image view is comes over the half of another image view frame,
and replace image or image view each other.
how can i done can开发者_Go百科 any one please help me.
You can use the CGRectIntersectsRect() function, it takes to CGRect's and returns YES if the rects intersect, otherwise NO.
Here is a short example:
if(CGRectIntersectsRect(image1.frame, image2.frame))
{
UIImage *temp = [[image1 image] retain];
[image1 setImage:image2.image];
[image2 setIamge:[temp autorelease]];
}
(It works of course easier if you have an array to iterate through)
精彩评论