Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw a BitmapFont rotated in libgdx

I can't seem to figure out how to rotate a Bitmap font correctly. I think you modify the transformation matrix of the SpriteBatch. However, trying to rotate that rotates the text around some point, and I don't know how to rotate it relative to the text itself.

like image 383
Rahat Ahmed Avatar asked Dec 14 '11 17:12

Rahat Ahmed


1 Answers

You can create a glyph into a sprite. That way , you can manipulate your text as a sprite.

Example code:

Note, this will return a Sprite of a single glyph. (E.g. char 'A' is transformed into a sprite.)

/** 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;
}   
like image 56
Gerrit Paul van Dijk Avatar answered Oct 08 '22 21:10

Gerrit Paul van Dijk