位图字体 API
测量宽度String
你用你的Font
并得到bounds
of the String
,你要画画了。
BitmapFont.getBounds(String str).width
位图字体 API http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/BitmapFont.html
您也可以获取用于绘制的正确偏移的高度。只需将宽度替换为高度即可。
另外对于多行文本使用getMultiLineBounds(someString).width
得到界限。
位图字体 API >= 1.5.6
The BitmapFont API 在 1.5.7 中更改所以现在有一种不同的方法来获取边界:
BitmapFont.TextBounds 和 getBounds 已完成。相反,将字符串提供给 GlyphLayout 并使用其宽度和高度字段获取边界。然后,您可以通过将相同的 GlyphLayout 传递给 BitmapFont 来绘制文本,这意味着字形不必像以前那样布局两次。
Source http://www.badlogicgames.com/wordpress/?p=3658 (网络档案 https://web.archive.org/web/20210120130740/https://www.badlogicgames.com/wordpress/?p=3658)
Example:
GlyphLayout layout = new GlyphLayout(); //dont do this every frame! Store it as member
layout.setText("meow");
float width = layout.width;// contains the width of the current set text
float height = layout.height; // contains the height of the current set text
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)