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

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -