Java Code Examples for com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator#generateFont()

The following examples show how to use com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator#generateFont() . 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: KeyConfiguration.java    From beatoraja with GNU General Public License v3.0 6 votes vote down vote up
public void create() {
	loadSkin(SkinType.KEY_CONFIG);
	if(getSkin() == null) {
		this.setSkin(new KeyConfigurationSkin(Resolution.HD, main.getConfig().getResolution()));
	}

	FreeTypeFontGenerator generator = new FreeTypeFontGenerator(
			Gdx.files.internal("skin/default/VL-Gothic-Regular.ttf"));
	FreeTypeFontParameter parameter = new FreeTypeFontParameter();
	parameter.size = (int) (20 * getSkin().getScaleY());
	titlefont = generator.generateFont(parameter);
	shape = new ShapeRenderer();

	input = main.getInputProcessor();
	keyboard = input.getKeyBoardInputProcesseor();
	controllers = input.getBMInputProcessor();
	midiinput = input.getMidiInputProcessor();
	setMode(0);
}
 
Example 2
Source File: SuperSnake.java    From super-snake with MIT License 5 votes vote down vote up
@Override
public void create () {
	batch = new SpriteBatch();

       WIDTH = Gdx.graphics.getBackBufferWidth();
       HEIGHT = Gdx.graphics.getBackBufferHeight();

       PADDED_WIDTH = WIDTH - PADDING;
       PADDED_HEIGHT = HEIGHT - PADDING;

       Gdx.app.log("Snake", "VIEWPORT " + WIDTH + ", " + HEIGHT);

       shapeRenderer = new ShapeRenderer();

       snake = new Snake(WIDTH / 2, HEIGHT / 2, INITIAL_SNAKE_LENGTH);
       pause_snake = new Snake(WIDTH / 2, 200, 100);

       FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/PatrickHand.ttf"));
       FreeTypeFontParameter parameter = new FreeTypeFontParameter();
       parameter.size = 32;
       font = generator.generateFont(parameter);

       parameter.size = 52;
       parameter.borderColor = Colors.spray;
       parameter.borderWidth = 2;
       fontBtn = generator.generateFont(parameter);

       parameter.size = 80;
       parameter.color = Color.WHITE;
       parameter.borderWidth = 2;
       parameter.borderColor = Colors.red;
       fontBig = generator.generateFont(parameter);

       generator.dispose();
}
 
Example 3
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 4
Source File: MessageRenderer.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
public void init(FreeTypeFontGenerator generator) {
	FreeTypeFontParameter parameter = new FreeTypeFontParameter();
	parameter.size = 24;
	parameter.characters += text;
	font = generator.generateFont(parameter);
	font.setColor(color);
}
 
Example 5
Source File: LaneRenderer.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
public LaneRenderer(BMSPlayer main, BMSModel model) {

		this.main = main;
		Pixmap hp = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
		hp.drawPixel(0, 0, Color.toIntBits(255, 255, 255, 255));
		blank = new TextureRegion(new Texture(hp));
		hp.dispose();

		FreeTypeFontGenerator generator = new FreeTypeFontGenerator(
				Gdx.files.internal("skin/default/VL-Gothic-Regular.ttf"));
		FreeTypeFontParameter parameter = new FreeTypeFontParameter();
		parameter.size = 18;
		font = generator.generateFont(parameter);
		generator.dispose();

		this.skin = (PlaySkin) main.getSkin();
		this.conf = main.main.getPlayerResource().getConfig();
		this.config = main.main.getPlayerResource().getPlayerConfig();
		this.playconfig = config.getPlayConfig(model.getMode()).getPlayconfig().clone();

		init(model);

		for (CourseData.CourseDataConstraint i : main.main.getPlayerResource().getConstraint()) {
			if (i == NO_SPEED) {
				playconfig.setHispeed(1.0f);
				playconfig.setLanecover(0);
				playconfig.setLift(0);
				playconfig.setHidden(0);
			}
		}
	}
 
Example 6
Source File: PracticeConfiguration.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
public void create(BMSModel model) {
	property.judgerank = model.getJudgerank();
	property.endtime = model.getLastTime() + 1000;
	Path p = Paths.get("practice/" + model.getSHA256() + ".json");
	if (Files.exists(p)) {
		Json json = new Json();
		try {
			property = json.fromJson(PracticeProperty.class, new FileReader(p.toFile()));
		} catch (FileNotFoundException | SerializationException e) {
			e.printStackTrace();
		}
	}

	if(property.gaugecategory == null) {
		property.gaugecategory = BMSPlayerRule.getBMSPlayerRule(model.getMode()).gauge;
	}
	this.model = model;
	if(property.total == 0) {
		property.total = model.getTotal();
	}
	FreeTypeFontGenerator generator = new FreeTypeFontGenerator(
			Gdx.files.internal("skin/default/VL-Gothic-Regular.ttf"));
	FreeTypeFontParameter parameter = new FreeTypeFontParameter();
	parameter.size = 18;
	titlefont = generator.generateFont(parameter);
	
	for(int i = 0; i < graph.length; i++) {
		graph[i].setDestination(0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, new int[0]);
	}
}
 
Example 7
Source File: ResourceManager.java    From TerraLegion with MIT License 5 votes vote down vote up
public BitmapFont getFont(String id, String file, Color color, int size) {
	FreeTypeFontGenerator gen = new FreeTypeFontGenerator(Gdx.files.internal(file));
	BitmapFont font = gen.generateFont(size);
	font.setColor(color);
	font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
	return font;
}
 
Example 8
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 9
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 10
Source File: CCLabelTTF.java    From cocos2d-java with MIT License 5 votes vote down vote up
public CCLabelTTF (String text, String fontName, int fontSize)      
{ 
	m_fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal(fontName));
	m_pString = removeRepeatChar(text);
	m_bitmapFont = m_fontGenerator.generateFont(fontSize, m_pString, false);
	m_pFontName = fontName;
    m_fFontSize = fontSize;
    
    setContentSize(new CCSize(m_bitmapFont.getBounds(m_pString).width,m_bitmapFont.getCapHeight() -1/2f* m_bitmapFont.getDescent()));
    setAnchorPoint(new CCPoint(0.5f, 0.5f));
}
 
Example 11
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 12
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 13
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();

    }