Java Code Examples for javafx.scene.text.Text#setTranslateX()

The following examples show how to use javafx.scene.text.Text#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: KeyStrokeMotion.java    From marathonv5 with Apache License 2.0 7 votes vote down vote up
private void createLetter(String c) {
    final Text letter = new Text(c);
    letter.setFill(Color.BLACK);
    letter.setFont(FONT_DEFAULT);
    letter.setTextOrigin(VPos.TOP);
    letter.setTranslateX((getWidth() - letter.getBoundsInLocal().getWidth()) / 2);
    letter.setTranslateY((getHeight() - letter.getBoundsInLocal().getHeight()) / 2);
    getChildren().add(letter);
    // over 3 seconds move letter to random position and fade it out
    final Timeline timeline = new Timeline();
    timeline.getKeyFrames().add(
            new KeyFrame(Duration.seconds(3), new EventHandler<ActionEvent>() {
                @Override public void handle(ActionEvent event) {
                    // we are done remove us from scene
                    getChildren().remove(letter);
                }
            },
            new KeyValue(letter.translateXProperty(), getRandom(0.0f, getWidth() - letter.getBoundsInLocal().getWidth()),INTERPOLATOR),
            new KeyValue(letter.translateYProperty(), getRandom(0.0f, getHeight() - letter.getBoundsInLocal().getHeight()),INTERPOLATOR),
            new KeyValue(letter.opacityProperty(), 0f)
    ));
    timeline.play();
}
 
Example 2
Source File: KeyStrokeMotion.java    From netbeans with Apache License 2.0 7 votes vote down vote up
private void createLetter(String c) {
    final Text letter = new Text(c);
    letter.setFill(Color.BLACK);
    letter.setFont(FONT_DEFAULT);
    letter.setTextOrigin(VPos.TOP);
    letter.setTranslateX((getWidth() - letter.getBoundsInLocal().getWidth()) / 2);
    letter.setTranslateY((getHeight() - letter.getBoundsInLocal().getHeight()) / 2);
    getChildren().add(letter);
    // over 3 seconds move letter to random position and fade it out
    final Timeline timeline = new Timeline();
    timeline.getKeyFrames().add(
            new KeyFrame(Duration.seconds(3), new EventHandler<ActionEvent>() {
                @Override public void handle(ActionEvent event) {
                    // we are done remove us from scene
                    getChildren().remove(letter);
                }
            },
            new KeyValue(letter.translateXProperty(), getRandom(0.0f, getWidth() - letter.getBoundsInLocal().getWidth()),INTERPOLATOR),
            new KeyValue(letter.translateYProperty(), getRandom(0.0f, getHeight() - letter.getBoundsInLocal().getHeight()),INTERPOLATOR),
            new KeyValue(letter.opacityProperty(), 0f)
    ));
    timeline.play();
}
 
Example 3
Source File: TowerDefenseApp.java    From FXGLGames with MIT License 6 votes vote down vote up
private void onEnemyKilled(EnemyKilledEvent event) {
    levelEnemies--;

    if (levelEnemies == 0) {
        gameOver();
    }

    Entity enemy = event.getEnemy();
    Point2D position = enemy.getPosition();

    Text xMark = getUIFactory().newText("X", Color.RED, 24);
    xMark.setTranslateX(position.getX());
    xMark.setTranslateY(position.getY() + 20);

    getGameScene().addGameView(new GameView(xMark, 1000));
}
 
Example 4
Source File: IOSApp.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
private Parent createContent() {
    Pane root = new Pane();
    root.setPrefSize(300, 300);

    Rectangle bg = new Rectangle(300, 300);

    ToggleSwitch toggle = new ToggleSwitch();
    toggle.setTranslateX(100);
    toggle.setTranslateY(100);

    Text text = new Text();
    text.setFont(Font.font(18));
    text.setFill(Color.WHITE);
    text.setTranslateX(100);
    text.setTranslateY(200);
    text.textProperty().bind(Bindings.when(toggle.switchedOnProperty()).then("ON").otherwise("OFF"));

    root.getChildren().addAll(toggle, text);
    return root;
}
 
Example 5
Source File: IOSApp.java    From FXTutorials with MIT License 6 votes vote down vote up
private Parent createContent() {
    Pane root = new Pane();
    root.setPrefSize(300, 300);

    Rectangle bg = new Rectangle(300, 300);

    ToggleSwitch toggle = new ToggleSwitch();
    toggle.setTranslateX(100);
    toggle.setTranslateY(100);

    Text text = new Text();
    text.setFont(Font.font(18));
    text.setFill(Color.WHITE);
    text.setTranslateX(100);
    text.setTranslateY(200);
    text.textProperty().bind(Bindings.when(toggle.switchedOnProperty()).then("ON").otherwise("OFF"));

    root.getChildren().addAll(toggle, text);
    return root;
}
 
Example 6
Source File: TowerDefenseApp.java    From FXGLGames with MIT License 6 votes vote down vote up
private void onEnemyKilled(EnemyKilledEvent event) {
    levelEnemies--;

    if (levelEnemies == 0) {
        gameOver();
    }

    Entity enemy = event.getEnemy();
    Point2D position = enemy.getPosition();

    Text xMark = getUIFactory().newText("X", Color.RED, 24);
    xMark.setTranslateX(position.getX());
    xMark.setTranslateY(position.getY() + 20);

    getGameScene().addGameView(new GameView(xMark, 1000));
}
 
Example 7
Source File: BejeweledApp.java    From FXTutorials with MIT License 6 votes vote down vote up
private Parent createContent() {
    Pane root = new Pane();
    root.setPrefSize(W * SIZE + 150, H * SIZE);

    jewels = IntStream.range(0, W * H)
            .mapToObj(i -> new Point2D(i % W, i / W))
            .map(Jewel::new)
            .collect(Collectors.toList());

    root.getChildren().addAll(jewels);

    Text textScore = new Text();
    textScore.setTranslateX(W * SIZE);
    textScore.setTranslateY(100);
    textScore.setFont(Font.font(68));
    textScore.textProperty().bind(score.asString("Score: [%d]"));

    root.getChildren().add(textScore);
    return root;
}
 
Example 8
Source File: GeoWarsApp.java    From FXGLGames with MIT License 5 votes vote down vote up
@Override
protected void initUI() {
    Text scoreText = getUIFactoryService().newText("", Color.WHITE, 28);
    scoreText.setTranslateX(60);
    scoreText.setTranslateY(70);
    scoreText.textProperty().bind(getip("score").asString());
    scoreText.setStroke(Color.GOLD);

    Text multText = getUIFactoryService().newText("", Color.WHITE, 28);
    multText.setTranslateX(60);
    multText.setTranslateY(90);
    multText.textProperty().bind(getip("multiplier").asString("x %d"));

    var livesText = getUIFactoryService().newText("", Color.WHITE, 24.0);
    livesText.setTranslateX(60);
    livesText.setTranslateY(110);
    livesText.textProperty().bind(getip("lives").asString("Lives: %d"));

    getGameScene().addUINodes(multText, scoreText, livesText);

    Text beware = getUIFactoryService().newText("Beware! Seekers get smarter every spawn!", Color.AQUA, 38);

    addUINode(beware);

    centerText(beware);

    animationBuilder()
            .duration(Duration.seconds(2))
            .autoReverse(true)
            .repeat(2)
            .fadeIn(beware)
            .buildAndPlay();
}
 
Example 9
Source File: Fx3DStageController.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
private void setRtAxis() {
    axes.getRtAxis().getChildren().clear();
    double rtDelta = (rtRange.upperEndpoint() - rtRange.lowerEndpoint())
            / 7;
    double rtScaleValue = rtRange.upperEndpoint();
    Text rtLabel = new Text("Retention Time");
    rtLabel.setRotationAxis(Rotate.X_AXIS);
    rtLabel.setRotate(-45);
    rtLabel.setTranslateX(SIZE * 3 / 8);
    rtLabel.setTranslateZ(-25);
    rtLabel.setTranslateY(13);
    axes.getRtAxis().getChildren().add(rtLabel);
    for (int y = 0; y <= SIZE; y += SIZE / 7) {
        Line tickLineX = new Line(0, 0, 0, 9);
        tickLineX.setRotationAxis(Rotate.X_AXIS);
        tickLineX.setRotate(-90);
        tickLineX.setTranslateY(-5);
        tickLineX.setTranslateX(y);
        tickLineX.setTranslateZ(-3.5);
        float roundOff = (float) (Math.round(rtScaleValue * 10.0) / 10.0);
        Text text = new Text("" + (float) roundOff);
        text.setRotationAxis(Rotate.X_AXIS);
        text.setRotate(-45);
        text.setTranslateY(9);
        text.setTranslateX(y - 5);
        text.setTranslateZ(-15);
        rtScaleValue -= rtDelta;
        axes.getRtAxis().getChildren().addAll(text, tickLineX);
    }
    Line lineX = new Line(0, 0, SIZE, 0);
    axes.getRtAxis().getChildren().add(lineX);
    axes.getRtRotate().setAngle(180);
    axes.getRtTranslate().setZ(-SIZE);
    axes.getRtTranslate().setX(-SIZE);
}
 
Example 10
Source File: MenuItem.java    From FXTutorials with MIT License 5 votes vote down vote up
public MenuItem(String name, int width) {
    setAlignment(Pos.CENTER_LEFT);

    text = new Text(name);
    text.setTranslateX(5);
    text.setFont(font);
    text.setFill(Colors.MENU_TEXT);
    text.setStroke(Color.BLACK);

    shadow = new DropShadow(5, Color.BLACK);
    text.setEffect(shadow);

    selection = new Rectangle(width - 45, 30);
    selection.setFill(Colors.MENU_ITEM_SELECTION);
    selection.setStroke(Color.BLACK);
    selection.setVisible(false);

    GaussianBlur blur = new GaussianBlur(8);
    selection.setEffect(blur);

    getChildren().addAll(selection, text);

    setOnMouseEntered(e -> {
        onSelect();
    });

    setOnMouseExited(e -> {
        onDeselect();
    });

    setOnMousePressed(e -> {
        text.setFill(Color.YELLOW);
    });
}
 
Example 11
Source File: Main.java    From FXTutorials with MIT License 5 votes vote down vote up
private Parent createContent() {
    Pane root = new Pane();
    root.setPrefSize(800, 600);

    Dice dice1 = new Dice();
    Dice dice2 = new Dice();

    dice1.setTranslateX(100);
    dice1.setTranslateY(200);

    dice2.setTranslateX(300);
    dice2.setTranslateY(200);

    Button btn = new Button("New target");
    btn.setOnAction(event -> {
        target.set((int)(Math.random() * (Dice.MAX_VALUE * 2 + 1)));
    });

    btn.setTranslateX(400);
    btn.setTranslateY(200);

    SimpleBooleanProperty bool = new SimpleBooleanProperty();
    bool.bind(target.isEqualTo(dice1.valueProperty.add(dice2.valueProperty)));

    Text message = new Text();
    message.textProperty().bind(target.asString().concat(bool.asString()));

    message.setTranslateX(500);
    message.setTranslateY(200);

    root.getChildren().addAll(dice1, dice2, btn, message);
    return root;
}
 
Example 12
Source File: MenuItem.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public MenuItem(String name, int width) {
    	int n = name.length();
//        Polygon bg = new Polygon(
//                0, 0,
//                220, 0,
//                245, 25,
//                220, 50,
//                0, 50
//        );
        Polygon bg = new Polygon(
                0, 0,
                width - 20 , 0,
                width, 25,
                width - 20, 50,
                0, 50
        );

        bg.setStroke(Color.color(1, 1, 1, 0.1));//75));
        //bg.setEffect(new GaussianBlur());
        bg.fillProperty().bind(
                Bindings.when(pressedProperty())
                        .then(Color.color(1, 1, 1, 0.35))//Color.color(139D/255D, 69D/255D, 19D/255D, 0.35))
                        .otherwise(Color.color(1, 1, 1, 0.15))
        );

        text = new Text(name);
        text.setTranslateX((18 - n) * 6.5);
        text.setTranslateY(34);
        text.setFont(Font.loadFont(MenuApp.class.getResource("/fonts/Penumbra-HalfSerif-Std_35114.ttf").toExternalForm(), 22));
        text.setFill(Color.LIGHTGOLDENRODYELLOW);//.CORAL);//.WHITE);
        text.effectProperty().bind(
                Bindings.when(hoverProperty())
                        .then(shadow)
                        .otherwise(blur)
        );

        getChildren().addAll(bg, text);
    }
 
Example 13
Source File: Fx3DStageController.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
private void setMzAxis() {
  axes.getMzAxisLabels().getChildren().clear();
  axes.getMzAxisTicks().getChildren().clear();
  double mzDelta = (mzRange.upperEndpoint() - mzRange.lowerEndpoint()) / 7;
  double mzScaleValue = mzRange.lowerEndpoint();
  Text mzLabel = new Text("m/z");
  mzLabel.setRotationAxis(Rotate.X_AXIS);
  mzLabel.setRotate(-45);
  mzLabel.setTranslateX(SIZE / 2);
  mzLabel.setTranslateZ(-5);
  mzLabel.setTranslateY(8);
  axes.getMzAxisLabels().getChildren().add(mzLabel);
  for (int y = 0; y <= SIZE; y += SIZE / 7) {
    Line tickLineZ = new Line(0, 0, 0, 9);
    tickLineZ.setRotationAxis(Rotate.X_AXIS);
    tickLineZ.setRotate(-90);
    tickLineZ.setTranslateY(-4);
    tickLineZ.setTranslateX(y - 2);
    float roundOff = (float) (Math.round(mzScaleValue * 100.0) / 100.0);
    Text text = new Text("" + roundOff);
    text.setRotationAxis(Rotate.X_AXIS);
    text.setRotate(-45);
    text.setTranslateY(8);
    text.setTranslateX(y - 10);
    text.setTranslateZ(20);
    mzScaleValue += mzDelta;
    axes.getMzAxisTicks().getChildren().add(tickLineZ);
    axes.getMzAxisLabels().getChildren().add(text);
  }
  axes.getMzAxisLabels().setRotate(270);
  axes.getMzAxisLabels().setTranslateX(SIZE / 2 + SIZE / 30);
  axes.getMzAxisTicks().setTranslateX(SIZE / 2 + 10);
  axes.getMzAxisTicks().setTranslateY(-1);
  axes.getMzAxis().setTranslateX(SIZE);
}
 
Example 14
Source File: Civ6MenuItem.java    From FXTutorials with MIT License 5 votes vote down vote up
public Civ6MenuItem(String name) {
    Polygon bg = new Polygon(
            0, 0,
            200, 0,
            215, 15,
            200, 30,
            0, 30
    );
    bg.setStroke(Color.color(1, 1, 1, 0.75));
    bg.setEffect(new GaussianBlur());

    bg.fillProperty().bind(
            Bindings.when(pressedProperty())
                    .then(Color.color(0, 0, 0, 0.75))
                    .otherwise(Color.color(0, 0, 0, 0.25))
    );

    text = new Text(name);
    text.setTranslateX(5);
    text.setTranslateY(20);
    text.setFont(Font.loadFont(Civ6MenuApp.class.getResource("res/Penumbra-HalfSerif-Std_35114.ttf").toExternalForm(), 14));
    text.setFill(Color.WHITE);

    text.effectProperty().bind(
            Bindings.when(hoverProperty())
                    .then(shadow)
                    .otherwise(blur)
    );

    getChildren().addAll(bg, text);
}
 
Example 15
Source File: Fx3DStageController.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
private void setRtAxis() {
  axes.getRtAxis().getChildren().clear();
  double rtDelta = (rtRange.upperEndpoint() - rtRange.lowerEndpoint()) / 7;
  double rtScaleValue = rtRange.upperEndpoint();
  Text rtLabel = new Text("Retention Time");
  rtLabel.setRotationAxis(Rotate.X_AXIS);
  rtLabel.setRotate(-45);
  rtLabel.setTranslateX(SIZE * 3 / 8);
  rtLabel.setTranslateZ(-25);
  rtLabel.setTranslateY(13);
  axes.getRtAxis().getChildren().add(rtLabel);
  for (int y = 0; y <= SIZE; y += SIZE / 7) {
    Line tickLineX = new Line(0, 0, 0, 9);
    tickLineX.setRotationAxis(Rotate.X_AXIS);
    tickLineX.setRotate(-90);
    tickLineX.setTranslateY(-5);
    tickLineX.setTranslateX(y);
    tickLineX.setTranslateZ(-3.5);
    float roundOff = (float) (Math.round(rtScaleValue * 10.0) / 10.0);
    Text text = new Text("" + roundOff);
    text.setRotationAxis(Rotate.X_AXIS);
    text.setRotate(-45);
    text.setTranslateY(9);
    text.setTranslateX(y - 5);
    text.setTranslateZ(-15);
    rtScaleValue -= rtDelta;
    axes.getRtAxis().getChildren().addAll(text, tickLineX);
  }
  Line lineX = new Line(0, 0, SIZE, 0);
  axes.getRtAxis().getChildren().add(lineX);
  axes.getRtRotate().setAngle(180);
  axes.getRtTranslate().setZ(-SIZE);
  axes.getRtTranslate().setX(-SIZE);
}
 
Example 16
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;
}
 
Example 17
Source File: TodaysDateWiget.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public Group getToDayControl(){
    String[] months = {"Jan", "Feb","Mar", "Apr", "May",          "Jun", "Jul","Aug", "Sep", "Oct", "Nov","Dec"};
    Calendar cal =  Calendar.getInstance();
 
    Group ctrl = new Group();
    Rectangle rect = new Rectangle();
    rect.setWidth(WIDTH);
    rect.setHeight(HEIGHT);
    rect.setArcHeight(10.0);
    rect.setArcWidth(10.0);
 
    Rectangle headerRect = new Rectangle();
    headerRect.setWidth(WIDTH);
    headerRect.setHeight(30);
    headerRect.setArcHeight(10.0);
    headerRect.setArcWidth(10.0);
 
    Stop[] stops = new Stop[] { new Stop(0, Color.color(0.31, 0.31, 0.31, 0.443)), new Stop(1,  Color.color(0, 0, 0, 0.737))};
    LinearGradient lg = new LinearGradient( 0.482, -0.017, 0.518, 1.017, true, CycleMethod.REFLECT, stops);
    headerRect.setFill(lg);
 
    Rectangle footerRect = new Rectangle();
    footerRect.setY(headerRect.getBoundsInLocal().getHeight() -4);
    footerRect.setWidth(WIDTH);
    footerRect.setHeight(125);
    footerRect.setFill(Color.color(0.51,  0.671,  0.992));
 
    final Text currentMon = new Text(months[(cal.get(Calendar.MONTH) )]);
    currentMon.setFont(Font.font("null", FontWeight.BOLD, 24));
    currentMon.setTranslateX((footerRect.getBoundsInLocal().getWidth() - currentMon.getBoundsInLocal().getWidth())/2.0);
    currentMon.setTranslateY(23);
    currentMon.setFill(Color.WHITE);
 
    final Text currentDate = new          Text(Integer.toString(cal.get(Calendar.DATE)));
    currentDate.setFont(new Font(100.0));
    currentDate.setTranslateX((footerRect.getBoundsInLocal().getWidth() - currentDate.getBoundsInLocal().getWidth())/2.0);
    currentDate.setTranslateY(120);
    currentDate.setFill(Color.WHITE);
 
    ctrl.getChildren().addAll(rect, headerRect, footerRect , currentMon,currentDate);
 
    DropShadow ds = new DropShadow();
    ds.setOffsetY(3.0);
    ds.setOffsetX(3.0);
    ds.setColor(Color.GRAY);
    ctrl.setEffect(ds);
 
    return ctrl;
}
 
Example 18
Source File: Level.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void initInfoPanel() {
    infoPanel = new Group();
    roundCaption = new Text();
    roundCaption.setText("ROUND");
    roundCaption.setTextOrigin(VPos.TOP);
    roundCaption.setFill(Color.rgb(51, 102, 51));
    Font f = new Font("Impact", 18);
    roundCaption.setFont(f);
    roundCaption.setTranslateX(30);
    roundCaption.setTranslateY(128);
    round = new Text();
    round.setTranslateX(roundCaption.getTranslateX() +
        roundCaption.getBoundsInLocal().getWidth() + Config.INFO_TEXT_SPACE);
    round.setTranslateY(roundCaption.getTranslateY());
    round.setText(levelNumber + "");
    round.setTextOrigin(VPos.TOP);
    round.setFont(f);
    round.setFill(Color.rgb(0, 204, 102));
    scoreCaption = new Text();
    scoreCaption.setText("SCORE");
    scoreCaption.setFill(Color.rgb(51, 102, 51));
    scoreCaption.setTranslateX(30);
    scoreCaption.setTranslateY(164);
    scoreCaption.setTextOrigin(VPos.TOP);
    scoreCaption.setFont(f);
    score = new Text();
    score.setTranslateX(scoreCaption.getTranslateX() +
        scoreCaption.getBoundsInLocal().getWidth() + Config.INFO_TEXT_SPACE);
    score.setTranslateY(scoreCaption.getTranslateY());
    score.setFill(Color.rgb(0, 204, 102));
    score.setTextOrigin(VPos.TOP);
    score.setFont(f);
    score.setText("");
    livesCaption = new Text();
    livesCaption.setText("LIFE");
    livesCaption.setTranslateX(30);
    livesCaption.setTranslateY(200);
    livesCaption.setFill(Color.rgb(51, 102, 51));
    livesCaption.setTextOrigin(VPos.TOP);
    livesCaption.setFont(f);
    Color INFO_LEGEND_COLOR = Color.rgb(0, 114, 188);
    int infoWidth = Config.SCREEN_WIDTH - Config.FIELD_WIDTH;
    Rectangle black = new Rectangle();
    black.setWidth(infoWidth);
    black.setHeight(Config.SCREEN_HEIGHT);
    black.setFill(Color.BLACK);
    ImageView verLine = new ImageView();
    verLine.setImage(new Image(Level.class.getResourceAsStream(Config.IMAGE_DIR+"vline.png")));
    verLine.setTranslateX(3);
    ImageView logo = new ImageView();
    logo.setImage(Config.getImages().get(Config.IMAGE_LOGO));
    logo.setTranslateX(30);
    logo.setTranslateY(30);
    Text legend = new Text();
    legend.setTranslateX(30);
    legend.setTranslateY(310);
    legend.setText("LEGEND");
    legend.setFill(INFO_LEGEND_COLOR);
    legend.setTextOrigin(VPos.TOP);
    legend.setFont(new Font("Impact", 18));
    infoPanel.getChildren().addAll(black, verLine, logo, roundCaption,
            round, scoreCaption, score, livesCaption, legend);
    for (int i = 0; i < Bonus.COUNT; i++) {
        Bonus bonus = new Bonus(i);
        Text text = new Text();
        text.setTranslateX(100);
        text.setTranslateY(350 + i * 40);
        text.setText(Bonus.NAMES[i]);
        text.setFill(INFO_LEGEND_COLOR);
        text.setTextOrigin(VPos.TOP);
        text.setFont(new Font("Arial", 12));
        bonus.setTranslateX(30 + (820 - 750 - bonus.getWidth()) / 2);
        bonus.setTranslateY(text.getTranslateY() -
            (bonus.getHeight() - text.getBoundsInLocal().getHeight()) / 2);
        // Workaround JFXC-2379
        infoPanel.getChildren().addAll(bonus, text);
    }
    infoPanel.setTranslateX(Config.FIELD_WIDTH);
}
 
Example 19
Source File: Level.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private void initInfoPanel() {
    infoPanel = new Group();
    roundCaption = new Text();
    roundCaption.setText("ROUND");
    roundCaption.setTextOrigin(VPos.TOP);
    roundCaption.setFill(Color.rgb(51, 102, 51));
    Font f = new Font("Impact", 18);
    roundCaption.setFont(f);
    roundCaption.setTranslateX(30);
    roundCaption.setTranslateY(128);
    round = new Text();
    round.setTranslateX(roundCaption.getTranslateX() +
        roundCaption.getBoundsInLocal().getWidth() + Config.INFO_TEXT_SPACE);
    round.setTranslateY(roundCaption.getTranslateY());
    round.setText(levelNumber + "");
    round.setTextOrigin(VPos.TOP);
    round.setFont(f);
    round.setFill(Color.rgb(0, 204, 102));
    scoreCaption = new Text();
    scoreCaption.setText("SCORE");
    scoreCaption.setFill(Color.rgb(51, 102, 51));
    scoreCaption.setTranslateX(30);
    scoreCaption.setTranslateY(164);
    scoreCaption.setTextOrigin(VPos.TOP);
    scoreCaption.setFont(f);
    score = new Text();
    score.setTranslateX(scoreCaption.getTranslateX() +
        scoreCaption.getBoundsInLocal().getWidth() + Config.INFO_TEXT_SPACE);
    score.setTranslateY(scoreCaption.getTranslateY());
    score.setFill(Color.rgb(0, 204, 102));
    score.setTextOrigin(VPos.TOP);
    score.setFont(f);
    score.setText("");
    livesCaption = new Text();
    livesCaption.setText("LIFE");
    livesCaption.setTranslateX(30);
    livesCaption.setTranslateY(200);
    livesCaption.setFill(Color.rgb(51, 102, 51));
    livesCaption.setTextOrigin(VPos.TOP);
    livesCaption.setFont(f);
    Color INFO_LEGEND_COLOR = Color.rgb(0, 114, 188);
    int infoWidth = Config.SCREEN_WIDTH - Config.FIELD_WIDTH;
    Rectangle black = new Rectangle();
    black.setWidth(infoWidth);
    black.setHeight(Config.SCREEN_HEIGHT);
    black.setFill(Color.BLACK);
    ImageView verLine = new ImageView();
    verLine.setImage(new Image(Level.class.getResourceAsStream(Config.IMAGE_DIR+"vline.png")));
    verLine.setTranslateX(3);
    ImageView logo = new ImageView();
    logo.setImage(Config.getImages().get(Config.IMAGE_LOGO));
    logo.setTranslateX(30);
    logo.setTranslateY(30);
    Text legend = new Text();
    legend.setTranslateX(30);
    legend.setTranslateY(310);
    legend.setText("LEGEND");
    legend.setFill(INFO_LEGEND_COLOR);
    legend.setTextOrigin(VPos.TOP);
    legend.setFont(new Font("Impact", 18));
    infoPanel.getChildren().addAll(black, verLine, logo, roundCaption,
            round, scoreCaption, score, livesCaption, legend);
    for (int i = 0; i < Bonus.COUNT; i++) {
        Bonus bonus = new Bonus(i);
        Text text = new Text();
        text.setTranslateX(100);
        text.setTranslateY(350 + i * 40);
        text.setText(Bonus.NAMES[i]);
        text.setFill(INFO_LEGEND_COLOR);
        text.setTextOrigin(VPos.TOP);
        text.setFont(new Font("Arial", 12));
        bonus.setTranslateX(30 + (820 - 750 - bonus.getWidth()) / 2);
        bonus.setTranslateY(text.getTranslateY() -
            (bonus.getHeight() - text.getBoundsInLocal().getHeight()) / 2);
        // Workaround JFXC-2379
        infoPanel.getChildren().addAll(bonus, text);
    }
    infoPanel.setTranslateX(Config.FIELD_WIDTH);
}
 
Example 20
Source File: Level.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private void initInfoPanel() {
    infoPanel = new Group();
    roundCaption = new Text();
    roundCaption.setText("ROUND");
    roundCaption.setTextOrigin(VPos.TOP);
    roundCaption.setFill(Color.rgb(51, 102, 51));
    Font f = new Font("Impact", 18);
    roundCaption.setFont(f);
    roundCaption.setTranslateX(30);
    roundCaption.setTranslateY(128);
    round = new Text();
    round.setTranslateX(roundCaption.getTranslateX() +
        roundCaption.getBoundsInLocal().getWidth() + Config.INFO_TEXT_SPACE);
    round.setTranslateY(roundCaption.getTranslateY());
    round.setText(levelNumber + "");
    round.setTextOrigin(VPos.TOP);
    round.setFont(f);
    round.setFill(Color.rgb(0, 204, 102));
    scoreCaption = new Text();
    scoreCaption.setText("SCORE");
    scoreCaption.setFill(Color.rgb(51, 102, 51));
    scoreCaption.setTranslateX(30);
    scoreCaption.setTranslateY(164);
    scoreCaption.setTextOrigin(VPos.TOP);
    scoreCaption.setFont(f);
    score = new Text();
    score.setTranslateX(scoreCaption.getTranslateX() +
        scoreCaption.getBoundsInLocal().getWidth() + Config.INFO_TEXT_SPACE);
    score.setTranslateY(scoreCaption.getTranslateY());
    score.setFill(Color.rgb(0, 204, 102));
    score.setTextOrigin(VPos.TOP);
    score.setFont(f);
    score.setText("");
    livesCaption = new Text();
    livesCaption.setText("LIFE");
    livesCaption.setTranslateX(30);
    livesCaption.setTranslateY(200);
    livesCaption.setFill(Color.rgb(51, 102, 51));
    livesCaption.setTextOrigin(VPos.TOP);
    livesCaption.setFont(f);
    Color INFO_LEGEND_COLOR = Color.rgb(0, 114, 188);
    int infoWidth = Config.SCREEN_WIDTH - Config.FIELD_WIDTH;
    Rectangle black = new Rectangle();
    black.setWidth(infoWidth);
    black.setHeight(Config.SCREEN_HEIGHT);
    black.setFill(Color.BLACK);
    ImageView verLine = new ImageView();
    verLine.setImage(new Image(Level.class.getResourceAsStream(Config.IMAGE_DIR+"vline.png")));
    verLine.setTranslateX(3);
    ImageView logo = new ImageView();
    logo.setImage(Config.getImages().get(Config.IMAGE_LOGO));
    logo.setTranslateX(30);
    logo.setTranslateY(30);
    Text legend = new Text();
    legend.setTranslateX(30);
    legend.setTranslateY(310);
    legend.setText("LEGEND");
    legend.setFill(INFO_LEGEND_COLOR);
    legend.setTextOrigin(VPos.TOP);
    legend.setFont(new Font("Impact", 18));
    infoPanel.getChildren().addAll(black, verLine, logo, roundCaption,
            round, scoreCaption, score, livesCaption, legend);
    for (int i = 0; i < Bonus.COUNT; i++) {
        Bonus bonus = new Bonus(i);
        Text text = new Text();
        text.setTranslateX(100);
        text.setTranslateY(350 + i * 40);
        text.setText(Bonus.NAMES[i]);
        text.setFill(INFO_LEGEND_COLOR);
        text.setTextOrigin(VPos.TOP);
        text.setFont(new Font("Arial", 12));
        bonus.setTranslateX(30 + (820 - 750 - bonus.getWidth()) / 2);
        bonus.setTranslateY(text.getTranslateY() -
            (bonus.getHeight() - text.getBoundsInLocal().getHeight()) / 2);
        // Workaround JFXC-2379
        infoPanel.getChildren().addAll(bonus, text);
    }
    infoPanel.setTranslateX(Config.FIELD_WIDTH);
}