List of usage examples for com.badlogic.gdx.graphics.g2d BitmapFontCache getBounds
public TextBounds getBounds()
From source file:com.ridiculousRPG.ui.DisplayPlainTextService.java
License:Apache License
/** * Adds a message which will be drawn onto the screen (To increase the * performance you should not compute the colors floatbits at every * iteration)//from ww w . j a v a 2s . c om * * @param wrapWidth * If wrapWidth > 0 then the text will be wrapped at the * specified bound. * @param forceRemove * to remove the message immediately after displaying it * (displays it for only one frame). * @see {@link Color#toFloatBits()} */ public BitmapFontCache addMessage(CharSequence text, float color, Alignment horizontalAlign, Alignment verticalAlign, float padding, float wrapWidth, boolean forceRemove) { Rectangle bounds = GameBase.$().getScreen(); Camera cam = GameBase.$().getCamera(); if (projectionMatrix(cam) == cam.projection) { bounds = GameBase.$().getPlane(); } float x = padding, y = bounds.height - padding; BitmapFontCache bfc = createMsg(text, color, 0f, 0f, wrapWidth); TextBounds b = bfc.getBounds(); if (horizontalAlign == Alignment.CENTER) x = (bounds.width - b.width) * .5f; else if (horizontalAlign == Alignment.RIGHT) x = bounds.width - b.width - padding; if (verticalAlign == Alignment.CENTER) y = bounds.height - (bounds.height - b.height) * .5f; else if (verticalAlign == Alignment.BOTTOM) y = b.height + padding; if (projectionMatrix(cam) == cam.view) { if (x < 0f) x = 0f; if (y > bounds.height) y = bounds.height; } int ix = (int) (x + .5f); int iy = (int) (y + .5f); bfc.setPosition(ix, iy); if (forceRemove) msgDisplayOnce.add(bfc); else msgDisplay.add(bfc); return bfc; }