我正在尝试实施定期生成并经历更长过渡周期的敌人。敌人生成之间的距离太长。任何建议都会有所帮助
我尝试将持续时间周期设置为一堆不同的长度,将其设置为较低的持续时间(5秒)会使动画过快达到我想要的速度
公共类敌人收集扩展了gameController {
private Rectangle grunte;
public enemyCollection(Rectangle grunt, Rectangle spawnBox, AnchorPane pane) {
//Creates base Grunt Unit
Rectangle grunte = new Rectangle();
grunte.setHeight(30);
grunte.setWidth(30);
grunte.setFill(javafx.scene.paint.Color.RED);
grunte.setLayoutX(1863);
grunte.setLayoutY(33);
//Code of the generic Path
Path path = new Path();
path.getElements().add(new MoveTo(1863,33));
//Start Coordinates
double startX = -15;
double endX = -115;
//Loop's rest of enemy path
for(int i = 0; i <= 6 ; ++i) {
path.getElements().add(new LineTo(startX, 10));
path.getElements().add(new LineTo(startX, 1000));
path.getElements().add(new LineTo(endX, 1000));
path.getElements().add(new LineTo(endX, 10));
path.getElements().add(new LineTo(endX - 100, 10));
startX = endX - 200;
endX = endX - 300;
}
pane.getChildren().add(grunte); //Adds path to grunt unit
PathTransition pathT = new PathTransition();
pathT.setDuration(Duration.seconds(5));
pathT.setPath(path);
pathT.setNode(grunte);
pathT.setCycleCount(PathTransition.INDEFINITE);
pathT.setAutoReverse(false);
pathT.setInterpolator(Interpolator.LINEAR);
pathT.play();
pane.getChildren().add(grunte);
}
我希望敌人会持续不断地产生,并且会经历很长的动画周期