public ChatMessage(String sender, String message) { super(skin); // debugAll(); FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/DroidSans.ttf")); FreeTypeFontParameter parameter = new FreeTypeFontParameter(); parameter.size = 17; parameter.minFilter = Texture.TextureFilter.Linear; parameter.magFilter = Texture.TextureFilter.Linear; final Label.LabelStyle labelStyle = skin.get("chat-sender", Label.LabelStyle.class); labelStyle.font = generator.generateFont(parameter); this.sender = new Label(sender, labelStyle); this.message = new Label(message, skin.get("chat-message", Label.LabelStyle.class)); this.message.setWrap(true); add(this.sender).fillX().expandX(); row(); add(this.message).fillX().expandX(); generator.dispose(); // don't forget to dispose to avoid memory leaks! }
public static BitmapFont createFont(String fontPath, int size, Color color, Color borderColor, int borderWidth) { // load font FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.absolute(fontPath)); FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); // https://github.com/libgdx/libgdx/wiki/Gdx-freetype parameter.size = size; parameter.borderColor = borderColor; parameter.borderWidth = borderWidth; parameter.color = color; BitmapFont font48 = generator.generateFont(parameter); generator.dispose(); return font48; }
public static BitmapFont createFont(FileHandle fileHandle, int size, Color color, Color borderColor, int borderWidth) { // load font FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fileHandle); FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); // https://github.com/libgdx/libgdx/wiki/Gdx-freetype parameter.size = size; parameter.borderColor = borderColor; parameter.borderWidth = borderWidth; parameter.color = color; BitmapFont font48 = generator.generateFont(parameter); generator.dispose(); return font48; }
private void loadAssets() { InternalFileHandleResolver fileHandler = new InternalFileHandleResolver(); assetManager = new AssetManager(fileHandler); assetManager.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(fileHandler)); assetManager.load(SKIN_PATH, Skin.class); assetManager.load(MASTER_PATH, TextureAtlas.class); assetManager.load(FONT_NORMAL_PATH, FreeTypeFontGenerator.class); assetManager.load(FONT_BOLD_PATH, FreeTypeFontGenerator.class); assetManager.load(MUSIC_PATH, Music.class); assetManager.load(MAIN_MENU_MUSIC_PATH, Music.class); assetManager.load(GOOD_PATH, Sound.class); assetManager.load(HALF_PATH, Sound.class); assetManager.load(BAD_PATH, Sound.class); assetManager.finishLoading(); }
private void initUtils() { //init camera & viewport camera = new OrthographicCamera(); viewport = new StretchViewport(Polymorph.WORLD_WIDTH, Polymorph.WORLD_HEIGHT, camera); viewport.apply(true); camera.update(); //init sprite batch batch = new SpriteBatch(); batch.setProjectionMatrix(camera.combined); //init font FreeTypeFontGenerator fontGenerator = polymorph.getAssetManager().get(Polymorph.FONT_BOLD_PATH, FreeTypeFontGenerator.class); FreeTypeFontParameter fontSettings = new FreeTypeFontParameter(); fontSettings.size = 80; fontSettings.minFilter = TextureFilter.Linear; fontSettings.magFilter = TextureFilter.Linear; font = fontGenerator.generateFont(fontSettings); }
private static BitmapFont createFont(int fontSize , Fonts type) { FileHandle fontFile = null; switch(type){ case HEMI_HEAD: fontFile = Gdx.files.internal("fonts/HEMIHEAD.TTF"); break; case VERA: fontFile = Gdx.files.internal("fonts/Vera.ttf"); break; case VERA_BD: fontFile = Gdx.files.internal("fonts/VeraBd.ttf"); break; default: break; } FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile); FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); parameter.size = fontSize; BitmapFont font = generator.generateFont(parameter); generator.dispose(); return font; }
/** * 初始游戏字体 */ private void initFont() { FreetypeFontLoader.FreeTypeFontLoaderParameter fontConfig = new FreetypeFontLoader.FreeTypeFontLoaderParameter(); fontConfig.fontFileName = "font.ttf"; fontConfig.fontParameters.size = 22; FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("font.ttf")); FreeTypeFontGenerator.FreeTypeFontParameter parameters = new FreeTypeFontGenerator.FreeTypeFontParameter(); parameters.size = 18; f18 = generator.generateFont(parameters); parameters.size = 22; f22 = generator.generateFont(parameters); parameters.size = 24; f24 = generator.generateFont(parameters); generator.dispose(); }
public void create() { batch = new SpriteBatch(); font = new BitmapFont(); FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("gfx/fonts/roboto-regular.ttf")); FreeTypeFontParameter parameter = new FreeTypeFontParameter(); parameter.size = 16; font = generator.generateFont(parameter); // font size 16 pixels generator.dispose(); music = Gdx.audio.newMusic(Gdx.files.internal("sounds/main.ogg")); music.setLooping(true); music.play(); this.setScreen(new MenuScreen(this)); }
private HUD() { stage = new Stage(new FitViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight())); stage.addListener(inputListener = new InputListener(true)); Gdx.input.setInputProcessor(stage); fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("font.ttf")); skin = new Skin(Gdx.files.internal("uiskin.json")); createFlashImage(); createProgressLabel(); createInfoLabel(); createLevelCompleteUI(); hideLevelComplete(); if (Globals.isMobile()) { createMobileButtons(); } }
private void createReplayButton() { FreeTypeFontGenerator.FreeTypeFontParameter fontParam = new FreeTypeFontGenerator.FreeTypeFontParameter(); fontParam.size = Gdx.graphics.getWidth() / 8; TextButton.TextButtonStyle style = new TextButton.TextButtonStyle(); style.font = fontGenerator.generateFont(fontParam); style.fontColor = Color.WHITE; final TextButton playButton = new TextButton("REPLAY?", skin); playButton.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); playButton.setPosition(0, 0); playButton.setStyle(style); playButton.addListener(new ClickListener() { @Override public void touchUp(InputEvent event, float x, float y, int pointer, int button) { game.setScreen(new Driver(game)); } }); stage.addActor(playButton); }
public Font(String filePath, int size, Color color, boolean filter) { // ASSIGN ATTRIBUTES this.size = size; this.color = color; // GENERATE FONT generator = new FreeTypeFontGenerator(Gdx.files.internal(filePath)); if (filter) // IF FILTER ENABLED { parameter.genMipMaps = true; parameter.minFilter = Texture.TextureFilter.Linear; parameter.magFilter = Texture.TextureFilter.Linear; } parameter.size = size; parameter.color = color; font = generator.generateFont(parameter); generator.dispose(); }
private Drawable getFontIcon(FileChooser.FileItem item) { FileHandle fileHandle = item.getFile(); BitmapFont bitmapFont; try { FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fileHandle); FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); parameter.size = CB.getScaledInt(50); parameter.characters = SkinFont.DEFAULT_CHARACTER; parameter.genMipMaps = true; parameter.minFilter = Texture.TextureFilter.MipMapNearestNearest; bitmapFont = generator.generateFont(parameter); } catch (Exception e) { return getImageIcon(item); } Drawable drawable = new BitmapFontDrawable(bitmapFont, item.getFile().nameWithoutExtension()); return drawable; }
public Font(final Application APP, String fileName, String filePath, int size, boolean filter) { // ASSIGN ATTRIBUTES this.size = size; FreetypeFontLoader.FreeTypeFontLoaderParameter parameter = new FreetypeFontLoader.FreeTypeFontLoaderParameter(); FileHandleResolver resolver = new InternalFileHandleResolver(); APP.assets.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver)); APP.assets.setLoader(BitmapFont.class, ".otf", new FreetypeFontLoader(resolver)); // GENERATE FONT if (filter) // IF FILTER ENABLED { parameter.fontParameters.genMipMaps = true; parameter.fontParameters.minFilter = Texture.TextureFilter.Linear; parameter.fontParameters.magFilter = Texture.TextureFilter.Linear; } parameter.fontFileName = filePath; parameter.fontParameters.size = size; APP.assets.load(fileName, BitmapFont.class, parameter); APP.assets.finishLoading(); font = APP.assets.get(fileName, BitmapFont.class); }
public MenuScreen(TTmath game, OrthoCamera camera, SpriteBatch sb){ this.camera = camera; this.game = game; this.sb = sb; game.resetScore(); game.manageScreens(this); // game.mainMenuScreen = this; createStage(); FreeTypeFontGenerator TEXT_8BIT = new FreeTypeFontGenerator(Gdx.files.internal("resources/Minecraftia-Regular.ttf")); font = createFont(TEXT_8BIT, 25); TEXT_8BIT.dispose(); createButton(); }
private void createDisplay() { if(created){ return; } FreeTypeFontGenerator TEXT_8BIT = new FreeTypeFontGenerator(Gdx.files.internal("resources/Minecraftia-Regular.ttf")); createFont(TEXT_8BIT, 25); TEXT_8BIT.dispose(); createQuestions(); createStage(); createLabel(); createButton(); createScoreLabel(); createIncorrectLabel(); created = true; game.problemScreen = this; }
public GameOverScreen(TTmath game, OrthoCamera camera, SpriteBatch sb) { this.game = game; this.camera = camera; this.sb = sb; // game.gameOver = this; game.setScreen(this); Gdx.input.setCatchBackKey(true); FreeTypeFontGenerator TEXT_8BIT = new FreeTypeFontGenerator(Gdx.files.internal("resources/Minecraftia-Regular.ttf")); createFont(TEXT_8BIT, 25); TEXT_8BIT.dispose(); createStage(); createLabel(); createButton(); }
public HighScoreScreen(TTmath game, OrthoCamera camera, SpriteBatch sb){ this.game = game; this.camera = camera; this.sb = sb; gameScore = game.getScore(); jScore = new JsonScore(); ArrayList<Score> score = jScore.getHighScoreList(); FreeTypeFontGenerator TEXT_8BIT = new FreeTypeFontGenerator(Gdx.files.internal("resources/Minecraftia-Regular.ttf")); createFont(TEXT_8BIT, 25); TEXT_8BIT.dispose(); createStage(); createLabel("High Scores!", true); for(int i = 0; i < score.size(); i++){ table.row(); createLabel(score.get(i).getUser(),false); createLabel(Integer.toString(score.get(i).getScore()),false); } createButon(); }
public LevelMenuScreen(TTmath game, OrthoCamera camera, SpriteBatch sb){ this.camera = camera; this.game = game; this.sb = sb; game.manageScreens(this); // game.levelMenu = this; Gdx.input.setCatchBackKey(true); FreeTypeFontGenerator TEXT_8BIT = new FreeTypeFontGenerator(Gdx.files.internal("resources/Minecraftia-Regular.ttf")); createFont(TEXT_8BIT, 25); TEXT_8BIT.dispose(); createStage(); createLabel(); createButton(); }
public void init(){ table = new Table(); FreeTypeFontGenerator ftfg = new FreeTypeFontGenerator(Assets.KENPIXEL_BLOCKS); FreeTypeFontGenerator.FreeTypeFontParameter ftfp = new FreeTypeFontGenerator.FreeTypeFontParameter(); ftfp.size = 24; //the size can be changed later ftfp.color = new Color(0.42f,0.64f,0.62f,1); BitmapFont font = ftfg.generateFont(ftfp); Label.LabelStyle style = new Label.LabelStyle(); style.font=font; capacity = new Label("0",style); currentFlow = new Label("0",style); table.add(currentFlow).padRight(2f).center(); table.add(capacity).padLeft(2f).center(); table.setPosition(posX*64+32,posY*64+32); }
static UnderlineMetrics deriveUnderlineMetrics(FreeTypeFontGenerator generator, int size) { try { // Size metrics aren't publicly accessible (as of 1.9.3). (Ab)use reflection to gain access. Field faceField = FreeTypeFontGenerator.class.getDeclaredField("face"); faceField.setAccessible(true); Face face = (Face)faceField.get(generator); SizeMetrics sizeMetrics = face.getSize().getMetrics(); int yScale = sizeMetrics.getYscale(); // 16.16 fixed point float position = FreeType.toInt(face.getUnderlinePosition() * yScale >> 16); float thickness = FreeType.toInt(face.getUnderlineThickness() * yScale >> 16); return new UnderlineMetrics(position, thickness); } catch (Exception e) { LOG.error("Error fetching FreeType underline metrics", e); } // Return a reasonable default return UnderlineMetrics.defaultInstance(size); }
private void initFonts() { FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/roboto.ttf")); FreeTypeFontGenerator.FreeTypeFontParameter params = new FreeTypeFontGenerator.FreeTypeFontParameter(); params.size = 48; params.color = new Color(.25f, .25f, .85f, 1); params.shadowOffsetX = 0; params.shadowOffsetY = 0; params.shadowColor = Color.BLACK; titleFont = generator.generateFont(params); params = new FreeTypeFontGenerator.FreeTypeFontParameter(); params.size = 32; params.color = Color.BLACK; buttonFont = generator.generateFont(params); generator.dispose(); }
public GridMapRenderer() { // load font from a .ttf file try { FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("data/font/jgfont.ttf")); FreeTypeFontParameter fp = new FreeTypeFontParameter(); fp.size = 9; font9 = generator.generateFont(fp); generator.dispose(); shapeRenderer = RTSGame.game.cameraShapeRenderer; fontBatch = new SpriteBatch(); } catch (Exception e) { e.printStackTrace(); } }
public QuadTreeRenderer() { // load font from a .ttf file try { FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("data/font/jgfont.ttf")); FreeTypeFontParameter fp = new FreeTypeFontParameter(); fp.size = 9; font9 = generator.generateFont(fp); generator.dispose(); shapeRenderer = RTSGame.game.cameraShapeRenderer; fontBatch = new SpriteBatch(); } catch (Exception e) { e.printStackTrace(); } }
@Override public void create () { boolean flip = false; batch = new SpriteBatch(); if (flip) { OrthographicCamera cam = new OrthographicCamera(); cam.setToOrtho(flip); cam.update(); batch.setProjectionMatrix(cam.combined); } font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), flip); FileHandle fontFile = Gdx.files.internal("data/arial.ttf"); FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile); FreeTypeFontParameter parameter = new FreeTypeFontParameter(); parameter.size = 15; parameter.flip = flip; parameter.genMipMaps = true; FreeTypeBitmapFontData fontData = generator.generateData(parameter); ftFont = generator.generateFont(parameter); generator.dispose(); }
public void render () { if (Gdx.input.justTouched()) { for (int i = 0; i < 10; i++) { if (font != null) { font.dispose(); } FileHandle fontFile = Gdx.files.internal("data/arial.ttf"); FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile); FreeTypeFontParameter parameter = new FreeTypeFontParameter(); parameter.size = 15; font = generator.generateFont(parameter); generator.dispose(); } for (int i = 0; i < 10; i++) System.gc(); Gdx.app.log("FreeTypeDisposeTest", "generated 10 fonts"); Gdx.app.log("FreeTypeDisposeTest", Gdx.app.getJavaHeap() + ", " + Gdx.app.getNativeHeap()); } }
public static void loadFonts(){ FreeTypeFontGenerator font_gen = new FreeTypeFontGenerator(Gdx.files.internal("font.ttf")); FreeTypeFontParameter parameter = new FreeTypeFontParameter(); parameter.size = 100; font100 = font_gen.generateFont(parameter); font100.getRegion().getTexture().setFilter(TextureFilter.Linear,TextureFilter.Linear); font100.setColor(Color.BLACK); font100.setScale(1, -1); parameter.size = 75; font75 = font_gen.generateFont(parameter); font75.getRegion().getTexture().setFilter(TextureFilter.Linear,TextureFilter.Linear); font75.setColor(Color.BLACK); font75.setScale(1, -1); parameter.size = 250; font250 = font_gen.generateFont(parameter); font250.getRegion().getTexture().setFilter(TextureFilter.Linear,TextureFilter.Linear); font250.setColor(Color.BLACK); font250.setScale(1, -1); font_gen.dispose(); }
/** * Convenience method for generating a font, and then writing the fnt and * png files. Writing a generated font to files allows the possibility of * only generating the fonts when they are missing, otherwise loading from a * previously generated file. * * @param fontFile * @param fontSize * @param destiny */ private void generateFiles(String fontName, FileHandle fontFile, int fontSize, int pageWidth, int pageHeight, FileHandle destiny) { FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile); PixmapPacker packer = new PixmapPacker(pageWidth, pageHeight, Pixmap.Format.RGBA8888, 2, false); FreeTypeFontParameter param = new FreeTypeFontParameter(); param.packer = packer; param.characters = FreeTypeFontGenerator.DEFAULT_CHARS; param.size = fontSize; param.flip = false; FreeTypeFontGenerator.FreeTypeBitmapFontData fontData = generator .generateData(param); saveFontToFile(fontData, fontSize, fontName, packer, destiny); generator.dispose(); packer.dispose(); }
/** * Liefert BitmapFont, die gut geeignet sind fuer Ueberschriften. * * @param size * vom Typ FontSize umd die Groesse der Schriftart zu definieren * @return b BitmapFont */ @SuppressWarnings("deprecation") public static BitmapFont getHeadlineFont(final FontSize size) { if (headlineFonts == null){ headlineFonts = new BitmapFont[FontSize.values().length]; } if (headlineFonts[size.ordinal()] == null) { int startIdx = directoryFonts.indexOf(FOLDERNAME_FONTS); String relativeFilePath = directoryFonts.substring(startIdx, directoryFonts.length()).replace("\\", "/") + FILESEPARATOR + "headlinefont/GetVoIP Grotesque.ttf"; FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal(relativeFilePath)); headlineFonts[size.ordinal()] = generator.generateFont(size.getVal()); } headlineFonts[size.ordinal()].setScale(1f); return headlineFonts[size.ordinal()]; }
/** * Liefert BitmapFont, die gut geeignet sind fuer Texte. * * @param size * vom Typ FontSize umd die Groesse der Schriftart zu definieren * @return b BitmapFont */ @SuppressWarnings("deprecation") public static BitmapFont getTextFont(final FontSize size) { if (textFonts == null){ textFonts = new BitmapFont[FontSize.values().length]; } if (textFonts[size.ordinal()] == null) { int startIdx = directoryFonts.indexOf(FOLDERNAME_FONTS); String relativeFilePath = directoryFonts.substring(startIdx, directoryFonts.length()).replace("\\", "/") + FILESEPARATOR + "textfont/Grundschrift-Bold.ttf"; FreeTypeFontGenerator gen = new FreeTypeFontGenerator(Gdx.files.internal(relativeFilePath)); textFonts[size.ordinal()] = gen.generateFont(size.getVal()); gen.dispose(); } textFonts[size.ordinal()].setScale(1f); return textFonts[size.ordinal()]; }
/** * Erzeugt den LadeButtonText. */ private void createButton() { Drawable drawable = new TextureRegionDrawable((new TextureRegion(new Texture( Gdx.files.internal("splashscreen/buttonBackground.png"))))); FreeTypeFontGenerator gen = new FreeTypeFontGenerator( Gdx.files.internal("fonts/textfont/Grundschrift-Bold.ttf")); FreeTypeFontParameter frontPara = new FreeTypeFontParameter(); frontPara.size = 40; BitmapFont b = gen.generateFont(frontPara); gen.dispose(); ImageTextButtonStyle imageButtonStyle = new ImageTextButton.ImageTextButtonStyle(); imageButtonStyle.down = drawable; imageButtonStyle.up = drawable; imageButtonStyle.font = b; imageButtonStyle.fontColor = Color.valueOf("877E6A"); textContent = new ImageTextButton("Lade... : ", imageButtonStyle); }
/** * Gets a font from the cache if it exists otherwise creates it based on the following arguments * @param fontID id of the font, must be in the format: {ttf-file-name}-{size} * @param defaultPath path to the ttf file used to create the font if it doesn't exist * @return the BitmapFont or null if it doesn't exist and no path is provided */ public static BitmapFont getFont(String fontID, String defaultPath) { if (fonts.containsKey(fontID)) { return fonts.get(fontID); } else if (defaultPath != null) { FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal(defaultPath)); FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); parameter.size = Integer.parseInt(fontID.split("-")[1]); BitmapFont font = generator.generateFont(parameter); generator.dispose(); fonts.put(fontID, font); return font; } return null; }
public void load(AssetManager assetManager) { background.load(assetManager); fish1.load(assetManager); fish2.load(assetManager); fish3.load(assetManager); fish4.load(assetManager); fish5.load(assetManager); fish6.load(assetManager); fish7.load(assetManager); fish8.load(assetManager); fish9.load(assetManager); fish10.load(assetManager); assetManager.load(AppConst.EXIT_BUTTON_TEXTURE, Texture.class); assetManager.load(AppConst.ADD_FISH_BUTTON_TEXTURE, Texture.class); assetManager.load(AppConst.SELECT_FISH_BUTTONS_TEXTURE, Texture.class); assetManager.load(AppConst.SELECT_TRAJECTORY_TEXTURE, Texture.class); FileHandleResolver resolver = new InternalFileHandleResolver(); assetManager.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver)); assetManager.setLoader(BitmapFont.class, ".ttf", new FreetypeFontLoader(resolver)); FreeTypeFontLoaderParameter size1Params = new FreeTypeFontLoaderParameter(); size1Params.fontFileName = AppConst.DEFAUFT_FONT; size1Params.fontParameters.size = AppConst.KEY_FONT_SIZE; assetManager.load(AppConst.KEY_FONT_NAME, BitmapFont.class, size1Params); }
/** * Retrieve the desired font and size (may load the font * if not cached). * * @param alias * @param size * @return the font */ private BitmapFont getFont(String alias, int size) { BitmapFont font = null; String mask = alias + ":" + size; if(this.fonts.containsKey(mask)) { font = this.fonts.get(mask); } else if(this.generators.containsKey(alias)) { FreeTypeFontParameter params = new FreeTypeFontParameter(); params.size = size; params.characters = FreeTypeFontGenerator.DEFAULT_CHARS; params.flip = true; params.magFilter = TextureFilter.Linear; params.minFilter = TextureFilter.Linear; font = this.generators.get(alias).generateFont(params); this.fonts.put(mask, font); } return font; }
public Assets() { textureParameter = new TextureLoader.TextureParameter(); //textureParameter.genMipMaps = true; textureParameter.magFilter = Texture.TextureFilter.Linear; textureParameter.minFilter = Texture.TextureFilter.Linear; resolver = new MaryoFileHandleResolver(); manager = new AssetManager(resolver); particleEffectParameter = new ParticleEffectLoader.ParticleEffectParameter(); particleEffectParameter.imagesDir = resolver.resolve("data/animation/particles"); // set the loaders for the generator and the fonts themselves manager.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver)); manager.setLoader(BitmapFont.class, ".ttf", new FreetypeFontLoader(resolver)); manager.setLoader(ParticleEffect.class, ".p", new ParticleEffectLoader(resolver)); manager.setLoader(Sound.class, ".mp3", new SoundLoader(new InternalFileHandleResolver())); manager.setLoader(Music.class, ".mp3", new MusicLoader(new InternalFileHandleResolver())); }
/** Convenience method for generating a font, and then writing the fnt and png files. * Writing a generated font to files allows the possibility of only generating the fonts when they are missing, otherwise * loading from a previously generated file. * @param fontFile * @param fontSize */ private BitmapFont generateFontWriteFiles(String fontName, FileHandle fontFile, int fontSize, int pageWidth, int pageHeight) { FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile); PixmapPacker packer = new PixmapPacker(pageWidth, pageHeight, Pixmap.Format.RGBA8888, 2, false); FreeTypeFontGenerator.FreeTypeBitmapFontData fontData = generator.generateData(fontSize, FreeTypeFontGenerator.DEFAULT_CHARS, false, packer); Array<PixmapPacker.Page> pages = packer.getPages(); TextureRegion[] texRegions = new TextureRegion[pages.size]; for (int i=0; i<pages.size; i++) { PixmapPacker.Page p = pages.get(i); Texture tex = new Texture(new PixmapTextureData(p.getPixmap(), p.getPixmap().getFormat(), false, false, true)) { @Override public void dispose () { super.dispose(); getTextureData().consumePixmap().dispose(); } }; tex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest); texRegions[i] = new TextureRegion(tex); } BitmapFont font = new BitmapFont(fontData, texRegions, false); saveFontToFile(font, fontSize, fontName, packer); generator.dispose(); packer.dispose(); return font; }
@Override public void show() { camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); camera.setToOrtho(false); camera.position.x = Gdx.graphics.getWidth() / 2; camera.position.y = Gdx.graphics.getHeight() / 2; //Get the font. FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("mainmenu/new/kenvector_future.ttf")); FreeTypeFontParameter parameter = new FreeTypeFontParameter(); parameter.size = 15; font = generator.generateFont(parameter); generator.dispose(); System.gc(); //We no longer need the Main Menu stuff, we should clean it up. }
public static BitmapFont getFont() { if (font == null) { FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("VCROSDMono.ttf")); FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); parameter.size = 30; parameter.borderWidth = 1; parameter.color = Color.BLACK; parameter.shadowOffsetX = 2; parameter.shadowOffsetY = 2; parameter.shadowColor = new Color(0, 1f, 0, 0.5f); font = generator.generateFont(parameter); generator.dispose(); } return font; }
private BitmapFont getFont() { FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/DroidSans.ttf")); FreeTypeFontParameter parameter = new FreeTypeFontParameter(); parameter.size = 20; BitmapFont font = generator.generateFont(parameter); generator.dispose(); return font; }
/** * Generate new bitmap font. * * @param fontDescriptor Descriptor object describing font properties. * @return Newly generated bitmap font. */ private static BitmapFont generateFont(FontDescriptor fontDescriptor) { FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal(fontDescriptor.getFontFilename())); FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); parameter.color = fontDescriptor.getForegroundColor(); parameter.size = fontDescriptor.getFontSize(); parameter.borderWidth = fontDescriptor.getBorderWidth(); parameter.borderColor = fontDescriptor.getBorderColor(); parameter.borderStraight = fontDescriptor.isStraightBorderUsed(); BitmapFont font = generator.generateFont(parameter); generator.dispose(); return font; }
public StatusScreen(CaramelosGame game, boolean victory,int level) { this.game = game; this.victory = victory; this.level = level; Preferences prefs = Gdx.app.getPreferences("My Preferences"); flagSound = prefs.getBoolean("sound"); if(victory) mp3Music = Gdx.audio.newMusic(Gdx.files.internal("Music/Victory.mp3")); else{ mp3Music = Gdx.audio.newMusic(Gdx.files.internal("Music/GameOver.mp3")); } mp3Music.setLooping(true); if(flagSound){ mp3Music.play(); } FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("Vollkorn/Vollkorn-Regular.ttf")); FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); parameter.size = 24; font12 = generator.generateFont(parameter); // font size 12 pixels generator.dispose(); // don't forget to dispose to avoid memory leaks! FileHandle baseFileHandle = Gdx.files.internal("Messages/menus"); String localeLanguage =java.util.Locale.getDefault().toString(); Locale locale = new Locale(localeLanguage); I18NBundle myBundle = I18NBundle.createBundle(baseFileHandle, locale,"UTF-8"); menulevel = myBundle.get("menulevel"); menuvictory = myBundle.get("menuvictory"); menuchampion = myBundle.get("menuchampion"); menucontinue = myBundle.get("menucontinue"); menugameover = myBundle.get("menugameover"); }