绘制一个在libgdx中旋转的BitmapFont

Rah*_*med 7 java rotation matrix bitmap-fonts libgdx

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

小智 5

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

示例代码:

注意,这将返回单个字形的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;
}   
Run Code Online (Sandbox Code Playgroud)


Dun*_*una 4

你可以尝试下面的代码:

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();
Run Code Online (Sandbox Code Playgroud)

  • 在执行 setToRotation 时,您应该详细说明向量的含义 (3认同)