-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTitleScreen.java
68 lines (56 loc) · 2.37 KB
/
TitleScreen.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import javafx.animation.Timeline;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.scene.layout.StackPane;
import javafx.scene.media.AudioClip;
import javafx.animation.KeyFrame;
public class TitleScreen extends Scene {
public TitleScreen(Parent root) {
super(root);
ImageView welcomeImage = new ImageView(new Image("file:assets\\welcome\\1.png"));
welcomeImage.setFitWidth(256 * DuckHunt.scale);
welcomeImage.setFitHeight(240 * DuckHunt.scale);
Text welcomeText = new Text("PRESS ENTER TO PLAY\nPRESS ESC TO QUIT");
welcomeText.setFont(Font.font("Verdana",FontWeight.BOLD, 18 * DuckHunt.scale));
welcomeText.setFill(javafx.scene.paint.Color.ORANGE);
welcomeText.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
StackPane stackPane = new StackPane();
stackPane.getChildren().add(welcomeText);
stackPane.setAlignment(javafx.geometry.Pos.CENTER);
stackPane.setTranslateY(50 * DuckHunt.scale);
Timeline timeline = new Timeline(
new KeyFrame(javafx.util.Duration.seconds(0.5), e -> {
welcomeText.setVisible(!welcomeText.isVisible());
})
);
timeline.setCycleCount(Timeline.INDEFINITE);
timeline.play();
AudioClip welcomeSound = new AudioClip("file:assets/effects/Title.mp3");
welcomeSound.setVolume(DuckHunt.volume);
welcomeSound.setCycleCount(AudioClip.INDEFINITE);
welcomeSound.play();
((StackPane)root).getChildren().addAll(welcomeImage, stackPane);
this.setOnKeyPressed(e -> {
switch (e.getCode()) {
case ENTER:
BackgroundSelection backgroundSelection = new BackgroundSelection(new StackPane());
DuckHunt.stage.setScene(backgroundSelection);
break;
case ESCAPE:
System.exit(0);
break;
default:
break;
}
});
}
public static void stopMusic() {
AudioClip welcomeSound = new AudioClip("file:assets/effects/Title.mp3");
welcomeSound.stop();
}
}