How do I check for collisions between two UIImageViews using a method not in the ViewController class?
For example:
This method bellow is in the rock class but glass UIImageView is in the ViewController.
if(CGRectIntersectsRect(rock.frame, glass.frame))
{
//do stuff
}
It complains that glass isn’t declared. So how do I refer to the glass UIImageView in the ViewController if I’m calling the collision method from the rock class???
I’m not sure exactly how to get classes to ‘talk’ to each other in general – it’s a concept I don’t quite understand so a small example would be much appreciated! Or if somebody could point out a good place to learn this concept that would help a lot.
Thanks.
The solution was simple in the end. I just didn’t understand the concept of getter and setter methods.
So the answer was to make a method in the ‘glass’ object like so:
And then call it from the ‘rock’ object:
Which returns true when the two rectangles intersect.
I’m surprised I didn’t get any replies for this as it was simple solution in the end. Perhaps I didn’t explain myself properly? Hope I explained the solution correctly. If not then please feel free to correct me. We wouldn’t want the blind leading the blind now would we!!!