Java Code Examples for com.badlogic.gdx.graphics.g2d.BitmapFont

The following examples show how to use com.badlogic.gdx.graphics.g2d.BitmapFont. These examples are extracted from open source projects. 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 Project: flopsydroid   Source File: FlopsyScreen.java    License: Apache License 2.0 6 votes vote down vote up
public FlopsyScreen(FlopsyDroidGame game, OnGlobalListener listener) {
    mStage = new Stage();

    mGlobalListener = listener;

    game.getAssetManager().load("flopsy.sprites", TextureAtlas.class);
    game.getAssetManager().finishLoading();
    mTextureAtlas = game.getAssetManager().get("flopsy.sprites", TextureAtlas.class);

    mLabelStyle = new Label.LabelStyle();
    mLabelStyle.font = new BitmapFont(Gdx.files.internal("flappyfont.fnt"),
            Gdx.files.internal("flappyfont.png"), false);

    mStage.addListener(new EventListener() {
        @Override
        public boolean handle(Event event) {

            if(event.getTarget().equals(mAndy)) {
                mGround.onDroidCollision();
                return true;
            }

            return false;
        }
    });
}
 
Example 2
Source Project: Klooni1010   Source File: SkinLoader.java    License: GNU General Public License v3.0 6 votes vote down vote up
static Skin loadSkin() {
    String folder = "ui/x" + bestMultiplier + "/";

    // Base skin
    Skin skin = new Skin(Gdx.files.internal("skin/uiskin.json"));

    // Nine patches
    final int border = (int) (28 * bestMultiplier);
    skin.add("button_up", new NinePatch(new Texture(
            Gdx.files.internal(folder + "button_up.png")), border, border, border, border));

    skin.add("button_down", new NinePatch(new Texture(
            Gdx.files.internal(folder + "button_down.png")), border, border, border, border));

    for (String id : ids) {
        skin.add(id + "_texture", new Texture(Gdx.files.internal(folder + id + ".png")));
    }

    folder = "font/x" + bestMultiplier + "/";
    skin.add("font", new BitmapFont(Gdx.files.internal(folder + "geosans-light64.fnt")));
    skin.add("font_small", new BitmapFont(Gdx.files.internal(folder + "geosans-light32.fnt")));
    skin.add("font_bonus", new BitmapFont(Gdx.files.internal(folder + "the-next-font.fnt")));

    return skin;
}
 
Example 3
Source Project: ud405   Source File: IciclesScreen.java    License: MIT License 6 votes vote down vote up
@Override
public void show() {
    iciclesViewport = new ExtendViewport(Constants.WORLD_SIZE, Constants.WORLD_SIZE);

    renderer = new ShapeRenderer();
    renderer.setAutoShapeType(true);

    // TODO: Initialize the HUD viewport
    hudViewport = new ScreenViewport();

    // TODO: Initialize the SpriteBatch
    batch = new SpriteBatch();

    // TODO: Initialize the BitmapFont
    font = new BitmapFont();

    // TODO: Give the font a linear TextureFilter
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);

    player = new Player(iciclesViewport);
    icicles = new Icicles(iciclesViewport);

    // TODO: Set top score to zero
    topScore = 0;
}
 
Example 4
Source Project: ud405   Source File: IciclesScreen.java    License: MIT License 6 votes vote down vote up
@Override
public void show() {
    iciclesViewport = new ExtendViewport(Constants.WORLD_SIZE, Constants.WORLD_SIZE);

    renderer = new ShapeRenderer();
    renderer.setAutoShapeType(true);

    hudViewport = new ScreenViewport();
    batch = new SpriteBatch();

    font = new BitmapFont();
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);

    player = new Player(iciclesViewport);
    icicles = new Icicles(iciclesViewport, difficulty);

    Gdx.input.setInputProcessor(this);

    topScore = 0;
}
 
Example 5
Source Project: skin-composer   Source File: MainListener.java    License: MIT License 6 votes vote down vote up
@Override
public void stylePropertyChanged(StyleProperty styleProperty,
        Actor styleActor) {
    if (styleProperty.type == Drawable.class) {
        dialogFactory.showDialogDrawables(styleProperty, dialogListener);
    } else if (styleProperty.type == Color.class) {
        dialogFactory.showDialogColors(styleProperty, dialogListener);
    } else if (styleProperty.type == BitmapFont.class) {
        dialogFactory.showDialogFonts(styleProperty, dialogListener);
    } else if (styleProperty.type == Float.TYPE) {
        main.getUndoableManager().addUndoable(new UndoableManager.DoubleUndoable(main, styleProperty, ((Spinner) styleActor).getValue()), false);
    } else if (styleProperty.type == ScrollPaneStyle.class) {
        main.getUndoableManager().addUndoable(new UndoableManager.SelectBoxUndoable(root, styleProperty, (SelectBox) styleActor), true);
    } else if (styleProperty.type == LabelStyle.class) {
        main.getUndoableManager().addUndoable(new UndoableManager.SelectBoxUndoable(root, styleProperty, (SelectBox) styleActor), true);
    } else if (styleProperty.type == ListStyle.class) {
        main.getUndoableManager().addUndoable(new UndoableManager.SelectBoxUndoable(root, styleProperty, (SelectBox) styleActor), true);
    }
}
 
Example 6
Source Project: cocos-ui-libgdx   Source File: FontUtilTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@NeedGL
public void shouldUnableToGenerateBitmapIfCharNotInTTF() throws Exception {
    FileHandle defaultFont = Gdx.files.internal("share/MLFZS.ttf");
    String text = "มันเป็นการทดสอบ";
    BitmapFont bitmapFont = FontUtil.createFont(defaultFont, text, 14);

    assertThat(bitmapFont, not(nullValue()));
    for (char c : text.toCharArray()) {
        BitmapFont.Glyph glyph = bitmapFont.getData().getGlyph(c);
        try {
            assertThat(glyph, is(nullValue()));
        } catch (AssertionError ignored) {
            //Different behaviour for 1.7.0
            assertThat(glyph.id, is(127));
        }
    }
}
 
Example 7
Source Project: vis-ui   Source File: HighlightTextArea.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void drawText (Batch batch, BitmapFont font, float x, float y) {
	maxAreaHeight = 0;
	float offsetY = 0;
	for (int i = firstLineShowing * 2; i < (firstLineShowing + linesShowing) * 2 && i < linesBreak.size; i += 2) {
		for (Chunk chunk : renderChunks) {
			if (chunk.lineIndex == i) {
				font.setColor(chunk.color);
				font.draw(batch, chunk.text, x + chunk.offsetX, y + offsetY);
			}
		}

		offsetY -= font.getLineHeight();
		maxAreaHeight += font.getLineHeight();
	}

	maxAreaHeight += 30;
}
 
Example 8
@Override
public void resetGenerators() {
	if (fonts != null) {
		for (FreeTypeFontGenerator generator : fonts.keySet()) {
			for (BitmapFont f : fonts.get(generator).values()) {
				f.dispose();
			}
			fonts.get(generator).clear();
			generator.dispose();
		}
		fonts.clear();
		if (packer != null) {
			for (PixmapPacker.Page p : packer.getPages()) {
				p.getTexture().dispose();
			}
			packer.dispose();
		}
		fonts = null;
	}
	setupFontGenerators(pageSize, systemfont);
}
 
Example 9
Source Project: jorbs-spire-mod   Source File: WrathCardIconPatch.java    License: MIT License 5 votes vote down vote up
@SpirePostfixPatch
public static void Postfix(AbstractCard card, SpriteBatch sb) {
    int wrathCount = WrathField.wrathEffectCount.get(card);

    boolean darken = ReflectionUtils.getPrivateField(card, AbstractCard.class, "darken");
    if (wrathCount == 0 || darken || card.isLocked || !card.isSeen) {
        return;
    }

    Color renderColor = ReflectionUtils.getPrivateField(card, AbstractCard.class, "renderColor");
    RenderUtils.renderAtlasRegionCenteredAt(sb,
            wrathIconOverlayImg,
            card.current_x,
            card.current_y,
            card.drawScale * Settings.scale,
            renderColor,
            card.angle);

    WRATH_TEXT_COLOR.a = card.transparency;
    String text = Integer.toString(wrathCount);
    BitmapFont font = FontHelper.cardEnergyFont_L;
    font.getData().setScale(card.drawScale);
    FontHelper.renderRotatedText(sb,
            font,
            text,
            card.current_x,
            card.current_y,
            WRATH_TEXT_OFFSET_X * card.drawScale * Settings.scale,
            WRATH_TEXT_OFFSET_Y * card.drawScale * Settings.scale,
            card.angle,
            false,
            WRATH_TEXT_COLOR);
}
 
Example 10
Source Project: gdx-ai   Source File: TabbedPane.java    License: Apache License 2.0 5 votes vote down vote up
public TabbedPaneStyle (Drawable titleBegin, Drawable titleEnd, Drawable bodyBackground, Drawable titleButtonSelected,
	Drawable titleButtonUnselected, BitmapFont font) {
	this.titleBegin = titleBegin;
	this.titleEnd = titleEnd;
	this.bodyBackground = bodyBackground;
	this.titleButtonSelected = titleButtonSelected;
	this.titleButtonUnselected = titleButtonUnselected;
	this.font = font;
}
 
Example 11
Source Project: gdx-proto   Source File: SmartFontGenerator.java    License: Apache License 2.0 5 votes vote down vote up
private void saveFontToFile(BitmapFont font, int fontSize, String fontName, PixmapPacker packer) {
	FileHandle fontFile = getFontFile(fontName + ".fnt"); // .fnt path
	FileHandle pixmapDir = getFontFile(fontName); // png dir path
	BitmapFontWriter.setOutputFormat(BitmapFontWriter.OutputFormat.Text);

	String[] pageRefs = BitmapFontWriter.writePixmaps(packer.getPages(), pixmapDir, fontName);
	Gdx.app.debug(TAG, String.format("Saving font [%s]: fontfile: %s, pixmapDir: %s\n", fontName, fontFile, pixmapDir));
	// here we must add the png dir to the page refs
	for (int i = 0; i < pageRefs.length; i++) {
		pageRefs[i] = fontName + "/" + pageRefs[i];
	}
	BitmapFontWriter.writeFont(font.getData(), pageRefs, fontFile, new BitmapFontWriter.FontInfo(fontName, fontSize), 1, 1);
}
 
Example 12
Source Project: uracer-kotd   Source File: BitmapFontFactory.java    License: Apache License 2.0 5 votes vote down vote up
public static void dispose () {
	for (BitmapFont f : fontCache.values()) {
		f.dispose();
	}

	fontCache.clear();
}
 
Example 13
Source Project: Norii   Source File: Utility.java    License: Apache License 2.0 5 votes vote down vote up
public static void loadFreeTypeFontAsset(final String fontName, final int size) {
	if (checkValidString(fontName)) {
		assetManager.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(filePathResolver));
		assetManager.setLoader(BitmapFont.class, ".ttf", new FreetypeFontLoader(filePathResolver));

		final FreeTypeFontLoaderParameter myFont = new FreeTypeFontLoaderParameter();
		myFont.fontFileName = fontName;
		myFont.fontParameters.size = size;
		myFont.fontParameters.borderWidth = 0.5f;
		myFont.fontParameters.color = Color.LIGHT_GRAY;
		myFont.fontParameters.shadowOffsetX = 2;
		myFont.fontParameters.shadowOffsetY = 2;
		assetManager.load(fontName, BitmapFont.class, myFont);
	}
}
 
Example 14
Source Project: Norii   Source File: Utility.java    License: 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 15
Source Project: ud405   Source File: FPSCounterScreen.java    License: MIT License 5 votes vote down vote up
@Override
public void show() {

    // TODO: Initialize the SpriteBatch
    batch = new SpriteBatch();

    // TODO: Initialize the BitmapFont
    font = new BitmapFont();
    font.getData().setScale(2);
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);

    // TODO: Initialize the ScreenViewport
    viewport = new ScreenViewport();
}
 
Example 16
Source Project: riiablo   Source File: StatLabel.java    License: Apache License 2.0 5 votes vote down vote up
private static BitmapFont getFont(int len) {
  if (len > 6) {
    return Riiablo.fonts.ReallyTheLastSucker;
  } else if (len > 3) {
    return Riiablo.fonts.font8;
  } else {
    return Riiablo.fonts.font16;
  }
}
 
Example 17
Source Project: RuinsOfRevenge   Source File: ScreenGameMap.java    License: MIT License 5 votes vote down vote up
private Stack<String> splitIntoLinesRec(Stack<String> list, String line, BitmapFont font, float width) {
	int visible = font.computeVisibleGlyphs(line, 0, line.length(), width);
	if (line.length() > visible) {
		String head = line.substring(0, visible-1);
		String rest = line.substring(visible, line.length()-1);
		list.push(head);
		return splitIntoLinesRec(list, rest, font, width);
	} else {
		list.push(line);
		return list;
	}
}
 
Example 18
Source Project: ud405   Source File: MyScreen.java    License: MIT License 5 votes vote down vote up
@Override
public void show() {
    batch = new SpriteBatch();
    font = new BitmapFont();
    font.getData().setScale(2);
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
    viewport = new ScreenViewport();
}
 
Example 19
Source Project: martianrun   Source File: Score.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);
    if (getScore() == 0) {
        return;
    }
    font.drawWrapped(batch, String.format("%d", getScore()), bounds.x, bounds.y, bounds.width, BitmapFont.HAlignment.RIGHT);
}
 
Example 20
Source Project: TerraLegion   Source File: ResourceManager.java    License: 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 21
@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 22
Source Project: ud405   Source File: ConnectTheDots.java    License: MIT License 5 votes vote down vote up
@Override
public void create() {
    spriteBatch = new SpriteBatch();
    bitmapFont = new BitmapFont();
    floatDots = vector2ArrayToFloatArray(dots);
    shapeRenderer = new ShapeRenderer();

}
 
Example 23
Source Project: riiablo   Source File: CharacterPanel.java    License: Apache License 2.0 5 votes vote down vote up
private BitmapFont getFont(int length) {
  if (length > 6) {
    return Riiablo.fonts.ReallyTheLastSucker;
  } else if (length > 3) {
    return Riiablo.fonts.font8;
  } else {
    return Riiablo.fonts.font16;
  }
}
 
Example 24
Source Project: riiablo   Source File: TextButton.java    License: Apache License 2.0 5 votes vote down vote up
public TextButtonStyle (Drawable up, Drawable down, Drawable checked, BitmapFont font) {
  super(up, down, checked);
  unpressedOffsetY = -2;
  pressedOffsetX = -2;
  pressedOffsetY = unpressedOffsetY + pressedOffsetX;
  checkedOffsetX = unpressedOffsetX;
  checkedOffsetY = unpressedOffsetY;
  this.font = font;
  fontColor = Color.BLACK;
}
 
Example 25
Source Project: libgdx-demo-pax-britannica   Source File: Settings.java    License: MIT License 5 votes vote down vote up
@Override
public void show() {		
	GameInstance.getInstance().resetGame();
	
	backgroundFX = new BackgroundFXRenderer();
	
	blackFade = Resources.getInstance().blackFade;
	
	back = Resources.getInstance().back;
	back.setPosition(20, 010);
	back.setColor(1,1,1,0.5f);
	collisionBack.set(new Vector3(back.getVertices()[0], back.getVertices()[1], -10),new Vector3(back.getVertices()[10], back.getVertices()[11], 10));
	
	collisionDiffEasy.set(new Vector3(90, 330,-10),new Vector3(190, 360, 10));
	collisionDiffMedium.set(new Vector3(240, 330,-10),new Vector3(340, 360, 10));
	collisionDiffHard.set(new Vector3(400, 330,-10),new Vector3(500, 360, 10));
	
	collisionFacHealthLow.set(new Vector3(90, 230,-10),new Vector3(190, 260, 10));
	collisionFacHealthMedium.set(new Vector3(240, 230,-10),new Vector3(340, 260, 10));
	collisionFacHealthHigh.set(new Vector3(400, 230,-10),new Vector3(500, 260, 10));
	
	collisionAntiAliasOff.set(new Vector3(90, 130,-10),new Vector3(190, 160, 10));
	collisionAntiAliasOn.set(new Vector3(240, 130,-10),new Vector3(340, 160, 10));
	
	checkboxOn = Resources.getInstance().checkboxOn;
	checkboxOff = Resources.getInstance().checkboxOff;
	
	titleBatch = new SpriteBatch();
	titleBatch.getProjectionMatrix().setToOrtho2D(0, 0, 800, 480);
	fadeBatch = new SpriteBatch();
	fadeBatch.getProjectionMatrix().setToOrtho2D(0, 0, 2, 2);
	
	font = new BitmapFont();
	font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
}
 
Example 26
Source Project: fluid-simulator-v2   Source File: FluidSimulatorGeneric.java    License: Apache License 2.0 5 votes vote down vote up
public FluidSimulatorGeneric(FluidSimulatorStarter fluidSimulatorStarter) {
		this.game = fluidSimulatorStarter;
		// LibGDX single batches cannot have a size more than 5460
		batch = new SpriteBatch(IS_DESKTOP ? 5460 : ANDROID_SIZE);
		font = new BitmapFont();
		camera = new OrthographicCamera(WORLD_WIDTH, WORLD_HEIGHT);
		camera.position.set(0, (WORLD_HEIGHT / 2) - 1, 0);
		immediateRenderer = new ImmediateModeRenderer20(SIZE*6, false, true, 0);
		irt = new Renderer20(SIZE*6, false, true, 1);
		irt2 = new ImmediateModeRenderer20(SIZE*11, false, true, 1);
		shapeRenderer = new ShapeRenderer(SIZE);
		renderer = new Box2DDebugRenderer(true, true, false, true, false, false);
		
		//3D
		camera3D = new PerspectiveCamera(67, WORLD_WIDTH, WORLD_HEIGHT);
		camera3D.position.set(0, 130f, 250f);
		camera3D.lookAt(0,150f,0);
		camera3D.near = 0.1f;
		camera3D.far = 500f;
		camera3D.update();
		ModelBuilder modelBuilder = new ModelBuilder();
//        model = modelBuilder.createSphere(5f, 5f, 5f, 4, 4, GL10.GL_TRIANGLES,
//                new Material(ColorAttribute.createDiffuse(Color.GREEN)),
//                Usage.Position | Usage.Normal);
        model = modelBuilder.createBox(5f, 5f, 5f,
            new Material(ColorAttribute.createDiffuse(Color.GREEN)),
            Usage.Position | Usage.Normal);
        instance = new ModelInstance(model);
        modelBatch = new ModelBatch();
        environment = new Environment();
        environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
        environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, 0, -0.8f, -0.2f));
        camController = new Camera3DController(camera3D);
        camController.setFluidSimulator(this);
		
		world = new World(new Vector2(0, -9.8f), false);
		world.setContactListener(this);
	}
 
Example 27
Source Project: SIFTrain   Source File: Assets.java    License: MIT License 5 votes vote down vote up
public static void queueLoading() {
    internalManager.load("textures/textures.pack.atlas", TextureAtlas.class);
    internalManager.load("hitsounds/bad.mp3", Sound.class);
    internalManager.load("hitsounds/good.mp3", Sound.class);
    internalManager.load("hitsounds/great.mp3", Sound.class);
    internalManager.load("hitsounds/perfect.mp3", Sound.class);
    internalManager.load("bigimages/main_menu_background.jpg", Texture.class);
    internalManager.load("images/hold_background.png", Texture.class);
    internalManager.load("fonts/combo-font.fnt", BitmapFont.class);
    internalManager.load("fonts/song-font.fnt", BitmapFont.class);
    reloadBeatmaps();
}
 
Example 28
protected EngineAssetManager(FileHandleResolver resolver) {
	super(resolver);

	resResolver = new EngineResolutionFileResolver(resolver);
	setLoader(Texture.class, new TextureLoader(resResolver));
	setLoader(TextureAtlas.class, new TextureAtlasLoader(resResolver));
	setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver));
	setLoader(BitmapFont.class, ".ttf", new FreetypeFontLoader(resolver));

	Texture.setAssetManager(this);
}
 
Example 29
public FilteredSelectBoxStyle(BitmapFont font, Color fontColor, Drawable background,
		ScrollPaneStyle scrollStyle, ListStyle listStyle, TextFieldStyle textFieldStyle) {
	this.font = font;
	this.fontColor.set(fontColor);
	this.background = background;
	this.scrollStyle = scrollStyle;
	this.listStyle = listStyle;
	this.textFieldStyle = textFieldStyle;
}
 
Example 30
Source Project: Entitas-Java   Source File: RendererSystem.java    License: MIT License 5 votes vote down vote up
public RendererSystem(CoreContext context, ShapeRenderer sr, Camera cam, Batch batch, BitmapFont font) {
    this.sr = sr;
    this.cam = cam;
    this.batch = batch;
    this.font = font;
    _group = context.getGroup(CoreMatcher.View());
    _groupScore = context.getGroup(CoreMatcher.Score());
    _groupTextureView = context.getGroup(CoreMatcher.TextureView());
}