Пример #1
0
  /**
   * Draws a String at the given coordinates. The String may contain newlines (\n or \r).<br>
   * If <code>font == null</code> the Render's instance of <code>BitmapFont</code> is used.
   *
   * @param batch
   * @param font
   * @param string
   * @param x
   * @param y
   * @param centered
   */
  public static void drawMultiLineString(
      SpriteBatch batch, BitmapFont font, String string, float x, float y, boolean centered) {
    if (font == null) font = font_;

    if (centered) {
      TextBounds bounds = font.getMultiLineBounds(string);
      float width = bounds.width;
      float height = bounds.height - font.getAscent();

      x -= (width / 2);
      y -= (height / 2);
    }

    font.drawMultiLine(batch, string, x, y);
  }
Пример #2
0
  @Override
  public void draw(float delta) {
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    viewMatrix.setToOrtho2D(0, 0, 480, 320);
    spriteBatch.setProjectionMatrix(viewMatrix);
    spriteBatch.setTransformMatrix(transformMatrix);
    spriteBatch.begin();
    spriteBatch.disableBlending();
    spriteBatch.setColor(Color.WHITE);
    spriteBatch.draw(background, 0, 0, 480, 320, 0, 0, 512, 512, false, false);
    spriteBatch.enableBlending();
    spriteBatch.draw(logo, 0, 320 - 128, 480, 128, 0, 256, 512, 256, false, false);
    String text = "It is the end my friend.\nTouch to continue!";
    TextBounds bounds = font.getMultiLineBounds(text);
    spriteBatch.setBlendFunction(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);
    font.drawMultiLine(spriteBatch, text, 0, 160 + bounds.height / 2, 480, HAlignment.CENTER);
    spriteBatch.end();
  }
Пример #3
0
 public int computeMultiLineTextWidth(CharSequence str) {
   return bitmapFont.getMultiLineBounds(str).width;
 }