我是javafx的新手,正在使用它的渲染功能编写游戏,具体来说就是在eclipse中使用GraphicsContext.fillArc()
等函数。
这是我的当前代码:
BorderPane root = new BorderPane();
Scene scene = new Scene(root, 400, 400);
primaryStage.setScene(scene);
scene.getStylesheets()
.add(getClass().getResource("application.css").toExternalForm());
Canvas canvas = new Canvas(400, 400);
root.getChildren().add(canvas);
GraphicsContext gc = canvas.getGraphicsContext2D();
new AnimationTimer()
{
public void handle(long currentNanoTime)
{
gc.setFill(Color.BLUE);
gc.fillArc(150, 150, 100, 100, 0, 240, ArcType.ROUND);
}
}.start();
primaryStage.show();
然而,
fillArc()
方法在我的屏幕上呈现的形状边缘不平滑。我希望应用抗锯齿处理以使边缘平滑。然而,在 GraphicsContext
类中找不到任何相关方法,将 scene
的实例化更改为 new Scene(root, 400, 400, false, SceneAntialiasing.BALANCED);
也没有效果。因此,我的问题是如何在 GraphicsContext.fillArc()
上实现抗锯齿处理,或者是否基本上可能?另外,我对 javafx 和 cgi 一般都非常陌生,所以欢迎任何建议和推荐。
更新:
正如 @jewelsea 建议的那样,当代码块
gc.setFill(Color.BLUE);
gc.fillArc(150, 150, 100, 100, 0, 240, ArcType.ROUND);
放置在 AnimationTimer
的匿名子类之外时,渲染的图像是抗锯齿的。目前我们都无法弄清楚原因。供参考。
AnimationTimer
类的属性。 - cyqsimon