所以我有一个阶段,我正在渲染一些imageview数组,问题是root.getChildren()。remove(i);并不总是从组中删除正确的项目。
一个解决方案是在场景中拥有多个群组,但互联网对此非常安静,所以我甚至不知道是否可以这样做。
另一种解决方案是在舞台上拥有多个场景,并使除最底层之外的所有场景都透明。我发现的唯一信息是让整个舞台变得透明,在这种情况下根本没有帮助我。
或者我在想错误的方向?
我如何将克隆对象添加到组中的示例(此代码围绕每个帧运行):
final ImageView ext = new ImageView();
ext.setTranslateX(move2.x);
ext.setTranslateY(move2.y);
ext.getTransforms().add(new Rotate(GPU.rotat,45, -70));
ext.setImage(thrustereffect);
root.getChildren().add(ext);
答案 0 :(得分:0)
import javafx.animation.ParallelTransition;
import javafx.animation.PathTransition;
import javafx.animation.PathTransition.OrientationType;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.CubicCurveTo;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.stage.Stage;
import javafx.util.Duration;
public class Mains extends Application{
@Override
public void start(Stage stage) throws Exception
{
final Group rootGroup = new Group();
final Group subGroup1= new Group();
rootGroup.getChildren().add( subGroup1 );
final Scene scene = new Scene(rootGroup, 350, 550, Color.GHOSTWHITE);
stage.setScene(scene);
stage.setTitle("Animations");
stage.show();
final Path pathOn_rootGroup = new Path();
final Path pathOn_subGroup1 = new Path();
pathOn_rootGroup.getElements().add(new MoveTo( 0, 20 ) );
pathOn_rootGroup.getElements().add(
new CubicCurveTo( 30, 120, 30, 220, 520, 120) );
pathOn_subGroup1.getElements().add(new MoveTo( 50, 50 ) );
pathOn_subGroup1.getElements().add(
new CubicCurveTo( 350, 20, 250, 240, 320, 240 ) );
pathOn_rootGroup.setOpacity( 0.5 );
pathOn_subGroup1.setOpacity( 0.5 );
rootGroup.getChildren().add( pathOn_rootGroup );
subGroup1.getChildren().add( pathOn_subGroup1 );
final javafx.scene.shape.Circle rootGroup_shape =
new javafx.scene.shape.Circle();
rootGroup_shape.setCenterX(50);
rootGroup_shape.setCenterY(50);
rootGroup_shape.setRadius(12.5);
rootGroup_shape.setFill( Color.AQUA );
final javafx.scene.shape.Rectangle subGroup1_shape =
new javafx.scene.shape.Rectangle();
subGroup1_shape.setX(20);
subGroup1_shape.setY(20);
subGroup1_shape.setWidth(20);
subGroup1_shape.setHeight(30);
subGroup1_shape.setFill( Color.BLUEVIOLET );
rootGroup.getChildren().add( rootGroup_shape );
subGroup1.getChildren().add( subGroup1_shape );
final PathTransition pathTransition_rootGroup = new PathTransition();
pathTransition_rootGroup.setDuration(Duration.seconds(8.0));
pathTransition_rootGroup.setDelay(Duration.seconds(.5));
pathTransition_rootGroup.setPath(pathOn_rootGroup);
pathTransition_rootGroup.setNode(rootGroup_shape);
pathTransition_rootGroup.setOrientation(OrientationType.NONE);
pathTransition_rootGroup.setCycleCount(Timeline.INDEFINITE);
pathTransition_rootGroup.setAutoReverse(true);
final PathTransition pathTransition_subGroup1 = new PathTransition();
pathTransition_subGroup1.setDuration(Duration.seconds(8.0));
pathTransition_subGroup1.setDelay(Duration.seconds(1.0));
pathTransition_subGroup1.setPath(pathOn_subGroup1);
pathTransition_subGroup1.setNode(subGroup1_shape);
pathTransition_subGroup1.setOrientation(OrientationType.NONE);
pathTransition_subGroup1.setCycleCount(Timeline.INDEFINITE);
pathTransition_subGroup1.setAutoReverse(true);
final ParallelTransition parallelTransition =
new ParallelTransition(pathTransition_rootGroup, pathTransition_subGroup1 );
parallelTransition.play();
}// end start()
public static void main(final String[] arguments)
{
Application.launch(arguments);
}// end main method
}// end class Main