开发者

how to detect collision of image views in a puzzle game

开发者 https://www.devze.com 2023-02-06 07:09 出处:网络
i am doing a simplejigsaw puzzle game. for that i crop a single image into 9 pieces and display it on 9 image views.

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消