我正在尝试在屏幕中间显示一个对话框。但我无法使用setWidth()或setHeight()更改对话框的大小。我有以下代码:
private void showDialog() {
Window.WindowStyle dialogStyle = new Window.WindowStyle();
dialogStyle.background = new TextureRegionDrawable(new TextureRegion(dialog_bg));
dialogStyle.titleFont = gameFont;
Dialog dialog = new Dialog("Test Dialog", dialogStyle);
dialog.setWidth(200); // will be ignored
dialog.show(stage);
}
有任何想法吗?
调用dialog.show()后,只需调用您的更改即可。在这种情况下,我正在使用一个带有FitViewport的舞台,所以我缩小我的演员以使它们适合。当我调整它们的大小时,我必须考虑到比例。
public void create(Dialog dialog, float scale){
dialog.setScale(scale);
dialog.setMovable(false);
dialog.text("Are you sure you want to yada yada?");
dialog.button("Yes", true); //sends "true" as the result
dialog.button("No", false); //sends "false" as the result
}
public void show(Stage st) {
dialog.show(st); //pack() is called internally
dialog.setWidth(worldWidth/scale); //we override changes made by pack()
dialog.setY(Math.round((st.getHeight() - dialog.getHeight()) / 2)); //we override changes made by pack()
}