0
使用Graphcis2D和AffineTransform在固定位置旋转图像时出现问题。使用AffineTransform旋转图像时未将图像绘制到固定位置
想法是根据身体的旋转旋转图像。
当图像的旋转角度与身体的旋转角度相匹配时,旋转正确发生。但是,随着旋转的发生,图像不会被绘制到与绘制身体相同的位置。该方法画的画的代码如下:
public void paintPicture(Graphics g, Body body) {
Graphics2D g2 = (Graphics2D) g;
Vector2f[] vertices = ((Box) body.getShape()).getPoints(body.getPosition(), body.getRotation());
Vector2f topLeftCorner = vertices[0];
AffineTransform oldTransform = g2.getTransform();
AffineTransform at = new AffineTransform();
at.rotate(body.getRotation());
g2.setTransform(at);
g2.drawImage(this.img, (int) topLeftCorner.x, (int) topLeftCorner.y, null);
g2.setTransform(oldTransform);
}
任何想法可能会导致图像的运动,而不是根据坐标(topLeftCorner.x,topLeftCorner.y)绘制了吗?