如何在JavaFX Canvas上禁用抗锯齿?

问题描述:

目前,我正在使用JavaFX制作2D游戏,该游戏是像素艺术.不幸的是,由于抗锯齿,像素图像变得模糊.

Currently I am working on a 2D Game using JavaFX, the game is pixel art. Unfortunetly, the pixel art is blurry, caused by Antialiasing.

有什么方法可以禁用JavaFX画布上的抗锯齿功能吗?我试过使用SceneAntialiasing.DISABLED,但没有用.我找不到其他禁用它的方法.

Is there any way to disable antialiasing on a JavaFX canvas? I've tried using SceneAntialiasing.DISABLED and It didn't work. I can't find any other way of disabling it.

canvas.getGraphicsContext2D().setImageSmoothing(false);

(自JavaFX 12起).