我製作了.pack文件並加載到皮膚。我可以將它設置爲可繪製的圖像類,它工作正常。但Table.setBackground
什麼都不做。Libgdx表setBackground什麼也不做
Drawable background = skin.getDrawable("tooltip_background");
tooltipGroup.setBackground(background);
爲什麼這段代碼不工作?
全碼:
tooltipGroup = new Table(skin);
tooltipGroup.setWidth(w/6);
Label.LabelStyle headerStyle = new Label.LabelStyle(headerFont, Color.GREEN);
Label headerLabel = new Label(effect.getName(), headerStyle);
headerLabel.setWidth(w/6);
headerLabel.setX(20);
headerLabel.setWrap(true);
headerLabel.setAlignment(Align.topLeft);
tooltipGroup.addActor(headerLabel);
Label.LabelStyle style = new Label.LabelStyle(font, Color.WHITE);
Label descriptionLabel = new Label(effect.getDescription(), style);
descriptionLabel.setWidth(w/6);
descriptionLabel.setWrap(true);
descriptionLabel.setAlignment(Align.topLeft);
descriptionLabel.setPosition(20, -descriptionLabel.getHeight());
tooltipGroup.addActor(descriptionLabel);
tooltipGroup.setPosition(mouseX, h - mouseY);
Drawable background = skin.getDrawable("tooltip_background");
tooltipGroup.setBackground(background);
stage.addActor(tooltipGroup);
我發現有什麼問題。在init中,表的寬度和高度= 0。並且...將具有它們自己尺寸的項目添加到Table中,不會改變Table的寬度和高度。爲什麼?我如何處理這個問題,如果帶'setWrap(true)'的標籤只返回一行的高度? –
粘貼構建表格的完整代碼,並將其添加到場景中。不添加最小寬度/高度的演員不會自動填充場景,因此要麼設置最小寬度/高度,要麼將其設置爲填充整個場景。 – Bernd
@Bernd檢查完整代碼的問題。 和...如果我設置最小的寬度/高度,比表將使用它?好。但是,內容的實際寬度和高度顯着超過理論上選擇的最小值。 –