我正在尝试使用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
的末尾我没有看到任何动画,只是插入图形后网格的最终状态。
有什么帮助吗?