2

有了SpriteBatch,我可以使用此方法拉伸 aTextureRegion以填充固定的“世界区域”

/** Draws a rectangle with the bottom left corner at x,y and stretching the region to cover the given width and height. */
    public void draw (TextureRegion region, float x, float y, float width, float height)

中是否有等效的方法BitmapFont

4

1 回答 1

2

没有。如果您需要不同大小的字体,您需要创建它们并将它们单独添加到资产中,或者您可以使用 Gdx Freetype 动态生成它们(从而节省大量空间)。

https://github.com/libgdx/libgdx/wiki/Gdx-freetype

由于仅链接的答案在此处无效,因此为了完整性,我将仅复制 wiki 条目的相关部分:

下载最新的夜间版本。

打开 libgdx-nightly-latest.zip/extensions/gdx-freetype 并执行以下操作:

extract gdx-freetype.jar and gdx-freetype-natives.jar to your core project's libs folder
link gdx-freetype.jar to your core, android and desktop project
link gdx-freetype-natives.jar to your desktop project
copy armeabi/libgdx-freetype.so to your android project's libs/armeabi folder
copy armeabi-v7a/libgdx-freetype.so to your android project's libs/armeabi-v7a folder

在代码中:

FreeTypeFontGenerator generator = new
FreeTypeFontGenerator(Gdx.files.internal("fonts/myfont.ttf"));
BitmapFont font12 = generator.generateFont(12); // font size 12 pixels
BitmapFont font25 = generator.generateFont(25); // font size 25 pixels
generator.dispose(); // don't forget to dispose to avoid memory leaks!
于 2013-11-08T11:13:19.930 回答