通过 SpriteBatch
,我可以使用此方法拉伸(stretch) TextureRegion
以填充固定的“世界区域”
/** 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 中是否有等效方法?
最佳答案
没有。如果您需要不同大小的字体,则需要创建它们并将它们单独添加到资源中,或者您可以使用 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!
关于libgdx - 如何绘制BitmapFont来填充矩形区域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19853165/