2017-03-10 7 views
0

Es gibt viele ImagePanels auf einer Region Oberfläche. Ich halte sie in Gruppen. Sie sollen horizontal in einer Kette rollen. enter image description hereMehrere Timeline-Animation in javafx-8

Es gibt einige Methoden, die ich dafür geschrieben habe, um zu arbeiten. Zum Beispiel Schaltposition links. (rects - Rechtecke. Früher war es Rechtecke).

//---------  OO<->OO OOOOOO OOOO  ----------------------- 
    private void shiftAnimatedInLeft(ObservableList rects) 
    { 
    ParallelTransition pt = new ParallelTransition(); 
    for (int i = 0; i < rects.size(); i++) 
    { 
     double startPosition = ((ImagePanel) rects.get(i)).getTranslateX(); 
     double finishPosition = -(rects 
       .size() - i) * getSideImageOffset() - getCenterOffset() - (IMAGE_WIDTH * (1 - SCALE_SMALL)/2); 
     Timeline timeline = new Timeline(); 
    timeline.getKeyFrames().addAll(
      new KeyFrame(new Duration(0), 
         new KeyValue(((ImagePanel) rects.get(i)).translateXProperty(), 
            startPosition, 
            INTERPOLATOR)), 
      new KeyFrame(new Duration(500), 
         new KeyValue(((ImagePanel) rects.get(i)).translateXProperty(), 
            finishPosition, 
            INTERPOLATOR)) 
); 
    pt.getChildren().add(timeline); 
//  timeline.play(); 
    } 
    pt.play(); 
    } 

z. Verschiebe Elemente von Mitte nach links.

//---------  OOOO <-OOOOOO OOOO  ----------------------- 


private void shiftAnimatedCenterToLeft(ImagePanel rect) 
    { 
    double startPosition = rect.getTranslateX(); 
    double finishPosition = - getSideImageOffset() - getCenterOffset() - (IMAGE_WIDTH*(1-SCALE_SMALL)/2); 

Timeline timeline = new Timeline(); 
timeline.getKeyFrames().addAll(
     new KeyFrame(new Duration(0), 
        new KeyValue(rect.translateXProperty(), startPosition, INTERPOLATOR), 
        new KeyValue(rect.scaleXProperty(), rect.getScaleX(), INTERPOLATOR), 
        new KeyValue(rect.scaleYProperty(), rect.getScaleY(), INTERPOLATOR), 
        new KeyValue(rect.angle, -270.0, INTERPOLATOR), 
        new KeyValue(rect.opacity, 1.0, INTERPOLATOR), 
        new KeyValue(rect.vboxStyle, "imagePanelBlackVBox", INTERPOLATOR)), 
     new KeyFrame(new Duration(500), 
        new KeyValue(rect.translateXProperty(), finishPosition, INTERPOLATOR), 
        new KeyValue(rect.scaleXProperty(), SCALE_SMALL, INTERPOLATOR), 
        new KeyValue(rect.scaleYProperty(), SCALE_SMALL, INTERPOLATOR), 
        new KeyValue(rect.angle, ANGLE, INTERPOLATOR), 
        new KeyValue(rect.opacity, 0.0, INTERPOLATOR), 
        new KeyValue(rect.vboxStyle, "imagePanelWhiteVBox", INTERPOLATOR)) 
); 
timeline.play(); 
    } 

usw.

Diese Verfahren verwenden onKeyPressed (links \ rechts) oder Scrollereignisse Mausrad.

Schließlich Problem: Wenn ich versuche, dies in einer unabhängigen Anwendung zu verwenden, funktioniert es normal (aber nicht nett). Wenn ich jedoch versuche, es in eine andere App zu integrieren, wird alles sehr lückig und verlangsamt die gesamte Animation.

Antwort

0

Sie könnten Animation in einem anderen Thread mit Platform.runLater() ausführen - vielleicht würde es helfen - oder testen Sie die Leistung Ihrer Anwendung mit Profiler wie JProfiler (oder einem anderen freien Äquivalent) und optimieren Sie die anspruchsvollsten Teile Ihres Codes.

Verwandte Themen