【发布时间】:2023-04-03 10:15:01
【问题描述】:
我正在尝试在开始菜单的按钮上绘制文本。
我可以画按钮和除字体/文本以外的所有内容。
这是字体代码:
正在初始化:
buttonFont = new BitmapFont(Gdx.files.internal(
"StartMenu/gamefont.fnt"), false);
buttonFont.setScale(0.2f);
这里是我画舞台的地方,舞台里面有字体:
Gdx.gl20.glClearColor(1, 0, 0, 1);
Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(delta);
sb.begin();
stage.draw();
sb.end();
这是用于初始化更多东西的东西:
@Override
public void resize(int width, int height) {
if(stage == null)
stage = new Stage();
stage.clear();
Gdx.input.setInputProcessor(stage);
style.font = buttonFont;
style.up = skin.getDrawable("Button");
style.down = skin.getDrawable("Button");
startGameBtn = new TextButton("Start Game", style);
startGameBtn.setWidth(250);
startGameBtn.setHeight(150);
startGameBtn.setX(Gdx.graphics.getWidth() / 2 - startGameBtn.getWidth() / 2);
startGameBtn.setY((float) (Gdx.graphics.getHeight() / 1.5));
startGameBtn.addListener(new InputListener()
{
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)
{
return true;
}
public void touchUp(InputEvent event, float x, float y, int pointer, int button)
{
game.setScreen(new Gameplay(game));
}
});
stage.addActor(startGameBtn);
stage.addActor(lb);
}
非常感谢任何帮助! :)
【问题讨论】:
-
你有理由不使用
TextButton吗? -
我正在使用文本按钮
-
哦,抱歉,没看到...您使用的是哪个 Libgdx 版本?好像他们在最新版本中改变了一些关于 BitmapFont 的东西......
-
您的问题有任何更新吗?你试过我的解决方案了吗?那样有用吗 ?如果没有,你观察到什么?
-
我还没有修好,没有。我相信字体文件可能有问题。你的解决方案是什么?我没看到。