你能鏈接滾動到時間軸動畫嗎? 然後按鈕可以控制時間線的開始和停止。
例如,這是類似的,但它控制一個正方形的旋轉(也許你可以使用一個TranslateTransition):
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.animation.transition.RotateTransition;
import javafx.animation.Timeline;
import javafx.scene.control.Button;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.animation.Interpolator;
def r = Rectangle {
x: 80 y: 80
height: 100 width: 100
arcHeight: 50 arcWidth: 50
fill: Color.VIOLET
}
def rotTransition = RotateTransition {
duration: 1s
node: r
byAngle: 180
repeatCount: Timeline.INDEFINITE
interpolator: Interpolator.LINEAR
}
def b = Button {
text: "Click and hold"
onMousePressed: function (e) {
rotTransition.play();
};
onMouseReleased: function (e) {
rotTransition.stop();
};
};
Stage {
title : "Rotation"
scene: Scene {
width: 250
height: 250
content: [r,b]
}
}
感謝,搗爛。很棒。 – Averroes 2009-10-21 18:40:31