List of usage examples for com.badlogic.gdx.graphics.g2d BitmapFont drawMultiLine
public TextBounds drawMultiLine(Batch batch, CharSequence str, float x, float y)
From source file:edu.lehigh.cse.lol.Display.java
License:Open Source License
/** * A helper method to draw text nicely. In GDX, we draw everything by giving * the bottom left corner, except text, which takes the top left corner. * This function handles the conversion, so that we can use bottom-left. * * @param x The X coordinate of the bottom left corner (in pixels) * @param y The Y coordinate of the bottom left corner (in pixels) * @param message The text to display/*from ww w.j a va2 s .c om*/ * @param bf The BitmapFont object to use for the text's font * @param sb The SpriteBatch used to render the text */ static void drawTextTransposed(int x, int y, String message, BitmapFont bf, SpriteBatch sb) { bf.drawMultiLine(sb, message, x, y + bf.getMultiLineBounds(message).height); }
From source file:edu.lehigh.cse.lol.Util.java
License:Open Source License
/** * Create a Renderable that consists of some text to draw * * @param x The X coordinate of the bottom left corner, in pixels * @param y The Y coordinate of the bottom left corner, in pixels * @param message The text to display... note that it can't change on the fly * @param red The red component of the font color (0-255) * @param green The green component of the font color (0-255) * @param blue The blue component of the font color (0-255) * @param fontName The font to use/* w w w .j av a 2 s. com*/ * @param size The font size * @return A Renderable of the text */ public static Renderable makeText(final int x, final int y, final String message, final int red, final int green, final int blue, String fontName, int size) { final BitmapFont bf = Media.getFont(fontName, size); return new Renderable() { @Override public void render(SpriteBatch sb, float elapsed) { bf.setColor(((float) red) / 256, ((float) green) / 256, ((float) blue) / 256, 1); bf.drawMultiLine(sb, message, x, y + bf.getMultiLineBounds(message).height); } }; }
From source file:edu.lehigh.cse.lol.Util.java
License:Open Source License
/** * Create a Renderable that consists of some text to draw. The text will be * centered vertically and horizontally on the screen * * @param message The text to display... note that it can't change on the fly * @param red The red component of the font color (0-255) * @param green The green component of the font color (0-255) * @param blue The blue component of the font color (0-255) * @param fontName The font to use// w w w . ja v a2s .c o m * @param size The font size * @return A Renderable of the text */ public static Renderable makeText(final String message, final int red, final int green, final int blue, String fontName, int size) { final BitmapFont bf = Media.getFont(fontName, size); final float x = Lol.sGame.mWidth / 2 - bf.getMultiLineBounds(message).width / 2; final float y = Lol.sGame.mHeight / 2 + bf.getMultiLineBounds(message).height / 2; return new Renderable() { @Override public void render(SpriteBatch sb, float elapsed) { bf.setColor(((float) red) / 256, ((float) green) / 256, ((float) blue) / 256, 1); bf.drawMultiLine(sb, message, x, y); } }; }
From source file:edu.lehigh.cse.lol.Util.java
License:Open Source License
/** * Draw some text on the current level/*w w w . ja va2 s . c o m*/ * * Note: the order in which this is called relative to other actors will * determine whether they go under or over this text. * * @param x X coordinate of bottom left corner of the text * @param y Y coordinate of bottom left corner of the text * @param text The text to display * @param red The red component of the color (0-255) * @param green The green component of the color (0-255) * @param blue The blue component of the color (0-255) * @param fontName The name of the font file to use * @param size The font size to use * @param zIndex The z index of the image. There are 5 planes: -2, -2, 0, 1, * and 2. By default, everything goes to plane 0 */ public static void drawText(final float x, final float y, final String text, final int red, final int green, final int blue, String fontName, int size, int zIndex) { final BitmapFont bf = Media.getFont(fontName, size); Renderable r = new Renderable() { @Override public void render(SpriteBatch sb, float elapsed) { bf.setColor(((float) red) / 256, ((float) green) / 256, ((float) blue) / 256, 1); bf.setScale(1 / Physics.PIXEL_METER_RATIO); bf.drawMultiLine(sb, text, x, y + bf.getMultiLineBounds(text).height); bf.setScale(1); } }; Lol.sGame.mCurrentLevel.addActor(r, zIndex); }
From source file:edu.lehigh.cse.lol.Util.java
License:Open Source License
/** * Draw some text on the current level, centered on a point. * * Note: the order in which this is called relative to other actors will * determine whether they go under or over this text. * * @param centerX X coordinate of center of the text * @param centerY Y coordinate of center of the text * @param text The text to display/* ww w . j a v a 2s .co m*/ * @param red The red component of the color (0-255) * @param green The green component of the color (0-255) * @param blue The blue component of the color (0-255) * @param fontName The name of the font file to use * @param size The font size to use * @param zIndex The z index of the image. There are 5 planes: -2, -2, 0, 1, * and 2. By default, everything goes to plane 0 */ public static void drawTextCentered(final float centerX, final float centerY, final String text, final int red, final int green, final int blue, String fontName, int size, int zIndex) { final BitmapFont bf = Media.getFont(fontName, size); // figure out the image dimensions bf.setScale(1 / Physics.PIXEL_METER_RATIO); final float w = bf.getMultiLineBounds(text).width; final float h = bf.getMultiLineBounds(text).height; bf.setScale(1); // describe how to render it Renderable r = new Renderable() { @Override public void render(SpriteBatch sb, float elapsed) { bf.setColor(((float) red) / 256, ((float) green) / 256, ((float) blue) / 256, 1); bf.setScale(1 / Physics.PIXEL_METER_RATIO); bf.drawMultiLine(sb, text, centerX - w / 2, centerY + h / 2); bf.setScale(1); } }; Lol.sGame.mCurrentLevel.addActor(r, zIndex); }
From source file:mobi.shad.s3lib.main.S3Gfx.java
License:Apache License
public static void drawString(float posX, float posY, String string, BitmapFont font) { spriteBatch.begin();//from w w w.j a va 2 s . c o m font.drawMultiLine(spriteBatch, string, posX, posY); spriteBatch.end(); }