Java Code Examples for com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator#FreeTypeFontParameter

The following examples show how to use com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator#FreeTypeFontParameter . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utility.java    From Norii with Apache License 2.0 5 votes vote down vote up
public static LabelStyle createLabelStyle(final String fontPath, final int size, final int borderWidth, final Color color, final int shadowX, final int shadowY) {
	final FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal(fontPath));
	final FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
	parameter.size = size;
	parameter.borderWidth = borderWidth;
	parameter.color = color;
	parameter.shadowOffsetX = shadowX;
	parameter.shadowOffsetY = shadowY;
	final BitmapFont font = generator.generateFont(parameter);
	final LabelStyle labelStyle = new LabelStyle();
	labelStyle.font = font;
	return labelStyle;
}
 
Example 2
Source File: SkinTextFont.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
public SkinTextFont(String fontpath, int cycle, int size, int shadow, StringProperty property) {
    	super(property);
    	try {
            generator = new FreeTypeFontGenerator(Gdx.files.internal(fontpath));
            parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
            parameter.characters = "";
//            this.setCycle(cycle);
            parameter.size = size;
            setShadowOffset(new Vector2(shadow, shadow));    		
    	} catch (GdxRuntimeException e) {
    		Logger.getGlobal().warning("Skin Font読み込み失敗");
    	}
    }
 
Example 3
Source File: Splash.java    From Skyland with MIT License 5 votes vote down vote up
private void addFonts() {
    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/forcedsquare.ttf"));
    FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
    parameter.size = Gdx.graphics.getHeight() / 15;
    Assets.menuSkin.add("font32", generator.generateFont(parameter));
    parameter.size = Gdx.graphics.getHeight() / 10;
    Assets.menuSkin.add("font64", generator.generateFont(parameter));
    parameter.size = Gdx.graphics.getHeight() / 25;
    Assets.menuSkin.add("console", generator.generateFont(parameter));
    generator.dispose();
}
 
Example 4
Source File: AndroidPlatformSupport.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BitmapFont getFont(int size, String text) {
	FreeTypeFontGenerator generator = getGeneratorForString(text);
	
	if (generator == null){
		return null;
	}
	
	if (!fonts.get(generator).containsKey(size)) {
		FreeTypeFontGenerator.FreeTypeFontParameter parameters = new FreeTypeFontGenerator.FreeTypeFontParameter();
		parameters.size = size;
		parameters.flip = true;
		parameters.borderWidth = parameters.size / 10f;
		parameters.renderCount = 3;
		parameters.hinting = FreeTypeFontGenerator.Hinting.None;
		parameters.spaceX = -(int) parameters.borderWidth;
		parameters.incremental = true;
		if (generator == basicFontGenerator){
			//if we're using latin/cyrillic, we can safely pre-generate some common letters
			//(we define common as >4% frequency in english)
			parameters.characters = "�etaoinshrdl";
		} else {
			parameters.characters = "�";
		}
		parameters.packer = packer;
		
		try {
			BitmapFont font = generator.generateFont(parameters);
			font.getData().missingGlyph = font.getData().getGlyph('�');
			fonts.get(generator).put(size, font);
		} catch ( Exception e ){
			Game.reportException(e);
			return null;
		}
	}
	
	return fonts.get(generator).get(size);
}
 
Example 5
Source File: DesktopPlatformSupport.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BitmapFont getFont(int size, String text) {
	FreeTypeFontGenerator generator = getGeneratorForString(text);
	
	if (generator == null){
		return null;
	}
	
	if (!fonts.get(generator).containsKey(size)) {
		FreeTypeFontGenerator.FreeTypeFontParameter parameters = new FreeTypeFontGenerator.FreeTypeFontParameter();
		parameters.size = size;
		parameters.flip = true;
		parameters.borderWidth = parameters.size / 10f;
		parameters.renderCount = 3;
		parameters.hinting = FreeTypeFontGenerator.Hinting.None;
		parameters.spaceX = -(int) parameters.borderWidth;
		parameters.incremental = true;
		if (generator == basicFontGenerator){
			//if we're using latin/cyrillic, we can safely pre-generate some common letters
			//(we define common as >4% frequency in english)
			parameters.characters = "�etaoinshrdl";
		} else {
			parameters.characters = "�";
		}
		parameters.packer = packer;
		
		try {
			BitmapFont font = generator.generateFont(parameters);
			font.getData().missingGlyph = font.getData().getGlyph('�');
			fonts.get(generator).put(size, font);
		} catch ( Exception e ){
			Game.reportException(e);
			return null;
		}
	}
	
	return fonts.get(generator).get(size);
}
 
Example 6
Source File: LibgdxFonts.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
@Override
public GameFont newPlatformFont(FileHandle fileHandle) {
	if(fileHandle.path().endsWith(".ttf")) {
		final LibgdxFileHandle gdxFileHandle = (LibgdxFileHandle) fileHandle;
		FreeTypeFontGenerator.FreeTypeFontParameter fontParameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
		fontParameter.size = 12;
		fontParameter.flip = true;
		fontParameter.kerning = true;
		FreeTypeFontGenerator freeTypeFontGenerator = new FreeTypeFontGenerator(gdxFileHandle.fileHandle);
		return new LibgdxBitmapFont(freeTypeFontGenerator.generateFont(fontParameter));
	}
	return new LibgdxBitmapFont(fileHandle);
}
 
Example 7
Source File: Main.java    From xibalba with MIT License 4 votes vote down vote up
/**
 * Setup & load the main menu.
 */
public void create() {
  // Debug shit
  debug = new Debug();

  // Load custom font
  assets = new AssetManager();
  FreeTypeFontGenerator generator =
      new FreeTypeFontGenerator(Gdx.files.internal("ui/Aller_Rg.ttf"));
  FreeTypeFontGenerator.FreeTypeFontParameter parameter =
      new FreeTypeFontGenerator.FreeTypeFontParameter();
  parameter.size = 12;
  BitmapFont font = generator.generateFont(parameter);
  generator.dispose();

  // Create UI skin
  skin = new Skin();
  skin.add("Aller", font, BitmapFont.class);
  skin.addRegions(new TextureAtlas(Gdx.files.internal("ui/uiskin.atlas")));
  skin.load(Gdx.files.internal("ui/uiskin.json"));
  skin.getFont("default-font").getData().markupEnabled = true;

  // Setup text colors
  Colors.put("LIGHT_GRAY", parseColor("c2c2c2"));
  Colors.put("DARK_GRAY", parseColor("666666"));
  Colors.put("CYAN", parseColor("67C8CF"));
  Colors.put("RED", parseColor("D67474"));
  Colors.put("YELLOW", parseColor("E0DFB1"));
  Colors.put("GREEN", parseColor("67CF8B"));

  // Environment colors
  Colors.put("forestFloor", parseColor("78AD8A"));
  Colors.put("forestFloorWet", parseColor("70BBAD"));
  Colors.put("forestTree-1", parseColor("67CF8B"));
  Colors.put("forestTree-2", parseColor("77E09B"));
  Colors.put("forestTree-3", parseColor("4AC775"));

  Colors.put("caveFloor-1", parseColor("7A7971"));
  Colors.put("caveFloor-2", parseColor("8C8B82"));
  Colors.put("caveFloor-3", parseColor("696862"));
  Colors.put("caveFloorWet", parseColor("71A48E"));
  Colors.put("caveWall", parseColor("66655C"));

  Colors.put("waterShallowLightBlue", parseColor("67C8CF"));
  Colors.put("waterShallowDarkBlue", parseColor("139EA8"));
  Colors.put("waterDeepLightBlue", parseColor("139EA8"));
  Colors.put("waterDeepDarkBlue", parseColor("0B7880"));

  Colors.put("waterShallowLightGreen", parseColor("67CFAB"));
  Colors.put("waterShallowDarkGreen", parseColor("13A88F"));
  Colors.put("waterDeepLightGreen", parseColor("13A88F"));
  Colors.put("waterDeepDarkGreen", parseColor("0B8074"));

  Colors.put("fire-1", parseColor("ED6161"));
  Colors.put("fire-2", parseColor("EDBE61"));
  Colors.put("fire-3", parseColor("ED9661"));

  // Decoration colors
  Colors.put("stone", Colors.get("LIGHT_GRAY"));
  Colors.put("bridge", parseColor("969482"));

  // Background colors
  Colors.put("screenBackground", parseColor("293033"));
  Colors.put("forestBackground", parseColor("29332F"));
  Colors.put("caveBackground", parseColor("293033"));

  // Tween manager
  tweenManager = new TweenManager();
  Tween.setCombinedAttributesLimit(4);
  Tween.registerAccessor(Sprite.class, new SpriteAccessor());

  // Cameras
  handheldCamera = new HandheldCamera();
  cameraShake = new CameraShake();

  // Start the main menu
  setScreen(new LoadingScreen(this));
}
 
Example 8
Source File: AssetsManager.java    From martianrun with Apache License 2.0 4 votes vote down vote up
public static void loadAssets() {

        // Background
        texturesMap.put(Constants.BACKGROUND_ASSETS_ID,
                new TextureRegion(new Texture(Gdx.files.internal(Constants.BACKGROUND_IMAGE_PATH))));

        // Ground
        texturesMap.put(Constants.GROUND_ASSETS_ID,
                new TextureRegion(new Texture(Gdx.files.internal(Constants.GROUND_IMAGE_PATH))));

        textureAtlas = new TextureAtlas(Constants.SPRITES_ATLAS_PATH);

        // Runner
        texturesMap.put(Constants.RUNNER_JUMPING_ASSETS_ID,
                textureAtlas.findRegion(Constants.RUNNER_JUMPING_REGION_NAME));
        texturesMap.put(Constants.RUNNER_DODGING_ASSETS_ID,
                textureAtlas.findRegion(Constants.RUNNER_DODGING_REGION_NAME));
        texturesMap.put(Constants.RUNNER_HIT_ASSETS_ID,
                textureAtlas.findRegion(Constants.RUNNER_HIT_REGION_NAME));
        animationsMap.put(Constants.RUNNER_RUNNING_ASSETS_ID, createAnimation(textureAtlas,
                Constants.RUNNER_RUNNING_REGION_NAMES));

        // Enemies
        animationsMap.put(Constants.RUNNING_SMALL_ENEMY_ASSETS_ID, createAnimation(textureAtlas,
                Constants.RUNNING_SMALL_ENEMY_REGION_NAMES));
        animationsMap.put(Constants.RUNNING_BIG_ENEMY_ASSETS_ID, createAnimation(textureAtlas,
                Constants.RUNNING_BIG_ENEMY_REGION_NAMES));
        animationsMap.put(Constants.RUNNING_LONG_ENEMY_ASSETS_ID, createAnimation(textureAtlas,
                Constants.RUNNING_LONG_ENEMY_REGION_NAMES));
        animationsMap.put(Constants.RUNNING_WIDE_ENEMY_ASSETS_ID, createAnimation(textureAtlas,
                Constants.RUNNING_WIDE_ENEMY_REGION_NAMES));
        animationsMap.put(Constants.FLYING_SMALL_ENEMY_ASSETS_ID, createAnimation(textureAtlas,
                Constants.FLYING_SMALL_ENEMY_REGION_NAMES));
        animationsMap.put(Constants.FLYING_WIDE_ENEMY_ASSETS_ID, createAnimation(textureAtlas,
                Constants.FLYING_WIDE_ENEMY_REGION_NAMES));

        // Tutorial
        texturesMap.put(Constants.TUTORIAL_LEFT_REGION_NAME,
                textureAtlas.findRegion(Constants.TUTORIAL_LEFT_REGION_NAME));
        texturesMap.put(Constants.TUTORIAL_RIGHT_REGION_NAME,
                textureAtlas.findRegion(Constants.TUTORIAL_RIGHT_REGION_NAME));

        // Fonts
        FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal(Constants.FONT_NAME));
        FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
        parameter.size = 36;
        smallFont = generator.generateFont(parameter);
        smallFont.setColor(.21f, .22f, .21f, 1f);
        parameter.size = 72;
        largeFont = generator.generateFont(parameter);
        largeFont.setColor(.21f, .22f, .21f, 1f);
        parameter.size = 24;
        smallestFont = generator.generateFont(parameter);
        smallestFont.setColor(.21f, .22f, .21f, 1f);
        generator.dispose();

    }