2015-05-24 56 views
1

嘿,我想做一個簡單的2d滾動,但我根本無法得到圖片滾動。我爲圖片使用了ImagveView,並且我嘗試了translatetransition和pathtransition,但是我得不到任何好結果?這裏是我的代碼:JavaFX 8 2d Scroller

public void aboutSceneAnimation() { 

    Rectangle2D psb = Screen.getPrimary().getVisualBounds(); 

    Path path = new Path(); 
    MoveTo moveTo = new MoveTo(); 
    moveTo.setX(0.0); 
    path.getElements().add(moveTo); 
    PathTransition pt = new PathTransition(); 
    pt.setDuration(Duration.INDEFINITE); 
    pt.setNode(map); 
    pt.setPath(path); 
    pt.setCycleCount(4); 
    pt.setAutoReverse(true); 

    pt.play(); 
} 

public Scene aboutScene() { 
    Rectangle2D psb = Screen.getPrimary().getVisualBounds(); 

    //Create the map 

    BorderPane border = new BorderPane(); 
    border.getChildren().addAll(map2); 

    //Size the map 

    map2.setFitWidth(psb.getWidth()); 
    map2.setFitHeight(psb.getHeight()); 

    Scene scene = new Scene(border, 500, 500); 
    aboutSceneAnimation(); 
    return scene; 

} 

它的工作方式是,在程序啓動時有加載到我的舞臺開始場景,然後我只是展現的舞臺。當按下按鈕時,我只需切換到aboutScene,它也調用aboutSceneAnimation,這是我希望地圖滾動的位置。任何想法將不勝感激!

-Cheers

回答