Question: How do I check if two rectangles are overlapping?
Answer: If you have two Rectangles and all you want to do is check if they are overlapping eachother or not, you can easily make use of the Intersects method.
In code, let's say you have two Rectangles called rect1 and rect2. To check if they overlap, you could have an if-statement like this:
if (rect1.Intersects(rect2))
{
//Code
}
Note: It doesn't matter which Rectangle you call Intersects fom.
In the code above, we check if any part of rect1 intersects any part of rect2. If rect1 and rect do overlap, Intersects will return true and then you can continue from there.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment