私はJavaFX 2.0に精通しながらアニメーションを再生していましたが、X軸とY軸に沿って長方形を回転させるための小さなテストプログラムを作成しました。ここにテストプログラムがあります:同じノード上の2つの同時回転トランジション
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);
}
}
残念ながら、回転は1つの軸で起こっています。私の前提は、両方ともRotationTransition
が実行されているが、一方が他方によって適用されたローテーションを上書きしているということです。これは意図された動作ですか?RotationTransition
?また
、次の3行がコメントされている場合:
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