使用 JavaFX DropShadow 移动节点留下痕迹

Moving Node with JavaFX DropShadow leaves trail

在我使用 JavaFX 开发的游戏中,我有卡片(Labels) with DropShadows. The cards can move, and, when they do, the shadow leaves behind a faint trail. I've tried using Node#setCache(boolean),它有效,但模糊了标签中的文本。

还有其他方法可以防止 DropShadow 留下踪迹吗?

这是一个 MCVE 结果:

public class DropShadowTest extends Application {

    @Override
    public void start(final Stage stage) throws Exception {
        final Label label = new Label("Hello, world!");
        label.setBackground(new Background(new BackgroundFill(Color.LIGHTGRAY, new CornerRadii(10), Insets.EMPTY)));
        label.setEffect(new DropShadow(3, 0, 1, Color.BLACK));
        label.setMaxSize(100, 100);
        label.setMinSize(100, 100);

        stage.setScene(new Scene(new StackPane(label), 640, 480));
        stage.show();

        label.setOnMouseClicked(event -> {
            final TranslateTransition anim = new TranslateTransition(Duration.seconds(1), label);
            anim.setToX(Math.random() * 500 - 250);
            anim.setToY(Math.random() * 300 - 150);
            anim.play();
        });
    }

    public static void main(final String[] args) {
        Application.launch(args);
    }

}

结果:

谢谢!

尝试将缓存Cache hints , For example before you start animating you set the cache hint to SPEED一起使用 完成动画后,切换回 QUALITY ,它将重新渲染您的节点(就像 swing 中的 repaint())