Added foreground Animation by just extending the BGAnimation

This commit is contained in:
Seraina 2022-05-15 08:27:34 +02:00
parent 2393fb68fe
commit 0e6be2ee29
5 changed files with 38 additions and 18 deletions

View File

@ -3,22 +3,27 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui;
import javafx.animation.Interpolator;
import javafx.animation.Transition;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.util.Duration;
public class BGAnimation extends Transition {
ImageView imageView;
int index;
int lastIndex;
private ImageView bgView;
private ImageView fgView;
private int index;
private int lastIndex;
public BGAnimation(Duration duration, ImageView imageView) {
public BGAnimation(Duration duration, ImageView bgView, ImageView fgView) {
index = 0;
lastIndex = 1034;
this.imageView = imageView;
imageView.setFitHeight(1950);
imageView.setFitWidth(6667.968);
imageView.setImage(Sprites.getBg());
this.bgView = bgView;
this.fgView = fgView;
bgView.setFitHeight(1950);
bgView.setFitWidth(6667.968);
bgView.setImage(Sprites.getBg());
fgView.setFitHeight(1950);
fgView.setFitWidth(6667.968);
fgView.setImage(Sprites.getFg());
setCycleDuration(duration);
setInterpolator(Interpolator.DISCRETE);
@ -26,14 +31,19 @@ public class BGAnimation extends Transition {
@Override
protected void interpolate(double frac) {
imageView.setImage(Sprites.getBg());
bgView.setImage(Sprites.getBg());
fgView.setImage(Sprites.getFg());
if(index == lastIndex) {
index = 0;
imageView.setX(0);
imageView.setY(0);
bgView.setX(0);
fgView.setX(0);
bgView.setY(0);
fgView.setY(0);
}
imageView.setX(index * -5);
imageView.setY(index * -1.07);
bgView.setX(index * -5);
fgView.setX(index * -5);
bgView.setY(index * -1.07);
fgView.setY(index * -1.07);
index++;
}

View File

@ -30,6 +30,7 @@ public class DayNightChangeListener implements Runnable {
@Override
public void run() {
try{
Thread.sleep(1000); //TODO(Seraina): test!
while(!gameStateModel.isGameOver()) {
if(gameStateModel.getDayClone()) { //its Day
LoungeSceneViewController.getTrainAnimationDayController().dontShowFullWagon();

View File

@ -19,6 +19,10 @@ public class TrainAnimationDayController implements Initializable {
public static final Logger LOGGER = LogManager.getLogger(TrainAnimationDayController.class);
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
@FXML
public ImageView wagonWallImageView;
@FXML
public ImageView foreGroundAnimationImageView1;
@FXML
private ImageView backGroundAnimationImageView;
@FXML
@ -91,6 +95,9 @@ public class TrainAnimationDayController implements Initializable {
Animation wheels = new WheelsAnimation(Duration.millis(866.666), wheelsImageView);
wheels.setCycleCount(Animation.INDEFINITE);
wheels.play();
Animation backGround = new BGAnimation(Duration.millis(17), backGroundAnimationImageView, foreGroundAnimationImageView1);
backGround.setCycleCount(Animation.INDEFINITE);
backGround.play();
}
});
}

View File

@ -247,10 +247,7 @@ public class LoungeSceneViewController implements Initializable {
Platform.runLater(new Runnable() {
@Override
public void run() {
backGroundAnimationPane.getChildren().add(bgAnimationView);
Animation backGround = new BGAnimation(Duration.millis(17), bgAnimationView);
backGround.setCycleCount(Animation.INDEFINITE);
backGround.play();
//TODO(SERAINA): bgAnimation?
}
});
LOGGER.debug("In Initialize 3 LobbyListView" + LobbyListView);

View File

@ -47,5 +47,10 @@
<ImageView fx:id="wheelsImageView" fitHeight="843.75" fitWidth="1500.0" preserveRatio="true" />
</children>
</AnchorPane>
<AnchorPane layoutX="10.0" layoutY="10.0" pickOnBounds="false" prefHeight="200.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<ImageView fx:id="foreGroundAnimationImageView1" fitHeight="843.75" fitWidth="1500.0" preserveRatio="true" />
</children>
</AnchorPane>
</children>
</AnchorPane>