栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

JavaFX中抛物线轨迹的时间线

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

JavaFX中抛物线轨迹的时间线

在a中

KeyValue
,第一个参数应为a
Writablevalue
,例如
circle.centerXProperty()
,代表初始坐标,例如
x
。第二个参数应该是类型兼容的值,在这种情况下
x
,就是射弹应向其移动的坐标。随着时间线播放,
Writablevalue
将会相应更新。添加一秒钟
KeyValue
以驱动
y
坐标。

在此处看到的第一个示例中,三个实例

KeyValue
将图形从其初始位置移动到其目的地位置,该位置是
size
沿每个坐标轴的单位。在此相关示例中,图形将形状点移动
p1
p2

在下面的例子中,

Circle
移动平行于
x
间轴
100
500
。同时,它们
Circle
平行于抛物线 y = –4( x –½)2
+1 定义的
y
轴之间
300
100
跟随其移动的轴,其顶点(1 / 2,1)且 x
在0和1处相交。根据API的要求,在单位正方形上实现抛物线路径模型的实现。您可以通过在关键帧中更改高度与宽度的比率来更改仰角,例如
curve()
__
curve()``curve()


KeyValue xKV = new KeyValue(c.centerXProperty(), 200);KeyValue yKV = new KeyValue(c.centerYProperty(), 0, new Interpolator() {…});

import javafx.animation.Interpolator;import javafx.animation.Keyframe;import javafx.animation.KeyValue;import javafx.animation.Timeline;import javafx.application.Application;import javafx.scene.Group;import javafx.scene.Scene;import javafx.scene.paint.Color;import javafx.scene.shape.Circle;import javafx.scene.shape.Line;import javafx.stage.Stage;import javafx.util.Duration;public class Test extends Application {    @Override    public void start(Stage primaryStage) {        primaryStage.setTitle("Test");        Group group = new Group();        Scene scene = new Scene(group, 600, 350);        scene.setFill(Color.BLACK);        primaryStage.setScene(scene);        primaryStage.show();        Circle c = new Circle(100, 300, 16, Color.AQUA);        Line l = new Line(100, 300, 500, 300);        l.setStroke(Color.AQUA);        group.getChildren().addAll(c, l);        final Timeline timeline = new Timeline();        timeline.setCycleCount(Timeline.INDEFINITE);        timeline.setAutoReverse(false);        KeyValue xKV = new KeyValue(c.centerXProperty(), 500);        KeyValue yKV = new KeyValue(c.centerYProperty(), 100, new Interpolator() { @Override protected double curve(double t) {     return -4 * (t - .5) * (t - .5) + 1; }        });        Keyframe xKF = new Keyframe(Duration.millis(2000), xKV);        Keyframe yKF = new Keyframe(Duration.millis(2000), yKV);        timeline.getKeyframes().addAll(xKF, yKF);        timeline.play();    }    public static void main(String[] args) {        launch(args);    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/463595.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号