Example usage for com.badlogic.gdx.graphics.g2d.freetype FreeTypeFontGenerator generateFont

List of usage examples for com.badlogic.gdx.graphics.g2d.freetype FreeTypeFontGenerator generateFont

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d.freetype FreeTypeFontGenerator generateFont.

Prototype

public BitmapFont generateFont(FreeTypeFontParameter parameter) 

Source Link

Document

Generates a new BitmapFont .

Usage

From source file:at.therefactory.jewelthief.JewelThief.java

License:Open Source License

@Override
public void create() {
    instance = this;

    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(
            Gdx.files.internal("fonts/amiga4ever pro2.ttf"));
    FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
    parameter.size = 8;//from   w w w . ja  v  a2  s .co  m
    parameter.mono = true;
    font = generator.generateFont(parameter);
    generator.dispose();

    batch = new SpriteBatch();
    shapeRenderer = new ShapeRenderer();
    camera = new OrthographicCamera();
    viewport = new FitViewport(WINDOW_WIDTH, WINDOW_HEIGHT, camera);
    camera.position.set(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2, 0);
    camera.update();

    textureAtlas = new TextureAtlas("textures.pack");
    assetManager = new AssetManager();

    fade = textureAtlas.createSprite("fade");
    fade.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
    fade.setPosition(0, 0);

    particles = new Particles(textureAtlas);

    loadInitialPreferences();
    loadAssets();
    tryToSubmitLatestHighscores();

    // load and show logo screen
    theRefactoryLogoScreen = new LogoScreen(batch, shapeRenderer, viewport, camera);
    setScreen(theRefactoryLogoScreen);
}

From source file:br.com.raphaelbruno.game.zombieinvaders.vr.util.FontUtils.java

License:Apache License

public static BitmapFont loadFont(String url, int size, Color color) {
    BitmapFont font;/*from  w  ww  .  j a  v a  2 s.  co m*/
    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal(url));
    FreeTypeFontParameter parameter = new FreeTypeFontParameter();
    parameter.size = size;
    if (color != null)
        parameter.color = color;
    font = generator.generateFont(parameter);
    generator.dispose();
    return font;
}

From source file:broken.shotgun.throwthemoon.stages.GameStage.java

License:Open Source License

private void loadFont() {
    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(
            Gdx.files.internal("fonts/anonymous_pro_b.ttf"));
    FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
    parameter.size = 20;//from ww w .jav a2s  .c o m
    font = generator.generateFont(parameter);
    generator.dispose();
}

From source file:CB_UI_Base.GL_UI.Fonts.java

License:Open Source License

private static BitmapFont loadFontFromFile(FreeTypeFontGenerator generator, int scale) {
    String fs = Global.fs;//from   w w w  .  jav  a 2  s .co  m
    String fontPath = "";
    // fonts-Verzeichnis "lokal" im cachebox/skins/small oder ..normal oder christmas

    if (cfg.SkinFolder.type() == FileType.Absolute) {
        String FolderPath = cfg.SkinFolder.path();
        String path = FolderPath.replace("/", fs) + fs + "fnts";
        if (FileIO.DirectoryExists(path)) {
            // fonts-Verzeichnis "lokal" im cachebox/skins/small oder ..normal oder christmas
            fontPath = path + fs + String.valueOf(scale) + ".fnt";
        } else {
            // fonts-Verzeichnis "global" im cachebox/skins
            path = FolderPath.replace("/", fs) + fs + ".." + fs + "fnts";
            fontPath = path + fs + String.valueOf(scale) + ".fnt";
        }

    }

    // Wenn der font nicht vorberechnet ist, dann wird er generiert
    if (FileIO.FileExists(fontPath)) {
        Log.debug(log, "load font for scale " + scale + " from " + fontPath);
        // automatic load of png does not work on Android, so
        // return new BitmapFont(Gdx.files.absolute(fontPath),false);
        Texture tex = new Texture(Gdx.files.absolute(fontPath.replace(".fnt", ".png")));
        tex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
        TextureRegion region = new TextureRegion(tex);
        BitmapFont ret = new BitmapFont(Gdx.files.absolute(fontPath), region, false);
        return ret;
    } else {
        Log.debug(log, "generate font for scale " + scale);
        FreeTypeFontParameter parameter = new FreeTypeFontParameter();
        parameter.size = scale;
        parameter.characters = DEFAULT_CHARACTER;
        BitmapFont ret = generator.generateFont(parameter);
        TextureRegion region = ret.getRegion();
        Texture tex = region.getTexture();
        tex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
        return ret;
    }
}

From source file:CB_UI_Base.graphics.GL_Fonts.java

License:Open Source License

private BitmapFont generateFont(FileHandle file, int textSize) {
    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(file);

    FreeTypeFontParameter parameter = new FreeTypeFontParameter();
    parameter.size = textSize;//w  w  w .  j  av a  2  s.  c om
    parameter.characters = Fonts.DEFAULT_CHARACTER;
    BitmapFont ret = generator.generateFont(parameter);

    TextureRegion region = ret.getRegion();
    Texture tex = region.getTexture();
    tex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    generator.dispose();

    return ret;
}

From source file:com.agateau.ui.UiAssets.java

License:Apache License

private BitmapFont loadFont(String name, FreeTypeFontGenerator.FreeTypeFontParameter parameter) {
    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal(name));
    BitmapFont font = generator.generateFont(parameter);
    generator.dispose();/*  ww w .j  a  v a  2 s.c  o  m*/
    return font;
}

From source file:com.andgate.pokeadot.PokeADot.java

License:Open Source License

private void createFonts() {
    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal(Constants.FONT_LOCATION));
    FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();

    parameter.size = (int) ((float) Constants.LARGE_FONT_SIZE * ppm);
    largeFont = generator.generateFont(parameter);

    parameter.size = (int) ((float) Constants.MEDIUM_FONT_SIZE * ppm);
    mediumFont = generator.generateFont(parameter);

    parameter.size = (int) ((float) Constants.MEDIUM_SMALL_FONT_SIZE * ppm);
    mediumSmallFont = generator.generateFont(parameter);

    parameter.size = (int) ((float) Constants.SMALL_FONT_SIZE * ppm);
    smallFont = generator.generateFont(parameter);

    generator.dispose();//from w w  w.java 2s. co  m
}

From source file:com.blackboxgaming.engine.factories.LayerFactory.java

public static Layer createLevelAndHealthLayer() {
    Stage stage = new Stage(new StretchViewport(486, 864));
    Skin skin = new Skin();
    Table table = new Table();
    table.top().pad(10);/*  ww w. j a  v a2 s .c o m*/

    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(
            Gdx.files.internal("ui/fonts/Century Gothic Bold.ttf"));
    FreeTypeFontParameter parameter = new FreeTypeFontParameter();
    parameter.size = 40;
    parameter.borderColor = Color.BLACK;
    parameter.borderWidth = 3;
    BitmapFont font = generator.generateFont(parameter);
    generator.dispose();
    Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE);

    skin.add("star", new Texture("ui/icons/star.png"));
    skin.add("shield", new Texture("ui/icons/shield.png"));
    skin.add("brick", new Texture("ui/icons/brick.png"));
    skin.add("swipe128", new Texture("ui/icons/swipe128.png"));

    float padding = 10;
    Image icon = new Image(skin.getDrawable("star"));
    if (Global.debugLevelUp) {
        icon.addListener(new ClickListener() {
            @Override
            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                if (Engine.systemManager.has(LevelProgressionSystem.class)) {
                    for (Entity entity : Engine.systemManager.get(LevelProgressionSystem.class).entities) {
                        Engine.garbageManager.markForDeletion(entity);
                    }
                }
                super.touchUp(event, x, y, pointer, button);
            }
        });
    }
    table.add(icon).pad(padding);
    Label levelLabel = new Label("", labelStyle);
    table.add(levelLabel).pad(padding);
    icon = new Image(skin.getDrawable("shield"));
    table.add(icon).pad(padding);
    Label healthLabel = new Label("", labelStyle);
    table.add(healthLabel).pad(padding);
    icon = new Image(skin.getDrawable("brick"));
    table.add(icon).pad(padding);
    Label brickLabel = new Label("", labelStyle);
    table.add(brickLabel).pad(padding);

    table.row();

    // swipe
    if (Engine.systemManager.has(LevelProgressionSystem.class)) {
        if (Engine.systemManager.get(LevelProgressionSystem.class).level < 5) {
            icon = new Image(skin.getDrawable("swipe128"));
            table.add(icon).padTop(350).colspan(6);
            Global.swipeIcon = icon;

        }
    }

    //        table.setDebug(true);
    table.setFillParent(true);
    stage.addActor(table);

    Global.LEVEL_LABEL = levelLabel;
    Global.HEALTH_LABEL = healthLabel;
    Global.BRICK_LABEL = brickLabel;

    if (Engine.systemManager.has(LevelProgressionSystem.class)) {
        Global.LEVEL_LABEL.setText("" + Engine.systemManager.get(LevelProgressionSystem.class).level);
        Global.HEALTH_LABEL.setText("" + Engine.systemManager.get(LevelProgressionSystem.class).health);
        Global.BRICK_LABEL.setText("" + Engine.systemManager.get(LevelProgressionSystem.class).nrOfBricks);
    }

    Engine.inputManager.add(stage);
    return new Layer("topLayer", stage, table);
}

From source file:com.eightpuzzle.game.EightPuzzle.java

License:Apache License

@Override
public void create() {
    gameFont = new BitmapFont();
    solvedFont = new BitmapFont();
    batch = new SpriteBatch();
    aspectRatio = (float) Gdx.graphics.getHeight() / (float) Gdx.graphics.getWidth();
    OrthographicCamera camera = new OrthographicCamera(GAME_WIDTH * aspectRatio, GAME_HEIGHT * aspectRatio);
    //camera.position.set(GAME_WIDTH/2, GAME_HEIGHT/2, 0)
    camera.setToOrtho(false, GAME_WIDTH * aspectRatio, GAME_HEIGHT * aspectRatio);
    //camera.setToOrtho(false,GAME_WIDTH,GAME_HEIGHT);
    stage = new Stage(new ExtendViewport(GAME_WIDTH * aspectRatio, GAME_HEIGHT * aspectRatio, camera));//Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), camera));
    Gdx.input.setInputProcessor(stage);//from  w  ww. jav  a 2  s  .  c  om

    // A skin can be loaded via JSON or defined programmatically, either is fine. Using a skin is optional but strongly
    // recommended solely for the convenience of getting a texture, region, etc as a drawable, tinted drawable, etc.
    skin = new Skin();

    // Generate a 1x1 white texture and store it in the skin named "white".
    Pixmap pixmap = new Pixmap(1, 1, Format.RGBA8888);
    pixmap.setColor(Color.WHITE);
    pixmap.fill();
    skin.add("white", new Texture(pixmap));

    // Store the default libgdx font under the name "default".
    skin.add("default", new BitmapFont());

    // Configure a TextButtonStyle and name it "default". Skin resources are stored by type, so this doesn't overwrite the font.
    TextButtonStyle textButtonStyle = new TextButtonStyle();
    textButtonStyle.up = skin.newDrawable("white", Color.DARK_GRAY);
    textButtonStyle.down = skin.newDrawable("white", Color.DARK_GRAY);
    //textButtonStyle.checked = skin.newDrawable("white", Color.BLUE);
    textButtonStyle.over = skin.newDrawable("white", Color.LIGHT_GRAY);
    textButtonStyle.font = skin.getFont("default");
    skin.add("default", textButtonStyle);

    Label.LabelStyle labelSty = new Label.LabelStyle();
    labelSty.font = skin.getFont("default");
    //labelSty.fontColor = Color.GREEN;
    skin.add("default", labelSty);

    WindowStyle ws = new Window.WindowStyle();
    ws.titleFont = new BitmapFont();
    ws.background = skin.newDrawable("white", Color.BLACK);
    skin.add("default", ws);

    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/Zig.ttf"));

    FreeTypeFontParameter parameter = new FreeTypeFontParameter();
    parameter.size = 25;
    gameFont = generator.generateFont(parameter);

    FreeTypeFontParameter parameter2 = new FreeTypeFontParameter();
    parameter2.size = 100;
    parameter2.color = Color.GREEN;
    solvedFont = generator.generateFont(parameter2);
    generator.dispose();

    FileHandle blue, n1, n2, n3, n4, n5, n6, n7, n8, solveUp, solveDown;
    if (Gdx.app.getType() == ApplicationType.Desktop) {
        blue = Gdx.files.internal("icons64px/blue-square.png");
        n1 = Gdx.files.internal("icons64px/Number-1-icon.png");
        n2 = Gdx.files.internal("icons64px/Number-2-icon.png");
        n3 = Gdx.files.internal("icons64px/Number-3-icon.png");
        n4 = Gdx.files.internal("icons64px/Number-4-icon.png");
        n5 = Gdx.files.internal("icons64px/Number-5-icon.png");
        n6 = Gdx.files.internal("icons64px/Number-6-icon.png");
        n7 = Gdx.files.internal("icons64px/Number-7-icon.png");
        n8 = Gdx.files.internal("icons64px/Number-8-icon.png");
        solveUp = blue;
        solveDown = blue;
    } else {
        blue = Gdx.files.internal("icons256px/blue-circle.png");
        n1 = Gdx.files.internal("icons256px/Number-1-icon.png");
        n2 = Gdx.files.internal("icons256px/Number-2-icon.png");
        n3 = Gdx.files.internal("icons256px/Number-3-icon.png");
        n4 = Gdx.files.internal("icons256px/Number-4-icon.png");
        n5 = Gdx.files.internal("icons256px/Number-5-icon.png");
        n6 = Gdx.files.internal("icons256px/Number-6-icon.png");
        n7 = Gdx.files.internal("icons256px/Number-7-icon.png");
        n8 = Gdx.files.internal("icons256px/Number-8-icon.png");
        solveUp = Gdx.files.internal("icons256px/Box_Green.png");
        solveDown = Gdx.files.internal("icons256px/rectangle_green.png");
    }
    Texture bSquare = new Texture(blue);
    Texture n1T = new Texture(n1);
    Texture n2T = new Texture(n2);
    Texture n3T = new Texture(n3);
    Texture n4T = new Texture(n4);
    Texture n5T = new Texture(n5);
    Texture n6T = new Texture(n6);
    Texture n7T = new Texture(n7);
    Texture n8T = new Texture(n8);

    TextureRegion bSquareReg = new TextureRegion(bSquare);
    TextureRegion n1Reg = new TextureRegion(n1T);
    TextureRegion n2Reg = new TextureRegion(n2T);
    TextureRegion n3Reg = new TextureRegion(n3T);
    TextureRegion n4Reg = new TextureRegion(n4T);
    TextureRegion n5Reg = new TextureRegion(n5T);
    TextureRegion n6Reg = new TextureRegion(n6T);
    TextureRegion n7Reg = new TextureRegion(n7T);
    TextureRegion n8Reg = new TextureRegion(n8T);

    TextureRegionDrawable solveDUp = new TextureRegionDrawable(new TextureRegion(new Texture(solveUp)));
    TextureRegionDrawable solveDDown = new TextureRegionDrawable(new TextureRegion(new Texture(solveDown)));
    ImageTextButton.ImageTextButtonStyle tbSty = new ImageTextButton.ImageTextButtonStyle(solveDUp, solveDDown,
            solveDUp, gameFont);
    skin.add("default", tbSty);

    ImageButtonStyle bSquareSty = new ImageButtonStyle();
    bSquareSty.imageUp = new TextureRegionDrawable(bSquareReg);
    bSquareSty.imageDown = new TextureRegionDrawable(bSquareReg);

    ImageButtonStyle n1Sty = new ImageButtonStyle();
    n1Sty.imageUp = new TextureRegionDrawable(n1Reg);
    n1Sty.imageDown = new TextureRegionDrawable(n1Reg);

    ImageButtonStyle n2Sty = new ImageButtonStyle();
    n2Sty.imageUp = new TextureRegionDrawable(n2Reg);
    n2Sty.imageDown = new TextureRegionDrawable(n2Reg);

    ImageButtonStyle n3Sty = new ImageButtonStyle();
    n3Sty.imageUp = new TextureRegionDrawable(n3Reg);
    n3Sty.imageDown = new TextureRegionDrawable(n3Reg);

    ImageButtonStyle n4Sty = new ImageButtonStyle();
    n4Sty.imageUp = new TextureRegionDrawable(n4Reg);
    n4Sty.imageDown = new TextureRegionDrawable(n4Reg);

    ImageButtonStyle n5Sty = new ImageButtonStyle();
    n5Sty.imageUp = new TextureRegionDrawable(n5Reg);
    n5Sty.imageDown = new TextureRegionDrawable(n5Reg);

    ImageButtonStyle n6Sty = new ImageButtonStyle();
    n6Sty.imageUp = new TextureRegionDrawable(n6Reg);
    n6Sty.imageDown = new TextureRegionDrawable(n6Reg);

    ImageButtonStyle n7Sty = new ImageButtonStyle();
    n7Sty.imageUp = new TextureRegionDrawable(n7Reg);
    n7Sty.imageDown = new TextureRegionDrawable(n7Reg);

    ImageButtonStyle n8Sty = new ImageButtonStyle();
    n8Sty.imageUp = new TextureRegionDrawable(n8Reg);
    n8Sty.imageDown = new TextureRegionDrawable(n8Reg);

    ImageButton b1 = new ImageButton(n1Sty);
    b1.addListener(new MyChangeListener(1));
    map.put(1, b1);

    ImageButton holeB = new ImageButton(bSquareSty);
    map.put(0, holeB);

    ImageButton ib = new ImageButton(n2Sty);
    ib.addListener(new MyChangeListener(2));
    map.put(2, ib);

    ImageButton b4 = new ImageButton(n3Sty);
    b4.addListener(new MyChangeListener(3));
    ImageButton b5 = new ImageButton(n4Sty);
    b5.addListener(new MyChangeListener(4));
    ImageButton b6 = new ImageButton(n5Sty);
    b6.addListener(new MyChangeListener(5));
    map.put(3, b4);
    map.put(4, b5);
    map.put(5, b6);

    ImageButton b7 = new ImageButton(n6Sty);
    b7.addListener(new MyChangeListener(6));
    ImageButton b8 = new ImageButton(n7Sty);
    b8.addListener(new MyChangeListener(7));
    ImageButton b9 = new ImageButton(n8Sty);
    b9.addListener(new MyChangeListener(8));
    map.put(6, b7);
    map.put(7, b8);
    map.put(8, b9);

    newGameB = new ImageTextButton("New Game", skin);
    newGameB.addListener(new NewGameListener());

    solveB = new ImageTextButton("Solve", skin);
    solveB.addListener(new MySolveListener());

    newGameBoard();

    //table.padTop(50);
    //table.padBottom(20);

    VerticalGroup vg = new VerticalGroup();
    //vg.padTop(50);
    vg.setFillParent(true);
    vg.addActor(newGameB);
    vg.addActor(table);
    vg.addActor(solveB);

    stage.addActor(vg);
}

From source file:com.game.libgdx.roguelikeengine.Credits.java

License:Open Source License

@Override
public void show() {
    //layout=new Layout();

    FileHandle fontFile = Gdx.files.internal("fonts/minecraftia.ttf");
    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile);
    spriteBatch = new SpriteBatch();
    //messagefont = new BitmapFont();
    messagefont = generator.generateFont(20); // px
    text = "CREDITS\nConcept & Programming: Ferran_Fabregas & Joshua_Byrom\nUI design: Manuela Sanfelix & Ferran_Fabregas\nTiles and sprites taken from http://opengameart.org/\n& http://animatedbattlers.wordpress.com &  http://www.pixeljoint.com \nReleased under GPL / Creative_Commons and copyrighted\nby their owners\nMusic from https://soundcloud.com/desperate-measurez/ \n& http://www.tannerhelland.com/music-directory/\nSound FX: http://www.freesound.org/\nFonts taken from http://www.fonts101.com/ & http://www.flamingtext.com/\nThanks to: Joseph Elliott.\nGame released under the terms of GNU GPL .";
    // create a fight message info screen 
    screentext = new PopupInfoText(0, 0, "UI/credits.png", Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    screentext.settextoffset((int) (Gdx.graphics.getHeight() * .1f), (int) (Gdx.graphics.getHeight() * .35f));

    screentext.addWordClickListener("Joshua_Byrom", new WordClickAction() {
        @Override// w  ww.  jav a  2  s  . co m
        public void onClicked(String word) {
            Gdx.net.openURI("http://www.joshbyrom.com");
        }
    });
    screentext.addWordClickListener("Ferran_Fabregas", new WordClickAction() {
        @Override
        public void onClicked(String word) {
            Gdx.net.openURI("http://www.ferranfabregas.info");
        }
    });

    screentext.addWordClickListener("http://www.pixeljoint.com", new WordClickAction() {
        @Override
        public void onClicked(String word) {
            Gdx.net.openURI("http://www.pixeljoint.com");
        }
    });
    screentext.addWordClickListener("http://opengameart.org/", new WordClickAction() {
        @Override
        public void onClicked(String word) {
            Gdx.net.openURI("http://www.opengameart.org");
        }
    });
    screentext.addWordClickListener("http://animatedbattlers.wordpress.com", new WordClickAction() {
        @Override
        public void onClicked(String word) {
            Gdx.net.openURI("http://animatedbattlers.wordpress.com");
        }
    });
    screentext.addWordClickListener("https://soundcloud.com/desperate-measurez/", new WordClickAction() {
        @Override
        public void onClicked(String word) {
            Gdx.net.openURI("https://soundcloud.com/desperate-measurez/");
        }
    });
    screentext.addWordClickListener("http://www.tannerhelland.com/music-directory/", new WordClickAction() {
        @Override
        public void onClicked(String word) {
            Gdx.net.openURI("http://www.tannerhelland.com/music-directory/");
        }
    });
    screentext.addWordClickListener("http://www.fonts101.com/", new WordClickAction() {
        @Override
        public void onClicked(String word) {
            Gdx.net.openURI("http://www.fonts101.com/");
        }
    });
    screentext.addWordClickListener("http://www.flamingtext.com/", new WordClickAction() {
        @Override
        public void onClicked(String word) {
            Gdx.net.openURI("http://www.flamingtext.com/");
        }
    });
    screentext.addWordClickListener("GPL", new WordClickAction() {
        @Override
        public void onClicked(String word) {
            Gdx.net.openURI("http://www.gnu.org/licenses/gpl.txt");
        }
    });
    screentext.addWordClickListener("http://www.freesound.org/", new WordClickAction() {
        @Override
        public void onClicked(String word) {
            Gdx.net.openURI("http://www.freesound.org/");
        }
    });
    screentext.addWordClickListener("GNU", new WordClickAction() {
        @Override
        public void onClicked(String word) {
            Gdx.net.openURI("http://www.gnu.org");
        }
    });

    screentext.addWordClickListener("Creative_Commons", new WordClickAction() {
        @Override
        public void onClicked(String word) {
            Gdx.net.openURI("http://creativecommons.org/");
        }
    });
    Gdx.input.setInputProcessor(this);
}