The backButton element in gameInterface() doesn’t seem to detect any clicks or inputs made on it, although it works perfectly fine in other classes, using the same code. It’s quite perplexing as this issue seems isolated to this specific function. I’ve tried various debugging techniques, such as inspecting the event listeners and checking for any conflicts within the codebase, but haven’t been able to pinpoint the root cause yet. I suspect it might be related to some nuances in the implementation or perhaps an unforeseen interaction with other elements on the interface. Further investigation is definitely warranted to resolve this issue, as the backButton is a crucial component of the game’s user interface and its malfunction could significantly impact the overall gameplay experience.
/// Code that the button doesnt work in
private void gameInterface() {
boolean inFight = true;
root.getChildren().clear(); // Clear previous content
VBox enemyBox = new VBox(20);
enemyBox.setPadding(new Insets(20));
Label textLabel = new Label("Fight a footballer");
textLabel.setStyle("-fx-font-size: 60px;");
textLabel.setTranslateY(-250);
Label playerInfo = new Label(footballPlayer.readFromFile().toString());
playerInfo.setStyle("-fx-font-size: 16px;");
StackPane.setAlignment(playerInfo, javafx.geometry.Pos.BOTTOM_LEFT);
playerInfo.setTranslateX(20);
playerInfo.setTranslateY(-20);
enemyFootballer opp = new enemyFootballer();
Button backButton = new Button("Back");
backButton.setStyle("-fx-font-size: 24px; -fx-min-width: 200px; -fx-min-height: 50px;");
backButton.setOnAction(e -> openMenu());
StackPane.setAlignment(backButton, javafx.geometry.Pos.BOTTOM_RIGHT);
backButton.setMouseTransparent(false);
root.getChildren().addAll(textLabel, backButton, playerInfo, enemyBox);
}
Tried setting mouse transparent to false, didnt work.
user24862373 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.