I tried to make the background size as the window size. but, It's quite picky. I didn't use the css file format.
it's the part of main to implement the window.
public void start(Stage primaryStage) throws Exception {
GameLoopManager loop = GameLoopManager.instance();
Controller controller = new Controller(loop, primaryStage);
loop.start(new MenuState());
primaryStage.show();
primaryStage.setFullScreen(true);
}
and this is the parts of body to implement the background and stage.
private UISubScene optionSubScene;
private UISubScene helpSubScene;
private UISubScene creditsSubScene;
private UISubScene buttonChooserScene;
private UISubScene sceneToHide;
List<UIButton> menuButtons;
List<ButtonPicker> buttonsList;
private BUTTON chosenButton;
public MenuViewManager(Stage mainStage) {
sound.backgroundMusic();
menuButtons = new ArrayList<>();
mainPane = new AnchorPane();
mainScene = new Scene(mainPane);
mainScene.setFill(null);
mainStage.setScene(mainScene);
super.mainStage = mainStage;
createSubScenes();
createButtons();
createBackground();
createLogo();
super.mainStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
public void handle(WindowEvent we) {
controller.stop();
}
});
// mainStage.show();
}
private void createBackground() {
Image backgroundImgae = new Image("main/resources/images/jxoPOUxa.gif",true);
BackgroundImage background = new BackgroundImage(backgroundImgae, BackgroundRepeat.NO_REPEAT,
BackgroundRepeat.NO_REPEAT, BackgroundPosition.DEFAULT, BackgroundSize.DEFAULT);
mainPane.setBackground(new Background(background));
}
I tired to use BackgroundSize.AUTO but, I can't. what should I do to get the solution?
If, I can use the css format how to use that? but I can't rewrite and revise lots of codes because, mine is almost done and I'm integrating and debugging.
If you want to stretch the image to fill the entire
Region
you should use:The two
true
arguments ofBackgroundSize
mean thewidth
andheight
arguments, respectively, are proportional rather than absolute. When that's the case thewidth
andheight
should be in the range[0.0, 1.0]
, otherwise known as 0% to 100%. The twofalse
arguments arecontain
andcover
, respectively. They must befalse
for thewidth
andheight
arguments to be used. In other words, that's telling JavaFX to make the image fill 100% of both the width and height of theRegion
. Note this will not maintain the aspect ratio of the image (see below).See the documentation of
BackgroundSize
for more information: