LibGDX标签不绘图

时间:2014-02-21 01:07:40

标签: java label libgdx draw scene2d

我正在尝试在屏幕上为我的游戏帮助屏幕绘制一个LibGDX标签但是,我没有从JVM获得任何错误,但标签文本不会绘制。

这是我的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
        }
    }
}

这是帮助屏幕的屏幕截图: Screenshot

如您所见,标签根本没有被绘制。所有文件都在正确的位置,所有代码似乎都是正确的,我可以从LibGDX文档中收集,但标签不会绘制。

1 个答案:

答案 0 :(得分:0)

尝试更改字体文件。也许这与将颜色设置为白色有关。我对字体有一些非常奇怪的错误,并且必须使用Angel Code site版本1.14的输出来最终使其正确。 1.13对我不起作用。