我在 Java 中使用 Graphics2D 缩放对象时遇到问题。在我的paintComponent 中,我创建了两个graphics2D 对象以便于管理。然后我尝试缩放它们。问题是输出按 x4 缩放(缩放命令相互影响)。否则,一切都会呈现应有的效果。
这个怎么解决最好。
有问题的代码:
@Override
public void paintComponent(Graphics g) {
playerGraphics = (Graphics2D) g;
backgroundGraphics = (Graphics2D) g;
playerGraphics.scale(2.0, 2.0);
backgroundGraphics.scale(2.0, 2.0);
backgroundGraphics.drawImage(background.getBackground(), 0, 0, null);
for(int i = 0; i < noPlayers; i++) {
playerGraphics.drawImage(players.get(i).getCurrentSprite(), players.get(i).getXPos(), players.get(i).getYPos(), null);
}
}
Run Code Online (Sandbox Code Playgroud)