[英]How to figure out the width and height of a written bitmap font string
好的,我有這個。
calibri.draw(FBLA_Game.spriteBatch, "Rooftop Defender",0 ,0 );
無論如何,這段代碼...我需要將文本居中。 而不是0,我會像這樣:
calibri.draw(FBLA_Game.spriteBatch, "Rooftop Defender",Gdx.graphics.getWidth()/2 ,Gdx.graphics.getHeight()/2 );
但這不是我想要的。 這使它開始寫單詞的位置居中。 因此,對於寬度,我需要減去要寫入的單詞的寬度,但是我無法弄清楚如何獲得要寫入的“ Rooftop Defender”的寬度。
感謝您的所有幫助,Alex
在LibGDX BitmapFont的新版本(> 1.6)正在與處理GlyphLayout類,你可以用它來計算您呈現字符串的寬度未來
//out of render() method! this call is expensive
GlyphLayout glyphLayout = new GlyphLayout(calibri, "Rooftop Defender");
...
//render()
float glyphLayoutWidth = glyphLayout.width;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.