请教JavaFx的PathTransition类的问题。

SilentHunter460 2020-04-01 11:57:10
这段程序,方块“rectangle对象”沿着圆圈运动,但是每圈都要暂停一小会儿,如何让方块不要暂停?我翻遍PathTransition的API说明也没找到。


import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.control.Button;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.event.EventHandler;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.animation.PathTransition;
import javafx.util.Duration;

public class Chapter15_11 extends Application{

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

@Override
public void start(Stage window) {
Circle pathcircle = new Circle(300, 300, 250);
Line pathline = new Line(50, 300, 550, 300);
Circle circle = new Circle(300, 300, 12);
Rectangle rectangle = new Rectangle(275, 275, 50, 50);
pathcircle.setStroke(Color.DARKGRAY);
pathcircle.setFill(null);
rectangle.setStroke(Color.BLACK);
rectangle.setFill(Color.LIGHTGRAY);
Pane pane = new Pane(pathcircle, pathline, rectangle, circle);
Scene scene = new Scene(pane, 600, 600);
window.setScene(scene);
window.setTitle("PathTransition");
window.setResizable(false);
window.show();
PathTransition path = new PathTransition(new Duration(3000), pathcircle, rectangle);
path.setOrientation(PathTransition.OrientationType.ORTHOGONAL_TO_TANGENT);
path.setCycleCount(200);
path.setAutoReverse(false);
path.play();
PathTransition path2 = new PathTransition(new Duration(3000), pathline, circle);
path2.setCycleCount(200);
path2.setAutoReverse(true);
path2.play();
}

}


...全文
217 1 打赏 收藏 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
SilentHunter460 2020-04-03
  • 打赏
  • 举报
回复
up up up

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧