public void setRenderType (RenderType renderType) { this.renderType = renderType; if (renderType != RenderType.FreeType) { if (bitmapFont != null) { bitmapFont.dispose(); generator.dispose(); } } else { String fontFile = getFontFile(); if (fontFile != null) { generator = new FreeTypeFontGenerator(Gdx.files.absolute(fontFile)); FreeTypeFontParameter param = new FreeTypeFontParameter(); param.size = font.getSize(); param.incremental = true; param.flip = true; param.mono = mono; param.gamma = gamma; bitmapFont = generator.generateFont(param); if (bitmapFont.getData().missingGlyph == null) bitmapFont.getData().missingGlyph = bitmapFont.getData().getGlyph('\ufffd'); cache = bitmapFont.newFontCache(); layout = new GlyphLayout(); } } }
public void setRenderType (RenderType renderType) { this.renderType = renderType; if (renderType != RenderType.FreeType) { if (bitmapFont != null) { bitmapFont.dispose(); generator.dispose(); } } else { String fontFile = getFontFile(); if (fontFile != null) { generator = new FreeTypeFontGenerator(Gdx.files.absolute(fontFile)); FreeTypeFontParameter param = new FreeTypeFontParameter(); param.size = font.getSize(); param.incremental = true; param.flip = true; param.mono = mono; param.gamma = gamma; bitmapFont = generator.generateFont(param); if (bitmapFont.getData().missingGlyph == null) bitmapFont.getData().missingGlyph = bitmapFont.getData().getGlyph('\ufffd'); cache = bitmapFont.newFontCache(); layout = new GlyphLayout(); } } }
@Override public void create () { Gdx.input.setInputProcessor(new InputAdapter() { public boolean touchDown (int x, int y, int pointer, int newParam) { renderMode = (renderMode + 1) % 6; return false; } }); spriteBatch = new SpriteBatch(); texture = new Texture(Gdx.files.internal("data/badlogic.jpg")); logoSprite = new Sprite(texture); logoSprite.setColor(1, 1, 1, 0.6f); logoSprite.setBounds(50, 100, 400, 100); font = new BitmapFont(Gdx.files.getFileHandle("data/verdana39.fnt", FileType.Internal), Gdx.files.getFileHandle( "data/verdana39.png", FileType.Internal), false); cache = font.newFontCache(); layout = new GlyphLayout(); }
@Override public void create () { spriteBatch = new SpriteBatch(); // font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), false); font = new BitmapFont(Gdx.files.internal("data/arial-32-pad.fnt"), false); // font = new FreeTypeFontGenerator(Gdx.files.internal("data/arial.ttf")).generateFont(new FreeTypeFontParameter()); font.getData().markupEnabled = true; font.getData().breakChars = new char[] {'-'}; multiPageFont = new BitmapFont(Gdx.files.internal("data/multipagefont.fnt")); // Add user defined color Colors.put("PERU", Color.valueOf("CD853F")); renderer = new ShapeRenderer(); renderer.setProjectionMatrix(spriteBatch.getProjectionMatrix()); stage = new Stage(new ScreenViewport()); Skin skin = new Skin(Gdx.files.internal("data/uiskin.json")); BitmapFont labelFont = skin.get("default-font", BitmapFont.class); labelFont.getData().markupEnabled = true; // Notice that the last [] has been deliberately added to test the effect of excessive pop operations. // They are silently ignored, as expected. label = new Label("<<[BLUE]M[RED]u[YELLOW]l[GREEN]t[OLIVE]ic[]o[]l[]o[]r[]*[MAROON]Label[][] [Unknown Color]>>", skin); label.setPosition(100, 200); stage.addActor(label); Window window = new Window("[RED]Multicolor[GREEN] Title", skin); window.setPosition(400, 300); window.pack(); stage.addActor(window); layout = new GlyphLayout(); }
GlyphLayout glyphLayout = new GlyphLayout(); String item = "Example"; glyphLayout.setText(font,item); float w = glyphLayout.width;
@Override public int textWidth(String text) { if (!definedFont) { return 0; } GlyphLayout layout = new GlyphLayout(font.getFont(), text); return (int) layout.width; }
GlyphLayout glyphLayout = new GlyphLayout(); glyphLayout.setText(font, message); float x = screenWidth/2 - glyphLayout.width/2; float y = screenHeight/2 + glyphLayout.height/2;
GlyphLayout layout = new GlyphLayout(); layout.setText(bitmapFont,"text"); float width = layout.width; float height = layout.height;
screenWidth = Gdx.graphics.getWidth();\ layout = new GlyphLayout(); recPlayButton = new Rectangle();
public void drawString(String text, int x, int y, int w, int h) { beginBatch(); GlyphLayout layout = new GlyphLayout(); layout.setText(font.getFont(), text); float cx = w / 2 - layout.width / 2; float cy = h / 2 - layout.height / 2; drawFont(text, x + cx, y + cy); }
public void drawStringX(String text, int y) { beginBatch(); GlyphLayout layout = new GlyphLayout(); layout.setText(font.getFont(), text); float cx = width / 2 - layout.width / 2; drawFont(text, cx, y); }
BitmapFont font; SpriteBatch spriteBatch; //... Load any font of your choice first FreeTypeFontGenerator fontGenerator = new FreeTypeFontGenerator( Gdx.files.internal("myFont.ttf") ); FreeTypeFontGenerator.FreeTypeFontParameter freeTypeFontParameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); freeTypeFontParameter.size = size; fontGenerator.generateData(freeTypeFontParameter); font = fontGenerator.generateFont(freeTypeFontParameter); //Initialize the spriteBatch as requirement GlyphLayout glyphLayout = new GlyphLayout(); String item = "Example"; glyphLayout.setText(font,item); float w = glyphLayout.width; font.draw(spriteBatch, glyphLayout, (Game.SCREEN_WIDTH - w)/2, y);
public RegionSpotlight(Skin skin) { whiteTex = skin.getRegion("white"); spotlightBorder = skin.getPatch("custom/white_frame"); font = skin.getFont("default-font"); glText = new GlyphLayout(); colorSpotlight = skin.getColor("orange"); colorTextFrame = new Color(0x333333aa); }
public final void init(DrunkToss ebingeimi) { this.ebingeimi = ebingeimi; batch = new SpriteBatch(50); hudBatch = new SpriteBatch(10); batch.setProjectionMatrix(this.ebingeimi.camera.combined); hudBatch.setProjectionMatrix(this.ebingeimi.hudCamera.combined); font = new BitmapFont(); layout = new GlyphLayout(font, ""); }
public WorldRenderer(World world) { this.world = world; this.cam = new OrthographicCamera(CAMERA_WIDTH, CAMERA_HEIGHT); this.cam.position.set(0f, 0f, 0f); this.cam.update(); spriteBatch = new PolygonSpriteBatch(); renderer = new ShapeRenderer(); layout = new GlyphLayout(); loadTextures(); }
private static void add(Stage stage, String text) { msg.clearActions(); msg.setText(text); GlyphLayout textLayout = new GlyphLayout(); textLayout.setText(msg.getStyle().font, text, Color.BLACK, stage.getWidth() * .8f, Align.center, true); msg.setSize(textLayout.width + textLayout.height, textLayout.height + textLayout.height * 2); if (!stage.getActors().contains(msg, true)) stage.addActor(msg); msg.setPosition(Math.round((stage.getWidth() - msg.getWidth()) / 2), Math.round((stage.getHeight() - msg.getHeight()) / 2)); msg.invalidate(); }
public void setRenderType (RenderType renderType) { this.renderType = renderType; if (renderType != RenderType.FreeType) { if (bitmapFont != null) { bitmapFont.dispose(); generator.dispose(); } } else { String fontFile = getFontFile(); if (fontFile != null) { generator = new FreeTypeFontGenerator(Gdx.files.absolute(fontFile)); FreeTypeFontParameter param = new FreeTypeFontParameter(); param.size = font.getSize(); param.incremental = true; param.flip = true; param.mono = mono; param.gamma = gamma; bitmapFont = generator.generateFont(param); if (bitmapFont.getData().missingGlyph == null) bitmapFont.getData().missingGlyph = bitmapFont.getData().getGlyph('\ufffd'); cache = bitmapFont.newFontCache(); layout = new GlyphLayout(); } } }
public BodiesListItem(RigidBodyModel model, float w, float h, float p, BitmapFont font, Color bgColor) { this.model = model; this.font = font; this.text = model.getName(); this.padding = p; this.bgColor = bgColor; background.setSize(w, h); background.setColor(bgColor); TextureRegion region = Assets.inst().getRegion(model); if (region != null) { image = new Sprite(region); float imgW = image.getWidth() > image.getHeight() ? w - p * 2 : (h - p * 2) * image.getWidth() / image.getHeight(); float imgH = image.getWidth() > image.getHeight() ? (w - p * 2) * image.getHeight() / image.getWidth() : h - p * 2; image.setSize(imgW, imgH); image.setColor(1, 1, 1, IMAGE_OPACITY); } else { image = null; } GlyphLayout glyph = new GlyphLayout(); glyph.setText(font, text); if (glyph.width > w - p * 2) { for (int i = 1; i <= model.getName().length(); i++) { text = model.getName().substring(0, i) + "..."; if (glyph.width > w - p * 2) { text = model.getName().substring(0, i - 1) + "..."; break; } } } }
batch = new SpriteBatch(); layout = new GlyphLayout(); font = new BitmapFont();
GlyphLayout textLayout = new GlyphLayout();