Java Libgdx字体问题
我试图在我的开始菜单按钮上绘制文本 除了字体/文本,我可以很好地绘制按钮和所有东西 以下是字体代码: 初始化:Java Libgdx字体问题,java,text,libgdx,Java,Text,Libgdx,我试图在我的开始菜单按钮上绘制文本 除了字体/文本,我可以很好地绘制按钮和所有东西 以下是字体代码: 初始化: buttonFont = new BitmapFont(Gdx.files.internal( "StartMenu/gamefont.fnt"), false); buttonFont.setScale(0.2f); 这里是我画舞台的地方,舞台上有字体: Gdx.gl20.glClearCol
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);
}
非常感谢您的帮助!: 我觉得奇怪的是,你在“调整大小”对话框中创建了按钮 我的建议,以及对我有效的建议,是在“创建”中初始化所有内容,在“渲染”中绘制舞台,并在“显示”中放置侦听器 初始化
create(){
//Define the stage where you'll draw the TextButton
stage = new Stage();
//Define your font
buttonFont = new BitmapFont(Gdx.files.internal("StartMenu/gamefont.fnt"), false);
//Define the skin that contains your images
textureAtlas = game.assets.get("Images.pack", TextureAtlas.class);
skin.addRegions(textureAtlas);
//Define the TextButtonStyle
textButtonStyle = new TextButtonStyle();
textButtonStyle.up = skin.getDrawable("Button");
textButtonStyle.down = skin.getDrawable("Button");
textButtonStyle.font = buttonFont;
textButtonStyle.fontColor = Color.WHITE;
textButtonStyle.downFontColor = new Color(0.5f, 0.5f, 0.5f, 1);
//Define the TextButton
startGameBtn = new TextButton("Start Game", textButtonStyle);
startGameBtn.setWidth(250);
startGameBtn.setHeight(150);
startGameBtn.setX(Gdx.graphics.getWidth() / 2 - startGameBtn.getWidth() / 2);
startGameBtn.setY(Gdx.graphics.getHeight() / 1.5f);
//Add the TextButton to the stage
stage.addActor(startGameBtn);
}
文本按钮的绘制
render(){
Gdx.gl20.glClearColor(1, 0, 0, 1);
Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act();
stage.draw();
}
show(){
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));
}
});
}
使用文本按钮
render(){
Gdx.gl20.glClearColor(1, 0, 0, 1);
Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act();
stage.draw();
}
show(){
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));
}
});
}
你不使用TextButton有什么原因吗?我正在使用TextButton哦,对不起,没有看到。。。您使用的是哪个Libgdx版本?看起来他们在最新版本中对BitmapFont做了一些更改…有关于您的问题的更新吗?你试过我的解决方案吗?这样行吗?如果没有,您观察到了什么?我仍然没有修复它,没有。我相信字体文件可能有问题。你的解决方案是什么?我没有看到。