iphone - "do something" when an image is near another -
i have 2 image (image1 , image2). image 2 moving around screen. want "do something" when image 2 near (20pixels) of image1. how can ?
create frame adds 20 pixel each side of image1's frame:
cgrect image1frame = image1.frame; cgrect collisionframe = cgrectmake(image1frame.origin.x-20.0, image1frame.origin.y-20.0, image1frame.size.width+20.0, image1frame.size.height+20.0);
then check if frame of image2 collides collisionframe:
cgrectintersectsrect(image2.frame, collisionframe);
Comments
Post a Comment