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.Interpolator;
import javafx.animation.Transition; import javafx.animation.Transition;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.util.Duration; import javafx.util.Duration;
public class BGAnimation extends Transition { public class BGAnimation extends Transition {
ImageView imageView; private ImageView bgView;
int index; private ImageView fgView;
int lastIndex; private int index;
private int lastIndex;
public BGAnimation(Duration duration, ImageView imageView) { public BGAnimation(Duration duration, ImageView bgView, ImageView fgView) {
index = 0; index = 0;
lastIndex = 1034; lastIndex = 1034;
this.imageView = imageView; this.bgView = bgView;
imageView.setFitHeight(1950); this.fgView = fgView;
imageView.setFitWidth(6667.968); bgView.setFitHeight(1950);
imageView.setImage(Sprites.getBg()); bgView.setFitWidth(6667.968);
bgView.setImage(Sprites.getBg());
fgView.setFitHeight(1950);
fgView.setFitWidth(6667.968);
fgView.setImage(Sprites.getFg());
setCycleDuration(duration); setCycleDuration(duration);
setInterpolator(Interpolator.DISCRETE); setInterpolator(Interpolator.DISCRETE);
@ -26,14 +31,19 @@ public class BGAnimation extends Transition {
@Override @Override
protected void interpolate(double frac) { protected void interpolate(double frac) {
imageView.setImage(Sprites.getBg()); bgView.setImage(Sprites.getBg());
fgView.setImage(Sprites.getFg());
if(index == lastIndex) { if(index == lastIndex) {
index = 0; index = 0;
imageView.setX(0); bgView.setX(0);
imageView.setY(0); fgView.setX(0);
bgView.setY(0);
fgView.setY(0);
} }
imageView.setX(index * -5); bgView.setX(index * -5);
imageView.setY(index * -1.07); fgView.setX(index * -5);
bgView.setY(index * -1.07);
fgView.setY(index * -1.07);
index++; index++;
} }

View File

@ -30,6 +30,7 @@ public class DayNightChangeListener implements Runnable {
@Override @Override
public void run() { public void run() {
try{ try{
Thread.sleep(1000); //TODO(Seraina): test!
while(!gameStateModel.isGameOver()) { while(!gameStateModel.isGameOver()) {
if(gameStateModel.getDayClone()) { //its Day if(gameStateModel.getDayClone()) { //its Day
LoungeSceneViewController.getTrainAnimationDayController().dontShowFullWagon(); 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 Logger LOGGER = LogManager.getLogger(TrainAnimationDayController.class);
public static final BudaLogConfig l = new BudaLogConfig(LOGGER); public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
@FXML
public ImageView wagonWallImageView;
@FXML
public ImageView foreGroundAnimationImageView1;
@FXML @FXML
private ImageView backGroundAnimationImageView; private ImageView backGroundAnimationImageView;
@FXML @FXML
@ -91,6 +95,9 @@ public class TrainAnimationDayController implements Initializable {
Animation wheels = new WheelsAnimation(Duration.millis(866.666), wheelsImageView); Animation wheels = new WheelsAnimation(Duration.millis(866.666), wheelsImageView);
wheels.setCycleCount(Animation.INDEFINITE); wheels.setCycleCount(Animation.INDEFINITE);
wheels.play(); 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() { Platform.runLater(new Runnable() {
@Override @Override
public void run() { public void run() {
backGroundAnimationPane.getChildren().add(bgAnimationView); //TODO(SERAINA): bgAnimation?
Animation backGround = new BGAnimation(Duration.millis(17), bgAnimationView);
backGround.setCycleCount(Animation.INDEFINITE);
backGround.play();
} }
}); });
LOGGER.debug("In Initialize 3 LobbyListView" + LobbyListView); 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" /> <ImageView fx:id="wheelsImageView" fitHeight="843.75" fitWidth="1500.0" preserveRatio="true" />
</children> </children>
</AnchorPane> </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> </children>
</AnchorPane> </AnchorPane>