码迷,mamicode.com
首页 > 移动开发 > 详细

JavaFx动画-路径移动

时间:2021-02-18 13:23:30      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:rri   vat   tran   prim   tag   ini   start   mat   getch   

import javafx.animation.Animation;
import javafx.animation.PathTransition;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Ellipse;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.util.Duration;

public class App16_9 extends Application {

    private TextArea textArea = new TextArea("我喜欢用JavaFx编程");

    @Override
    public void start(Stage primaryStage) {

        Pane pane = new Pane();
        Text t = new Text("您好");
        t.setFont(Font.font(20));
        t.setFill(Color.RED);
        Ellipse ellipse = new Ellipse(100, 60, 70, 40);
        ellipse.setFill(Color.WHITE);
        ellipse.setStroke(Color.BLUE);
        pane.getChildren().addAll(ellipse, t);

        //创建动画路径
        PathTransition pathTransition = new PathTransition();
        //设置播放的持续时间
        pathTransition.setDuration(Duration.millis(4000));
        //设置椭圆为路径
        pathTransition.setPath(ellipse);
        //设置t为动画节点
        pathTransition.setNode(t);
        pathTransition.setOrientation(PathTransition.OrientationType.ORTHOGONAL_TO_TANGENT);
        //设置无限次播放
        pathTransition.setCycleCount(Animation.INDEFINITE);
        pathTransition.setAutoReverse(false);
        pathTransition.play();

        ellipse.setOnMousePressed(e -> pathTransition.pause());
        ellipse.setOnMouseReleased(e -> pathTransition.play());

        Scene scene = new Scene(pane, 800, 600);
        primaryStage.setScene(scene);
        primaryStage.setTitle("移动路径动画");
        primaryStage.show();

    }

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

JavaFx动画-路径移动

标签:rri   vat   tran   prim   tag   ini   start   mat   getch   

原文地址:https://www.cnblogs.com/xl4ng/p/14406537.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!