在javafx中克隆或复制形状? [英] Clone or duplicate shapes in javafx?
问题描述
我在javafx中使用Scenebuilder 2.0为GUI创建了一个Connect 4游戏。这基本上是从顶部下载芯片的动画片:
I'm making a Connect 4 game in javafx using Scenebuilder 2.0 for the GUI. This is basically what the animation for the chip coming down from top:
@FXML
private void click0(javafx.event.ActionEvent event) {
TranslateTransition translate = new TranslateTransition(
Duration.millis(750));
translate.setToX(1);
translate.setToY(432);
ParallelTransition transition = new ParallelTransition(c0,translate);
transition.setCycleCount(1);
transition.play();
}
当我点击直接位于所有行下方的按钮时,会发生这种情况。它还没有完成。但是我怎么能拥有一个重复的圈子(c0)保持原来的位置?
This happens when I click the buttons which is directly below all the rows. It isn't nearly complete yet. But how can I have a duplicate of the circle (c0) stay in the original position?
推荐答案
很简单 - 只是声明另一个与c0完全一样的圈子:
Very simple-- just declare another circle that is exactly the same as c0:
Circle c0copy = c0;
并将其添加到容器中的原始位置c0位于:
and add it to the original location in the container c0 is in:
yourPane.getChildren().add(c0copy);
如果你想在任何时候删除它(或任何其他任何窗格的孩子,将 remove()
更改为其他东西):
If you want to remove it at any point (or do anything else with any of the pane's children by changing remove()
to something else):
yourPane.getChildren().remove(c0copy);
这篇关于在javafx中克隆或复制形状?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!