使用函数调用运行转换几次

时间:2014-04-03 22:07:46

标签: javafx transition

我正在尝试使用javaFX过渡类。我写了这个函数,它将Labal设置为Scene中特定位置的动画。

问题是,显示的动画仅用于函数的最后一次调用。
这是调用循环:

List<Player> tempList = myTable.getPlayersOnTable();
for (int i = 0 ; i < myTable.getNumberOfPlayers() ; ++i) {
    dealCardsAnimation(tempList.get(i).getHand().get(0).getHandCards().getCard(0), i);
    dealCardsAnimation(tempList.get(i).getHand().get(0).getHandCards().getCard(1), i);
}

private void dealCardsAnimation(Card card, int playerIndex) {
    ImageView cardImage = new ImageView("resources/cards/" 
                                         + card.getSuit().toString() + "/" 
                                         + card.getRank().toString() + ".png");
    cardImage.setFitWidth(72);
    cardImage.setFitHeight(113);    
    deckLabel.setGraphic(cardImage);
    playersCardsLocation.get(playerIndex).insertCardToGrid(deckLabel);

}

和函数本身:

  

private AnchorPane cardsGridPane; private int index;

public void insertCardToGrid(Label card) {
    double x = card.getLayoutX();
    double y = card.getLayoutY();
    FlowPane temp = (FlowPane) (cardsGridPane.getChildren().get(index));

    TranslateTransition translate = new TranslateTransition(Duration.seconds(0.5), card);
    translate.setToX(cardsGridPane.getLayoutX() + temp.getLayoutX() - x);
    translate.setToY(cardsGridPane.getLayoutY() + temp.getLayoutY() - y);

    RotateTransition rotate = new RotateTransition(Duration.seconds(0.5), card);
    rotate.setToAngle(temp.getRotate());

    ParallelTransition transition = new ParallelTransition(translate, rotate);
    transition.play();

    card.setLayoutX(x);
    card.setLayoutY(y);
    index++;
}

最后一件事 - 当我添加这一行时:

    temp.getChildren().add(card.getGraphic());

insertCardToGrid的末尾我没有看到任何动画,只是插入图形后网格的最终状态。 有什么帮助吗?

0 个答案:

没有答案