3

我正在画布上绘制一系列矩形。矩形应该以一定角度移动。出于某种原因,当它们移动时,它们会按比例放大:

xPos += xSpeed;
yPos += ySpeed;
updateBounds(xPos, yPos, width, height);

我的 UpdateBounds 方法:

public void updateBounds(double x, double y, double w, double h) {
    bounds.setRect(x, y, w, h);
}

Bounds 是一个 Rectangle2D 对象。还有我的绘图方法:

g.fillRect((int) bounds.getX(), (int) bounds.getY(),
                (int) bounds.getMaxX(), (int) bounds.getMaxY());

为什么我会出现这种行为?

4

1 回答 1

2

Graphics.fillRect()接受宽度和高度参数,而不是要绘制的矩形的最大 x 和 y 位置。

第三个和第四个参数fillRect应该是 Rectangle2D 的getWidth()getHeight()

作为参考,getMaxX() 将给你的链接

于 2015-07-26T04:42:34.387 回答