Repository navigation
Expand file tree
/
Copy pathSmallExplosion.java
More file actions
44 lines (37 loc) · 1.49 KB
/
Copy pathSmallExplosion.java
File metadata and controls
44 lines (37 loc) · 1.49 KB
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
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.animation.PauseTransition;
import javafx.util.Duration;
// The SmallExplosion class represents a visual effect for small explosions.
public class SmallExplosion extends ImageView {
private PauseTransition transition; // Controls how long the explosion stays visible
// Creates and displays a small explosion at the specified (x, y) coordinates.
public SmallExplosion(double x, double y, GameManager gameManager) {
// Load the explosion image
Image explosionImage = new Image("file:assets/smallExplosion.png");
setImage(explosionImage);
setFitWidth(32);
setFitHeight(32);
// Center the image around (x, y)
setTranslateX(x - 16); // 32 / 2
setTranslateY(y - 16); // 32 / 2
// Add explosion to the game scene
gameManager.getChildren().add(this);
// Automatically remove the explosion after 0.3 seconds
transition = new PauseTransition(Duration.seconds(0.3));
transition.setOnFinished(e -> gameManager.getChildren().remove(this));
transition.play();
}
// Pauses the explosion's disappearance.
public void pause() {
if (transition != null) {
transition.pause();
}
}
// Resumes the explosion's disappearance.
public void resume() {
if (transition != null) {
transition.play();
}
}
}