Search in sources :

Example 1 with FreeTypeFontLoaderParameter

use of com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader.FreeTypeFontLoaderParameter in project libgdx by libgdx.

the class FreeTypeFontLoaderTest method create.

@Override
public void create() {
    manager = new AssetManager();
    // set the loaders for the generator and the fonts themselves
    FileHandleResolver resolver = new InternalFileHandleResolver();
    manager.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver));
    manager.setLoader(BitmapFont.class, ".ttf", new FreetypeFontLoader(resolver));
    // load to fonts via the generator (implicitely done by the FreetypeFontLoader).
    // Note: you MUST specify a FreetypeFontGenerator defining the ttf font file name and the size
    // of the font to be generated. The names of the fonts are arbitrary and are not pointing
    // to a file on disk!
    FreeTypeFontLoaderParameter size1Params = new FreeTypeFontLoaderParameter();
    size1Params.fontFileName = "data/arial.ttf";
    size1Params.fontParameters.size = 10;
    manager.load("size10.ttf", BitmapFont.class, size1Params);
    FreeTypeFontLoaderParameter size2Params = new FreeTypeFontLoaderParameter();
    size2Params.fontFileName = "data/arial.ttf";
    size2Params.fontParameters.size = 20;
    manager.load("size20.ttf", BitmapFont.class, size2Params);
    // we also load a "normal" font generated via Hiero
    manager.load("data/default.fnt", BitmapFont.class);
    batch = new SpriteBatch();
}
Also used : FreeTypeFontLoaderParameter(com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader.FreeTypeFontLoaderParameter) AssetManager(com.badlogic.gdx.assets.AssetManager) InternalFileHandleResolver(com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver) FileHandleResolver(com.badlogic.gdx.assets.loaders.FileHandleResolver) InternalFileHandleResolver(com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver) FreeTypeFontGeneratorLoader(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGeneratorLoader) FreetypeFontLoader(com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 2 with FreeTypeFontLoaderParameter

use of com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader.FreeTypeFontLoaderParameter in project libgdx by libgdx.

the class APKExpansionTest method loadFont.

private void loadFont(AssetManager assetManager, String fontName, int size) {
    FreeTypeFontLoaderParameter param = new FreeTypeFontLoaderParameter();
    param.fontFileName = fontName;
    param.fontParameters.size = 12;
    param.fontParameters.genMipMaps = true;
    param.fontParameters.minFilter = TextureFilter.MipMapLinearLinear;
    param.fontParameters.magFilter = TextureFilter.Linear;
    assetManager.load(fontName + "size" + size + ".ttf", BitmapFont.class, param);
}
Also used : FreeTypeFontLoaderParameter(com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader.FreeTypeFontLoaderParameter)

Example 3 with FreeTypeFontLoaderParameter

use of com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader.FreeTypeFontLoaderParameter in project AmazingMaze by TheVirtualMachine.

the class Assets method getFont.

/**
	 * Return the given font, if it is loaded. The font will be lazily loaded if it is not loaded already.
	 *
	 * @param fontName the name of the font.
	 * @param fontSize the size of the font.
	 * @return the desired {@link BitmapFont}.
	 */
protected BitmapFont getFont(String fontName, int fontSize) {
    if (manager.containsAsset(fontName + fontSize + ".ttf")) {
        return manager.get(fontName + fontSize + ".ttf");
    }
    FreeTypeFontLoaderParameter fontParams = new FreeTypeFontLoaderParameter();
    fontParams.fontFileName = "fonts/" + fontName + ".ttf";
    float horizontalAdjust = Gdx.graphics.getWidth() / 1920f;
    float verticalAdjust = Gdx.graphics.getHeight() / 1080f;
    float totalAdjust = horizontalAdjust * verticalAdjust * 1.25f;
    float screenSize = Math.min(horizontalAdjust, Math.min(verticalAdjust, totalAdjust));
    fontParams.fontParameters.size = (int) (fontSize * Gdx.graphics.getDensity() * screenSize);
    manager.load(fontName + fontSize + ".ttf", BitmapFont.class, fontParams);
    manager.finishLoadingAsset(fontName + fontSize + ".ttf");
    return manager.get(fontName + fontSize + ".ttf");
}
Also used : FreeTypeFontLoaderParameter(com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader.FreeTypeFontLoaderParameter)

Aggregations

FreeTypeFontLoaderParameter (com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader.FreeTypeFontLoaderParameter)3 AssetManager (com.badlogic.gdx.assets.AssetManager)1 FileHandleResolver (com.badlogic.gdx.assets.loaders.FileHandleResolver)1 InternalFileHandleResolver (com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1 FreeTypeFontGeneratorLoader (com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGeneratorLoader)1 FreetypeFontLoader (com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader)1