2

I am working on educational klondike game project with JavaFX. What I am trying to do is to create dynamic scaling of whole game.

I used scale class to do so. It seems almost good, as it change the scale of all interface elements, apart of the background, which is a bit smaller then the actual window.

I already tried to manipulate with BackgroundSize, but it doesn't make any change. How can I fix it?

Thanks a lot for Your help!

I add pictures to show the problem:

enter image description here enter image description here

public class Klondike extends Application {

private static final double WINDOW_WIDTH = 1400;
private static final double WINDOW_HEIGHT = 900;
Button changeThemeButton;
Button newGame;
Button undo;

public static void main(String[] args) {
    launch(args);
}

@Override
public void start(Stage primaryStage) {
    startGame(primaryStage);
}

public void startGame(Stage primaryStage){
    Card.loadCardImages();
    Game game = new Game();
    game.setTableBackground(new Image(Common.loadThemeSettings().get(0)));

    initializeButtons(game, primaryStage);

    primaryStage.setTitle("Klondike Solitaire");
    primaryStage.setScene(new Scene(game, WINDOW_WIDTH, WINDOW_HEIGHT));

    // SCALLING:

    Scale scale = new Scale(1, 1);
    scale.xProperty().bind(game.widthProperty().divide(WINDOW_WIDTH));
    scale.yProperty().bind(game.heightProperty().divide(WINDOW_HEIGHT));
    game.getTransforms().add(scale);
    primaryStage.setResizable(true);

    // SCALLING END:
    primaryStage.show();
}

BACKGROUND PICTURE:

    public void setTableBackground(Image tableBackground) {
    setBackground(new Background(new BackgroundImage(tableBackground,
            BackgroundRepeat.REPEAT, BackgroundRepeat.REPEAT,
            BackgroundPosition.CENTER, BackgroundSize.DEFAULT)));
}
  • 1
    Applying a scale transform does not modify the size of the node it's applied to. Only the rendered size is modified. Since the original size only includes the green parts, you get a empty border. The simplest solution would probably be wrapping the content in a `Pane` and resizing the node that contains the background when the scale changed. (Set `managed` to `false` for that node to prevent it's parent from resizing it to a smaller size.) – fabian Apr 04 '18 at 17:28
  • Maybe look at this question: [JavaFX fullscreen - resizing elements based upon screen size](https://stackoverflow.com/questions/16606162/javafx-fullscreen-resizing-elements-based-upon-screen-size). Perhaps this question is a duplicate of that. – jewelsea Apr 04 '18 at 19:40

0 Answers0