I've done a quick google search and found this:
http://silentmatt.com/computers/playgro ... ection.php
According to this page, it is easier if your rectangles are specified as four points (without heights and widths): If we call them A.x1, A.y1, A.x2, A.y2, B.x1, B.y1, B.x2, B.y2, we end up with the following condition:
Code: Select all
(A.x1 < B.x2 and A.x2 > B.x1 and A.y1 < B.y2 and A.y2 > B.y1)
If you must have x1, y1, w1, h1 and x2, y2, w2, h2 then it gets a bit uglier, but still intelligible:
Code: Select all
(x1 < x2+w2 and x1+w1 > x2 and y1 < y2+h2 and y1+h1 > y2)
You might want to change some of the < and > by <= and >= if you want to test if two rectangles are "touching" without "overlapping".
More information on this stackoverflow post:
http://stackoverflow.com/questions/3063 ... each-other