Search in sources :

Example 1 with TextBounds

use of com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds in project commons-gdx by gemserk.

the class SpriteBatchUtils method drawCentered.

/**
	 * Draws a text centered in the specified coordinates
	 */
public static void drawCentered(SpriteBatch spriteBatch, BitmapFont font, CharSequence text, float x, float y) {
    TextBounds bounds = font.getBounds(text);
    font.draw(spriteBatch, text, x - bounds.width * 0.5f, y + bounds.height * 0.5f);
}
Also used : TextBounds(com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds)

Example 2 with TextBounds

use of com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds in project commons-gdx by gemserk.

the class SpriteBatchUtils method drawMultilineTextWithAlignment.

public static void drawMultilineTextWithAlignment(SpriteBatch spriteBatch, BitmapFont font, CharSequence text, float x, float y, float cx, float cy, HAlignment alignment, boolean roundPosition) {
    TextBounds bounds = font.getMultiLineBounds(text);
    float centerx = getCenterForAlignment(cx, alignment, bounds);
    if (roundPosition)
        font.drawMultiLine(spriteBatch, text, Math.round(x + centerx), Math.round(y + bounds.height * cy), 0f, alignment);
    else
        font.drawMultiLine(spriteBatch, text, x + centerx, y + bounds.height * cy, 0f, alignment);
}
Also used : TextBounds(com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds)

Example 3 with TextBounds

use of com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds in project commons-gdx by gemserk.

the class SpriteBatchUtils method getBounds.

public static Rectangle getBounds(BitmapFont font, CharSequence text, float x, float y, float sx, float sy) {
    TextBounds bounds = font.getMultiLineBounds(text);
    float w = bounds.width;
    float h = bounds.height;
    return new Rectangle(x - sx - w * 0.5f, y - sy - h * 0.5f, w + 2 * sx, h + 2 * sy);
}
Also used : Rectangle(com.badlogic.gdx.math.Rectangle) TextBounds(com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds)

Aggregations

TextBounds (com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds)3 Rectangle (com.badlogic.gdx.math.Rectangle)1