0

I am wondering if there is an easier way to check if the mouse is in a rectangle. Currently I am using an if statement like so

if (mX > rectX && mX < rectX + 20 && mY > rectY && my < rectY + 10){
} // where mX is mouse X and mY is mouse Y and rectX is the rectangle x and rectY is the rectangle y and + 20 is the width and +10 is the height

This is very time consuming. I am wondering if there is a quicker way of doing this.

Thanks for your help.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by sirlink99
0

No, that's really about it. You have to check against all four bounds for containment.

If you're using Rectangle to store the rectangles, you can use its contains() method, but it does pretty much the same calcs you are doing there.

Edited by Ezzaral: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.