Example usage for com.badlogic.gdx.graphics.g2d BitmapFont setScale

List of usage examples for com.badlogic.gdx.graphics.g2d BitmapFont setScale

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d BitmapFont setScale.

Prototype

public void setScale(float scaleX, float scaleY) 

Source Link

Document

Scales the font by the specified amounts on both axes

Note that smoother scaling can be achieved if the texture backing the BitmapFont is using TextureFilter#Linear .

Usage

From source file:com.haxtastic.haxmasher.entity.ui.Console.java

License:Apache License

@Override
public void draw(SpriteBatch batch, BitmapFont font) {
    AtlasRegion spriteRegion = Art.regions.get(name);
    if (width == 0)
        width = spriteRegion.getRegionWidth();
    if (height == 0)
        height = spriteRegion.getRegionHeight();
    if (width < 0)
        width = -width;/*from w ww  .  jav  a2 s  .c o m*/
    float posX = x * Constants.PIXELS_PER_METER_X;
    float posY = y * Constants.PIXELS_PER_METER_Y;
    batch.draw(spriteRegion, posX, posY, width * Constants.PIXELS_PER_METER_X,
            height * Constants.PIXELS_PER_METER_Y);
    //Draw text
    font.setColor(0, 0, 0, 1);
    float sX = font.getScaleX();
    float sY = font.getScaleY();
    font.setScale(1.1f, 1.1f);
    String msg = null;
    int i = 0;
    ListIterator<String> iter = lines.listIterator(lines.size());
    while (iter.hasPrevious()) {
        msg = iter.previous();
        posX = linex * Constants.PIXELS_PER_METER_X;
        posY = (liney + (space * i)) * Constants.PIXELS_PER_METER_Y + (font.getBounds(msg).height * i);
        font.draw(batch, msg, posX, posY);
        i++;
    }
    font.setScale(sX, sY);
}

From source file:com.haxtastic.haxmasher.scene.Stats.java

License:Apache License

@Override
public void draw(float dt, SpriteBatch batch, BitmapFont font) {
    if (parent != null)
        parent.draw(dt, batch, font);//from  ww w. ja  va  2  s  .  c  o m
    Iterator<Actor> iter = getActors().iterator();
    while (iter.hasNext()) {
        Actor actor = iter.next();
        actor.draw(batch, font);
    }
    font.setColor(0, 0, 0, 1);
    float sX = font.getScaleX();
    float sY = font.getScaleY();
    font.setScale(1.575f, 1.725f);

    String msg = "You have gained " + level;
    msg += (level > 1 ? " levels." : " level.");
    float posX = (Constants.Positions.pointsTextX) * Constants.PIXELS_PER_METER_X
            + (font.getBounds(" to spend").width / 2);
    float posY = (Constants.Positions.pointsTextY + 0.1f) * Constants.PIXELS_PER_METER_Y
            + (font.getBounds(msg).height);
    font.draw(batch, msg, posX, posY);

    msg = "You have " + points + " skill points to spend.";
    posX = Constants.Positions.pointsTextX * Constants.PIXELS_PER_METER_X;
    posY = Constants.Positions.pointsTextY * Constants.PIXELS_PER_METER_Y;
    font.draw(batch, msg, posX, posY);

    msg = Constants.Stats.healthWeight + " * " + (PlayerStats.pHealth + PlayerStats.level);
    posX = Constants.Buttons.healthTextX * Constants.PIXELS_PER_METER_X - (font.getBounds(msg).width / 2);
    posY = Constants.Buttons.pointsY * Constants.PIXELS_PER_METER_Y + (font.getBounds(msg).height);
    font.draw(batch, msg, posX, posY);

    msg = Constants.Stats.damageWeight + " * " + (PlayerStats.pDamage + PlayerStats.level);
    posX = Constants.Buttons.damageTextX * Constants.PIXELS_PER_METER_X - (font.getBounds(msg).width / 2);
    posY = Constants.Buttons.pointsY * Constants.PIXELS_PER_METER_Y + (font.getBounds(msg).height);
    font.draw(batch, msg, posX, posY);

    msg = Constants.Stats.armorWeight + " * " + (PlayerStats.pArmor + PlayerStats.level);
    posX = Constants.Buttons.armorTextX * Constants.PIXELS_PER_METER_X - (font.getBounds(msg).width / 2);
    posY = Constants.Buttons.pointsY * Constants.PIXELS_PER_METER_Y + (font.getBounds(msg).height);
    font.draw(batch, msg, posX, posY);

    msg = Constants.Stats.critWeight + " * " + (PlayerStats.pCrit + PlayerStats.level);
    posX = Constants.Buttons.critTextX * Constants.PIXELS_PER_METER_X - (font.getBounds(msg).width / 2);
    posY = Constants.Buttons.pointsY * Constants.PIXELS_PER_METER_Y + (font.getBounds(msg).height);
    font.draw(batch, msg, posX, posY);
    font.setScale(sX, sY);
}

From source file:org.illarion.engine.backend.gdx.GdxGraphics.java

License:Open Source License

@Override
public void drawText(@Nonnull final Font font, @Nonnull final CharSequence text, @Nonnull final Color color,
        final int x, final int y, final double scaleX, final double scaleY) {
    if (font instanceof GdxFont) {
        activateSpriteBatch();//from   w  w w .  jav  a  2s. com
        transferColor(color, tempColor1);
        final BitmapFont bitmapFont = ((GdxFont) font).getBitmapFont();
        bitmapFont.setScale((float) scaleX, (float) scaleY);
        bitmapFont.setColor(tempColor1);
        bitmapFont.draw(spriteBatch, text, x, y - bitmapFont.getAscent());
    }
}