public void updateFont(String newChars) { parameter.characters = parameter.characters + newChars; font = generator.generateFont(parameter); // generator.generateData(parameter); BitmapFont oldFont = this.getStyle().font; this.getStyle().font = this.getStyle().messageFont = font; oldFont.dispose(); updateDisplayText(); }
/** * 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 AnimvsBitmapFont generateFontWriteFiles( String fontName, FileHandle fontFile, int fontSize, int pageWidth, int pageHeight, String characters) { FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile); PixmapPacker packer = new PixmapPacker(pageWidth, pageHeight, Pixmap.Format.RGBA8888, 1, false); FreeTypeFontParameter fontParameters = new FreeTypeFontParameter(); fontParameters.characters = characters; fontParameters.size = fontSize; fontParameters.minFilter = TextureFilter.Nearest; fontParameters.magFilter = TextureFilter.Linear; fontParameters.packer = packer; // FreeTypeFontGenerator.FreeTypeBitmapFontData fontData = // generator.generateData(fontSize, characters, false, packer); FreeTypeFontGenerator.FreeTypeBitmapFontData fontData = generator.generateData(fontParameters); Array<PixmapPacker.Page> pages = packer.getPages(); Array<TextureRegion> texRegions = new Array<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.add(new TextureRegion(tex)); } AnimvsBitmapFont font = new AnimvsBitmapFont(fontData, texRegions, true); setDefaultFilter(font); saveFontToFile(font, fontSize, fontName, packer); generator.dispose(); packer.dispose(); return font; }
public GameState(Specular game) { super(game); // Loading map texture from a internal directory Texture mapTexture = new Texture(Gdx.files.internal("graphics/game/packed/Level.png")); Texture shockLight = new Texture(Gdx.files.internal("graphics/game/packed/ShockLight.png")); Texture parallax = new Texture(Gdx.files.internal("graphics/game/packed/Parallax.png")); // Loading gameover textures gameOverTex = new Texture(Gdx.files.internal("graphics/game/packed/Background.png")); newHighscore = new Texture(Gdx.files.internal("graphics/menu/gameover/New Highscore.png")); // Loading pause menu textures pauseTex = new Texture(Gdx.files.internal("graphics/menu/pausemenu/Pause.png")); greyPixel = new Texture(Gdx.files.internal("graphics/menu/pausemenu/Grey Pixel.png")); textureAtlas = new TextureAtlas(Gdx.files.internal("graphics/game/packed/Specular.atlas")); // Loading HUD hud = new HUD(this); // Initializing map handler for handling many maps mapHandler = new MapHandler(); mapHandler.addMap( "Map", mapTexture, shockLight, parallax, mapTexture.getWidth(), mapTexture.getHeight(), this); currentMap = mapHandler.getMap("Map"); clipBounds = new Rectangle(0, 0, currentMap.getWidth(), currentMap.getHeight()); // Initializing font FreeTypeFontGenerator fontGen = new FreeTypeFontGenerator(Gdx.files.internal("fonts/Battlev2l.ttf")); FreeTypeFontParameter ftfp = new FreeTypeFontParameter(); ftfp.size = 96; // MAX SIZE ftfp.characters = "1234567890,"; gameOverScoreFont = fontGen.generateFont(ftfp); gameOverScoreFont.setColor(Color.RED); ftfp.characters = "1234567890,tapocniue"; // Characters for "Tap to continue" ftfp.size = 64; scoreFont = fontGen.generateFont(ftfp); scoreFont.setColor(Color.RED); ftfp.characters = "1234567890,x"; ftfp.size = 40; multiplierFont = fontGen.generateFont(ftfp); multiplierFont.setColor(Color.RED); // Tutorial (Must be initialized before fontGen.dispose()) tutorial = new Tutorial(this, fontGen); fontGen.dispose(); // Graphics Settings GfxSettings.init(); // Tutorial Tutorial.init(textureAtlas); // Initializing entities and analogstick statically Player.init(textureAtlas); Bullet.init(this); Particle.init(textureAtlas); UpgradeOrb.init(textureAtlas); EnemyWanderer.init(textureAtlas); EnemyCircler.init(textureAtlas); EnemyStriver.init(textureAtlas); EnemyBooster.init(textureAtlas); EnemyWorm.init(textureAtlas); EnemyVirus.init(textureAtlas); EnemyShielder.init(textureAtlas); EnemyExploder.init(textureAtlas); EnemyDasher.init(textureAtlas); EnemyTanker.init(textureAtlas); AnalogStick.init(hud); // Initializing power-ups AddLife.init(textureAtlas); BulletBurst.init(textureAtlas); FireRateBoost.init(textureAtlas); ScoreMultiplier.init(textureAtlas); ShieldPowerUp.init(textureAtlas); SlowdownEnemies.init(textureAtlas); BoardshockPowerUp.init(textureAtlas); Ricochet.init(textureAtlas); Repulsor.init(textureAtlas); LaserPowerup.init(textureAtlas); ShockWaveRenderer.init(textureAtlas); Laser.init(this); Swarm.init(textureAtlas); PDSPowerUp.init(textureAtlas); pss = new PlayerSpawnSystem(this); puss = new PowerUpSpawnSystem(this); pass = new ParticleSpawnSystem(this); oss = new OrbSpawnSystem(this); cs = new ComboSystem(); waveManager = new WaveManager(this); input = Gdx.input; }