我正在为一个uni项目制作一款战斗纸牌游戏(炉石)
棋盘上的“小精灵”牌有生命值和攻击值,这些都是不断变化的,我正在尝试制作一个复合组件,它将是一个中心ImageIcon,在左下角和右下角有两个“正方形”,代表卡片当前的生命值和攻击值,在左上角有一个,代表它的费用,所有这些都是StringProperty。
我真的不知道如何处理这件事,也许一个复合组件甚至不是必要的
这是一个炉石卡片的示例:

发布于 2016-05-17 09:33:22
使用StackPane。将图像放在底部,然后将AnchorPane放在顶部。在三个角中的每个角中放置一个文本,并将每个角的textProperty()绑定到其中一个StringProperties。如下所示:
public class BattleCard extends Application {
private static Label label;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
label = new Label();
label.setText("Waiting...");
StackPane root = new StackPane();
root.getChildren().add(new CardPane());
primaryStage.setScene(new Scene(root, 350, 420));
primaryStage.show();
}
public class CardPane extends StackPane {
public CardPane() {
ImageView cardImage = new ImageView(new Image("http://i.stack.imgur.com/1ljQH.png"));
AnchorPane anchorPane = new AnchorPane();
getChildren().addAll(cardImage, anchorPane);
Text costText = new Text("Cost");
Text healthText = new Text("Health");
Text attackText = new Text("Attack");
AnchorPane.setTopAnchor(costText, 0d);
AnchorPane.setLeftAnchor(costText, 0d);
AnchorPane.setBottomAnchor(healthText, 0d);
AnchorPane.setLeftAnchor(healthText, 0d);
AnchorPane.setBottomAnchor(attackText, 0d);
AnchorPane.setRightAnchor(attackText, 0d);
anchorPane.getChildren().addAll(costText, healthText, attackText);
}
}}
https://stackoverflow.com/questions/36699735
复制相似问题