font.draw()可以在第一次调用时正常工作,但不能在第二次调用时正常工作 [英] font.draw() works correctly on first call but not on second
问题描述
我不确定是否不允许您两次调用font.draw(),但是第一行显示正确,但是第二行非常故障,缺少很多字母[在第一行中看起来不错]和随机数似乎没有绘制.我的.fnt文件可以在按钮上使用,而复选框也可以.
I'm not sure if you're not allowed to call font.draw() twice but the first linedisplays correctly but the second one is very glitchy, a lot of letters are missing [that appear fine in the first line] and random numbers seem to not draw. My .fnt file is fine as it works on buttons and checkbox's just fine.
这是我的一些代码:
private BitmapFont font = new BitmapFont(Gdx.files.internal("test.fnt"),false);
private SpriteBatch batch = new SpriteBatch();
//in Render Method
batch.begin();
font.draw(batch, "Best Distance: " + bestDistance + "m", Gdx.graphics.getHeight() / 2, Gdx.graphics.getWidth() / 2);
font.draw(batch, "Distance: " + finalDistance + "m", Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
stage.draw();
hud.stage.draw();
batch.end();
如果我切换他们的绘图调用的顺序,那么哪个被称为第一个正确绘制.
If I switch the order of their draw call then whichever one is called first draws correctly.
推荐答案
您正在调用stage.draw()
而不关闭spritebatch.在开始绘制舞台之前,只需调用batch.end()
即可.
在另一个打开的批处理中渲染一个批处理将导致各种奇怪的行为,使您认为错误不在于该批处理而已.
You're calling stage.draw()
without closing the spritebatch. Simply call batch.end()
before starting to draw the stage.
Rendering a batch inside another opened batch will result in all kind of weird behaviour that makes you think the fault lies in everything but the batch.
这是一个类似的问题.
这篇关于font.draw()可以在第一次调用时正常工作,但不能在第二次调用时正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!