저는 JavaFX 2.0에 익숙해지면서 애니메이션을 가지고 놀았으며, X 축과 Y 축을 따라 사각형을 회전시키기위한 작은 테스트 프로그램을 작성했습니다. 다음은 테스트 프로그램입니다.동일한 노드에서 두 개의 동시 회전 전환이 있습니다.
import javafx.animation.Animation;
import javafx.animation.FadeTransition;
import javafx.animation.ParallelTransition;
import javafx.animation.RotateTransition;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.RectangleBuilder;
import javafx.scene.transform.Rotate;
import javafx.stage.Stage;
import javafx.util.Duration;
public class ParallelTransitionTest extends Application
{
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception
{
init(primaryStage);
primaryStage.show();
}
private void init(Stage primaryStage)
{
primaryStage.setTitle("Parallel Transition");
primaryStage.setResizable(true);
// Create the scene
BorderPane root = new BorderPane();
Scene scene = new Scene(root, 800, 600, true);
scene.setFill(Color.BLACK);
primaryStage.setScene(scene);
Rectangle rect = RectangleBuilder.create()
.width(100).height(100)
.x(350).y(250)
.fill(Color.BLUE)
.build();
RotateTransition rotationY = new RotateTransition();
rotationY.setAxis(Rotate.Y_AXIS);
rotationY.setDuration(Duration.seconds(5));
rotationY.setByAngle(360);
rotationY.setNode(rect);
rotationY.setAutoReverse(true);
rotationY.setCycleCount(Animation.INDEFINITE);
RotateTransition rotationX = new RotateTransition();
rotationX.setAxis(Rotate.X_AXIS);
rotationX.setDuration(Duration.seconds(5));
rotationX.setByAngle(360);
rotationX.setNode(rect);
rotationX.setAutoReverse(true);
rotationX.setCycleCount(Animation.INDEFINITE);
FadeTransition fade = new FadeTransition();
fade.setDuration(Duration.seconds(5));
fade.setToValue(0.2);
fade.setNode(rect);
fade.setAutoReverse(true);
fade.setCycleCount(Animation.INDEFINITE);
ParallelTransition transition = new ParallelTransition(rect,
rotationX, rotationY, fade);
transition.setAutoReverse(true);
transition.play();
root.getChildren().add(rect);
}
}
불행하게도 축 중 하나에서만 회전이 발생합니다. 내 가정은 모두 RotationTransition
이 실행되고 있지만 다른 하나가 적용한 회전을 덮어 쓰는 것입니다. 이 의도 된 동작은 RotationTransition
입니까? 다음 세 줄은 주석 경우에도
rotationY.setNode(rect);
...
rotationX.setNode(rect);
...
fade.setNode(rect);
은 내가 NullPointerException
를 얻을. 문서에서는 ParallelTransition
에 포함 된 전환에 노드를 설정할 필요가 없다고 제안합니다. 이거 버그 야?
시도 [설정] (http://docs.oracle.com/javafx/2.0/api/javafx/scene/ Scene.html # setCamera % 28javafx.scene.Camera % 29) a [PerspectiveCamera] (http://docs.oracle.com/javafx/2.0/api/javafx/scene/PerspectiveCamera.html)를 선택합니다. – jewelsea
@jewelsea PerspectiveCamera를 사용하면 (예상대로) 원근감을 변경했지만 동시에 'RotationTransition'문제를 수정하지 않았습니다. – lifelongcoug