绘制一个在libgdx中旋转的BitmapFont

我似乎无法弄清楚如何正确旋转位图字体。 我想你修改了SpriteBatch的转换矩阵。 但是,尝试旋转可以围绕某个点旋转文本,我不知道如何相对于文本本身旋转文本。

您可以尝试以下代码:

Matrix4 mx4Font = new Matrix4(); BitmapFont font; SpriteBatch spriteFont; font = new BitmapFont(Gdx.files.internal("data/font/agencyFB.fnt"), Gdx.files.internal("data/font/agencyFB.png"), true); //must be set true to be flipped mx4Font.setToRotation(new Vector3(200, 200, 0), 180); spriteFont.setTransformMatrix(mx4Font); spriteFont.begin(); font.setColor(1.0f, 1.0f, 1.0f, 1.0f); font.draw(spriteFont, "The quick brown fox jumped over the lazy dog", 100, 110); spriteFont.end(); 

您可以在精灵中创建一个字形。 这样,您可以将文本操作为精灵。

示例代码:

注意,这将返回单个字形的Sprite。 (例如char’A’被转换为精灵。)

 /** Creates a sprite from a glyph. * * @param ch * @return Sprite */ public Sprite getGlyphSprite (char ch) { Glyph glyph = Globals.g.font.getData().getGlyph(ch); Sprite s = new Sprite(Globals.g.font.getRegion().getTexture(), glyph.srcX,glyph.srcY,glyph.width, glyph.height); s.flip(false, true); s.setOrigin(glyph.width/2, glyph.height/2); return s; } 

我只想添加..我想你在某些图册中有字体基础图像..所以你需要添加TextureRegion原件sot gliph src,因为它只是相对于给定的纹理区域所以

 BitmapFont font = ... BitmapFont.Glyph glyph = font.getData().getGlyph(ch); int srcX = glyph.srcX + font.getRegion().getRegionX(); int srcY = glyph.srcY+ font.getRegion().getRegionY(); Sprite s = new Sprite(font.getRegion().getTexture(), srcX,srcY,glyph.width, glyph.height); 

Lunatikul的第一个答案在我的2D案例中没有奏效。 它将我的文字缩减为半个字母。 我成功了以下内容:

 batch.begin(); batch.setTransformMatrix(new Matrix4().setToRotation(0,0,1,)); font.draw(batch, "Hallo Welt", 100, 100); batch.end();