dimanche 12 février 2017

Add A New KeyFrame to Timeline While an Animation is Executing

Vote count: 0

I would like to modify a Timeline while it is running, for example in response to a mouse-click I want to change the target value of the animation. I have tried several methods to do this including (in a mouse clicked handler) :

  1. Pausing the animation by calling pause() on the Timeline, clearing the KeyFramesObservableList, adding a new KeyFrame and calling play() on the Timeline.
  2. Creating a new KeyFrame with a Cue-name, adding the new frame to the Observable list and calling jumpTo(cueName) on the Timeline.

Some example code is:

String cueName = String.valueOf(System.currentTimeMillis());
KeyValue kv = new KeyValue(myObject.rotateProperty(), -90 + 180.0 * Math.random(), new CustomInterpolator());
KeyFrame kf = new KeyFrame(Duration.seconds(10), cueName, kv);
startupTimeline.getKeyFrames().add(kf);
startupTimeline.jumpTo(cueName);
startupTimeline.play();

Neither of these appear to work, the animation just stops.

Should I be able to modify the KeyFrame list of an existing Timeline or do I need to create a new Timeline if I want to change an animation while it is executing?

asked 1 min ago

Let's block ads! (Why?)



Add A New KeyFrame to Timeline While an Animation is Executing

Aucun commentaire:

Enregistrer un commentaire