Hi.
Ah. The intersect function deals with some properties of objects, not others. So although there is considerable control over the nature of the pixels that comprise an object, that alpha channel stuff, there is no support at all for, say, the left of an object intersecting with another.
TWO EXERCISES. # 1
You will likely have to roll your own here. For example, if you want to know if the left of button 1 has "intersected" with any part of button 2, you might test to see if the top, center or bottom of that side of the button is within the rect of the other. But the "is within" operator requires a point, not a single value. So although this will give you a valid answer:
answer "100,100" is within the rect of btn 2
this will not:
answer "100" is within the rect of btn 2
So what to do? Well, write a simple function that extracts a bunch of points from any side. If you ask if anyLeftPoint(button 1) is within the rect of button 2, then you are home free. Can you do this? Can you do it in a single robust function that handles all four sides? I hope we are talking about rectangles here, whatever object or graphic is involved. All this becomes much more complex if not.
# 2
What if you detect the intersect, and then determine the relative positions of the two objects? So if you compare the various lefts, rights, tops and bottoms of both, you should be able to determine which side touched the target. (pseudoCode):
Code: Select all
if the left of button 1 is just less than the right of button 2 then youKnowWhichSideHitWhich
This sounds simpler than #1. You should do both.
Write back...
Craig