我试图在基于libgdx的游戏中使用BitMapFont。我这样做:
BitmapFont font;
this.font = new BitmapFont();
render{
Gdx.gl.glClearColor(0x64 / 255.0f, 0x95 / 255.0f, 0xed / 255.0f,
0xff / 255.0f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Gdx.app.log(TAG, " FPS: " + Gdx.graphics.getFramesPerSecond());
batch.setProjectionMatrix(CameraManager.camera.combined);
batch.begin();
font.setColor(Color.BLACK);
font.draw(batch, "Time", 4, 4);
batch.end();
}
我的相机管理如下:
public class CameraManager {
public static OrthographicCamera camera;
public CameraManager(){
camera = new OrthographicCamera(Constants.VIEWPORT_WIDTH, Constants.VIEWPORT_HEIGHT);
camera.viewportWidth = (camera.viewportHeight)
* ((float) Gdx.graphics.getWidth() / (float) Gdx.graphics
.getHeight());
camera.position.set(camera.viewportWidth / 2,
camera.viewportHeight / 2, 0);
camera.update();
}
public void resize(int width, int height) {
camera.viewportWidth = (camera.viewportHeight)
* ((float) width / (float) height);
camera.update();
}
}
但是不是文本,而是显示几个矩形,其颜色是我传递给setColor()的颜色。我真的不知道这里发生了什么。大多数教程都使用这段简单的代码。但它不适合我。
请告知。
答案 0 :(得分:0)
我建议下载一些.ttf字体并将它们传递到位图字体对象中,如此
BitmapFont font = new BitmapFont(Gdx.files.internal("fontfile.ttf"));
您可以下载许多优秀的.ttf字体https://www.google.com/fonts