1
我試圖在屏幕上爲我的遊戲的幫助屏幕繪製一個LibGDX標籤,但是,我沒有從JVM中得到任何錯誤,但是標籤文本不會繪製。LibGDX Label Not Drawing
這是我HelpMenu類:
package metrovelox.screens;
//imports...
public class HelpMenu extends Screen {
private Stage stage;
public HelpMenu(Game game, String name) {
super(game, name);
}
@Override
public void init() {
Texture.setEnforcePotImages(false);
stage = new Stage();
Group background = new Group();
Group foreground = new Group();
background.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
foreground.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
stage.addActor(background);
stage.addActor(foreground);
background.addActor(ResourceLoader.loadImage("ui/Main Menu Background.jpg"));
TextButton back = new TextButton("back", GuiSkinRegistry.retrieve("Simple Buttons"));
back.setPosition(Utils.getScreenCenter().x - 186, Utils.getScreenCenter().y - 200);
Label text = new Label("Hello", GuiSkinRegistry.retrieve("Simple Label"));
text.setPosition(Utils.getScreenCenter().x, Utils.getScreenCenter().y);
back.addListener(new ClickListener(Buttons.LEFT) {
@Override
public void clicked(InputEvent event, float x, float y) {
getGame().setScreen(getGame().getScreen("Main Menu"));
}
});
foreground.addActor(back);
foreground.addActor(text);
Gdx.input.setInputProcessor(stage);
}
@Override
public void render(float delta) {
super.render(delta);
stage.act(delta);
stage.draw();
}
@Override
public void dispose() {
super.dispose();
stage.dispose();
}
}
這是我主要的遊戲類:
package metrovelox.core;
import metrovelox.screens.HelpMenu;
import metrovelox.screens.MainMenu;
public class Metrovelox extends Game {
@Override
public void init() {
//Register skins, screens etc...
GuiSkinRegistry.register("Simple Buttons", ResourceLoader.loadSkin("MainMenu", ResourceLoader.loadTextureAtlas("ui/simple_buttons")));
GuiSkinRegistry.register("Simple Label", ResourceLoader.loadSkin("HelpMenu"));
addScreen(new MainMenu(this, "Main Menu"));
addScreen(new HelpMenu(this, "Help Menu"));
setScreen(getScreen("Main Menu"));
}
}
這是我的皮膚文件:
{
com.badlogic.gdx.graphics.Color: {
white: { hex: "ffffff" }
},
com.badlogic.gdx.graphics.g2d.BitmapFont: {
impact: {file: "../fonts/impact.fnt"}
},
com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
default: {
font: impact, fontColor: white
}
}
}
這是一個屏幕截圖幫助屏幕:
正如您所看到的,該標籤根本沒有被繪製。所有的文件都在正確的位置,所有的代碼似乎都是正確的,從我可以從LibGDX文檔收集到的內容看起來是正確的,但標籤不會繪製。
您是否找到任何解決方案,我似乎也有類似的問題。 = [ – user959631