我想渲染固定的文本,以便在我的guiCam (不受任何旋转或变换影响的第二个摄像头)中进行调试。
我认为呈现的文本要么太大,要么太小,从我的角度来看,我在这里看不到,但我似乎在官方libgdx文档中找不到文本是如何绘制的,以及如何操纵大小。
创建:
guiCam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
guiCam.position.set(1f, 1f, 20f);
guiCam.lookAt(0, 0, 0);
guiCam.near = 1f;
guiCam.far = 300f;
guiCam.update();
batch = new SpriteBatch();
batch.setProjectionMatrix(guiCam.combined);
font = new BitmapFont();
font.setColor(Color.RED);渲染:
font.draw(batch, "debug line here", 200, 200);谁能给我解释一下libgdx默认字体是如何绘制的,或者这里有没有更好的方法来显示固定的文本?
我已经尝试过使用OrthoGraphic摄像头而不是预期的摄像头,但由于我的主要应用程序是3D,所以OrthoGraphic摄像头无法工作。
发布于 2019-10-24 19:47:45
Found this for you on stackexchange.
Lookx2给出的答案:
您可以只使用另一个SpriteBatch,而无需设置投影矩阵来绘制平显。
camera.update();
spriteBatch.setProjectionMatrix(camera.combined);
spriteBatch.begin();
aButton.draw(spriteBatch, 1F);
playerShip.draw(spriteBatch, 1F);
spriteBatch.end();
hudBatch.begin();
//Draw using hudBatch
hudBatch.end();如果你想在屏幕上呈现文本,那么你可以通过绘制到HUD来实现
发布于 2021-11-30 14:36:37
我认为它甚至不能混合2d和3d批次。您应该将Stage和StringBuilder与单个透视摄影机一起使用。
例如,在create()函数中初始化以下内容
...
font = new BitmapFont();
//design the font
label = new Label("<text>", new Label.LabelStyle(font, Color.BLACK));
// set position
label.setPosition(Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/2);
stage = new Stage();
stage.addActor(label);
...然后在render()函数中使用StringBuilder
...
StringBuilder builder = new StringBuilder();
//Change text at runtime
builder.append("<text>");
label.setText(builder);
stage.draw();
...帮助我使用它的示例来自https://sudonull.com/post/91327-The-simplest-3D-game-on-libGDX-for-Android-in-200-lines-of-code
https://stackoverflow.com/questions/58539815
复制相似问题