一次绘制数百个圆形动画的程序不会流畅地绘制它们。建议使用仿射变换来复制形状。这段代码被重构为使用 graphics2D,可以工作,但不会导致任何性能提升,因为它仍在填充数百个椭圆。如何正确使用仿射变换来填充形状一次然后复制/移动它?
public void paintComponent(Graphics g) {
super.paintComponent(g);
setBackground(Color.WHITE);
for (int i = 0; i < gameLogic.getParticleArrSize(); i++) {
Graphics2D g2 = (Graphics2D) g;
Color color = new Color(6,6,6);
Ellipse2D oval = new Ellipse2D.Double(
gameLogic.getParticleXCoor(i),
gameLogic.getParticleYCoor(i),
gameLogic.getParticleSize(i),
gameLogic.getParticleSize(i));
g2.setPaint(color);
g2.fill(oval);
g2.translate(15, 15);
g2.fill(oval);
}
}