장면을 다른 장면으로 전환하기 위해 슬라이딩 애니메이션을 만들지 만,이 메서드를 호출하면 전환 장면이 지연됩니다. 원인이 Scene
인 snapshot()
이라는 것을 발견했습니다. 해결책이있는 사람이 있습니까?Javafx Scene.snapshot 메서드가 느린 성능을 사용합니다.
코드 :
public void switchScene(Scene target) {
Scene current = getPrimaryStage().getScene();
WritableImage beforeImage;
WritableImage afterImage;
int width = ((int) ((Region) current.getRoot()).getWidth());
int height = ((int) ((Region) current.getRoot()).getHeight());
beforeImage = new WritableImage(width, height);
ImageView leftImage = new ImageView(current.snapshot(beforeImage));
afterImage = new WritableImage(width, height);
ImageView rightImage = new ImageView(target.snapshot(afterImage));
leftImage.setTranslateX(0);
rightImage.setTranslateX(width);
StackPane animation = new StackPane(leftImage, rightImage);
animation.setPrefSize(target.getWidth(), target.getHeight());
primaryStage.setScene(new Scene(animation));
Timeline timeline = new Timeline();
KeyValue kv = new KeyValue(rightImage.translateXProperty(), 0, Interpolator.EASE_BOTH);
KeyFrame kf = new KeyFrame(Duration.seconds(0.75), kv);
timeline.getKeyFrames().add(kf);
timeline.setOnFinished(t -> {
// remove pane and restore scene 1
primaryStage.setScene(target);
});
timeline.play();
}
당신이 무엇을하려고하는지 잘 모르겠습니다. 그러나 [스냅 샷] (snapshot)에 대한 비동기 호출을 만드십시오. (http://docs.oracle.com/javafx/2/api/javafx/scene/Scene.html#snapshot (javafx.util.Callback, % 20javafx.scene.image.WritableImage)) method? – ItachiUchiha