Java Code Examples for javafx.scene.layout.HBox#setTranslateX()

The following examples show how to use javafx.scene.layout.HBox#setTranslateX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FroggerApp.java    From FXTutorials with MIT License 5 votes vote down vote up
private void checkState() {
    for (Node car : cars) {
        if (car.getBoundsInParent().intersects(frog.getBoundsInParent())) {
            frog.setTranslateX(0);
            frog.setTranslateY(600 - 39);
            return;
        }
    }

    if (frog.getTranslateY() <= 0) {
        timer.stop();
        String win = "YOU WIN";

        HBox hBox = new HBox();
        hBox.setTranslateX(300);
        hBox.setTranslateY(250);
        root.getChildren().add(hBox);

        for (int i = 0; i < win.toCharArray().length; i++) {
            char letter = win.charAt(i);

            Text text = new Text(String.valueOf(letter));
            text.setFont(Font.font(48));
            text.setOpacity(0);

            hBox.getChildren().add(text);

            FadeTransition ft = new FadeTransition(Duration.seconds(0.66), text);
            ft.setToValue(1);
            ft.setDelay(Duration.seconds(i * 0.15));
            ft.play();
        }
    }
}
 
Example 2
Source File: MKXMenuApp.java    From FXTutorials with MIT License 4 votes vote down vote up
private Parent createContent() {
    Pane root = new Pane();
    root.setPrefSize(900, 600);

    Rectangle bg = new Rectangle(900, 600);

    ContentFrame frame1 = new ContentFrame(createLeftContent());
    ContentFrame frame2 = new ContentFrame(createMiddleContent());
    ContentFrame frame3 = new ContentFrame(createRightContent());

    HBox hbox = new HBox(15, frame1, frame2, frame3);
    hbox.setTranslateX(120);
    hbox.setTranslateY(50);

    MenuItem itemExit = new MenuItem("EXIT");
    itemExit.setOnActivate(() -> System.exit(0));

    menuBox = new VBox(10,
            new MenuItem("ONE PLAYER"),
            new MenuItem("TWO PLAYER"),
            new MenuItem("ONLINE"),
            new MenuItem("FACTION"),
            new MenuItem("KRYPT"),
            new MenuItem("OPTIONS"),
            new MenuItem("EXTRAS*"),
            itemExit);
    menuBox.setAlignment(Pos.TOP_CENTER);
    menuBox.setTranslateX(360);
    menuBox.setTranslateY(300);

    Text about = new Text("MKXMenuApp\n\tby\n    AlmasB");
    about.setTranslateX(50);
    about.setTranslateY(500);
    about.setFill(Color.WHITE);
    about.setFont(FONT);
    about.setOpacity(0.2);

    getMenuItem(0).setActive(true);

    root.getChildren().addAll(bg, hbox, menuBox, about);
    return root;
}