鼠标有两个点,即 x 和 y 位置。
int mouseX = gc.getInput().getMouseX();
int mouseY = gc.getInput().getMouseY();
我们有一个矩形
Rectangle rec = new Rectangle( 100, 100, 200, 200 );
所以我们可以检查
if ( mouseX >= rec.getMinX() && mouseX <= rec.getMaxX ) // check if X is within range
&& ( mouseY >= rec.getMinY() && mouseY <= rec.getMaxY) // check if y is within range
或者现在我们知道我们的 X 值必须大于矩形的低值但小于其高值,并且 Y 的值相同,让我们检查 contains 函数
contains(float xp, float yp, float xr, float yr, float widthr, float heightr)
xp - The x coordinate of the point to check
yp - The y coordinate of the point to check
xr - The x coordinate of the rectangle
yr - The y coordinate of the rectangle
widthr - The width of the rectangle
heightr - The height of the rectangle
所以我想说
contains( mouseX, mouseY, rec.getMinX(), rect.getMinY(), rec.getWidth(), rec.getHeight() )
也许这里出了什么问题?