PDA

View Full Version : Best way to detect image overlap?




macfanboy
Mar 22, 2009, 02:30 PM
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!
if (image1.center.x - image2.center.x = 75) {
if (image1.center.y - image2.center.y = 75) {
//Whatever I want
}
}



jpyc7
Mar 23, 2009, 07:35 AM
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).