我试图在屏幕中间显示一个对话框。但我无法使用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);
}
有什么想法吗?
答案 0 :(得分:0)
只需在调用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()
}