Best way to detect image overlap?

Discussion in 'iOS Programming' started by macfanboy, Mar 22, 2009.

  1. macfanboy macrumors 6502a

    Joined:
    Jun 5, 2007
    #1
    I was trying to detect when two imageviews (equally sized circles) overlap, and i was going to call a method every 0.01 seconds and using the below code. I thought there may be a better way to do this but i couldnt find out how. Any advice is greatly appreciated!
    Code:
    if (image1.center.x - image2.center.x = 75) {
         if (image1.center.y - image2.center.y = 75) {
              //Whatever I want
         }
    } 
     
  2. jpyc7 macrumors 6502

    Joined:
    Mar 8, 2009
    Location:
    Denver, CO
    #2
    two comments

    1. Instead of checking every X seconds, you should just check whenever a circle moves. Or maybe you meant the circle movement rate was X seconds. Anyway, you get the idea that you don't need to check for overlap any faster than the circle movement rate.

    2. Your logic works, but you need a 'less than' sign in front of the 75 (which I assume is the radius of the circle).
     

Share This Page