List of usage examples for com.badlogic.gdx.graphics.g2d.freetype FreeTypeFontGenerator scaleForPixelHeight
public int scaleForPixelHeight(int height)
From source file:edu.lehigh.cse.lol.Media.java
License:Open Source License
/** * Get the font described by the file name and font size * * @param fontFileName The filename for the font. This should be in the android * project's assets, and should end in .ttf * @param fontSize The size to display * @return A font object that can be used to render text *//* w w w. ja v a 2 s . co m*/ static BitmapFont getFont(String fontFileName, int fontSize) { // we store fonts as their filename appended with their size String key = fontFileName + "--" + fontSize; // check if we've already got this font, return it if we do BitmapFont f = Lol.sGame.mMedia.mFonts.get(key); if (f != null) { // just to play it safe, make the font white... the caller can // change this f.setColor(1, 1, 1, 1); return f; } // Generate the font, save it, and return it // // NB: if this crashes, the user will get a reasonably good error // message FreeTypeFontParameter parameter = new FreeTypeFontParameter(); FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal(fontFileName)); parameter.size = fontSize; generator.scaleForPixelHeight(fontSize); parameter.minFilter = Texture.TextureFilter.Linear; parameter.magFilter = Texture.TextureFilter.Linear; f = generator.generateFont(parameter); generator.dispose(); Lol.sGame.mMedia.mFonts.put(key, f); return f; }