font.getData().setScale(scale); layout.setText(font, TEXT); maxWidth = Math.max(maxWidth, layout.width);
/** Scales the font by the specified amount in both directions. * @see #setScale(float, float) * @throws IllegalArgumentException if scaleX or scaleY is zero. */ public void setScale (float scaleXY) { setScale(scaleXY, scaleXY); }
public void init(BitmapFont fpsBitmapFont, int fontRawPixSize) { this.batch = new SpriteBatch(); this.fpsBitmapFont = fpsBitmapFont; // 计算帧率文本显示位置(为了兼容所有不同尺寸的屏幕) float height = Gdx.graphics.getHeight(); float scale = (height * OCCUPY_HEIGHT_RATIO) / (float) fontRawPixSize; this.fpsBitmapFont.getData().setScale(scale); float scaledFontSize = fontRawPixSize * scale; float offset = scaledFontSize * DISPLAY_ORIGIN_OFFSET_RATIO; x = scaledFontSize - offset; y = scaledFontSize * 1.85F - offset; }
private void scaleAndComputePrefSize () { BitmapFont font = cache.getFont(); float oldScaleX = font.getScaleX(); float oldScaleY = font.getScaleY(); if (fontScaleChanged) font.getData().setScale(fontScaleX, fontScaleY); computePrefSize(); if (fontScaleChanged) font.getData().setScale(oldScaleX, oldScaleY); }
@Override public BitmapFont getFont(String fontName) { BitmapFont bitmapFont = this.assetManager.get(getAssetName(fontName), BitmapFont.class); bitmapFont.getData().setScale(resolutionHelper.getSizeMultiplier(), resolutionHelper.getSizeMultiplier()); return bitmapFont; }
skin.getAtlas().getTextures().iterator().next().setFilter(TextureFilter.Nearest, TextureFilter.Nearest); skin.getFont("default-font").getData().markupEnabled = true; skin.getFont("default-font").getData().setScale(scale); stage = new Stage(new ScreenViewport()); Gdx.input.setInputProcessor(stage);
batch.begin(); font.setColor(0, 0, 1, 1); font.getData().setScale(2); font.draw(batch, "fps: " + Gdx.graphics.getFramesPerSecond() + (useStage ? ", stage" : "sprite"), 10, 40); batch.end();
if (scaledSize != -1) font.getData().setScale(scaledSize / font.getCapHeight()); return font; } catch (RuntimeException ex) {
if (scaledSize != -1) font.getData().setScale(scaledSize / font.getCapHeight()); return font; } catch (RuntimeException ex) {
@Override public void create () { Gdx.input.setInputProcessor(new InputAdapter() { public boolean touchDown (int x, int y, int pointer, int newParam) { renderMode = (renderMode + 1) % 4; return false; } }); spriteBatch = new SpriteBatch(); spriteBatch.setProjectionMatrix(new Matrix4().setToOrtho(0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 0, 0, 1)); texture = new Texture(Gdx.files.internal("data/badlogic.jpg")); logoSprite = new Sprite(texture); logoSprite.flip(false, true); logoSprite.setPosition(0, 320 - 256); logoSprite.setColor(1, 1, 1, 0.5f); font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), Gdx.files.internal("data/verdana39.png"), true); cache1 = font.newFontCache(); cache2 = font.newFontCache(); cache3 = font.newFontCache(); cache4 = font.newFontCache(); cache5 = font.newFontCache(); createCaches("cached", cache1, cache2, cache3, cache4, cache5); font.getData().setScale(1.33f); cacheScaled1 = font.newFontCache(); cacheScaled2 = font.newFontCache(); cacheScaled3 = font.newFontCache(); cacheScaled4 = font.newFontCache(); cacheScaled5 = font.newFontCache(); createCaches("cache scaled", cacheScaled1, cacheScaled2, cacheScaled3, cacheScaled4, cacheScaled5); }
@Override public void render () { red.a = (red.a + Gdx.graphics.getDeltaTime() * 0.1f) % 1; Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); spriteBatch.begin(); logoSprite.draw(spriteBatch); switch (renderMode) { case 0: font.getData().setScale(1); renderNormal("normal"); break; case 1: font.getData().setScale(1); renderCached(); break; case 2: font.getData().setScale(red.a + 0.5f); renderNormal("normal scaled"); break; case 3: font.getData().setScale(1); renderCachedScaled(); break; } spriteBatch.end(); }
/** Scales the font by the specified amount in both directions. * @see #setScale(float, float) * @throws IllegalArgumentException if scaleX or scaleY is zero. */ public void setScale (float scaleXY) { setScale(scaleXY, scaleXY); }
private void scaleAndComputePrefSize () { BitmapFont font = cache.getFont(); float oldScaleX = font.getScaleX(); float oldScaleY = font.getScaleY(); if (fontScaleChanged) font.getData().setScale(fontScaleX, fontScaleY); computePrefSize(); if (fontScaleChanged) font.getData().setScale(oldScaleX, oldScaleY); }
private void scaleAndComputePrefSize () { BitmapFont font = cache.getFont(); float oldScaleX = font.getScaleX(); float oldScaleY = font.getScaleY(); if (fontScaleChanged) font.getData().setScale(fontScaleX, fontScaleY); computePrefSize(); if (fontScaleChanged) font.getData().setScale(oldScaleX, oldScaleY); }
/** Sets the font's scale relative to the current scale. * @see #setScale(float, float) * @throws IllegalArgumentException if the resulting scale is zero. */ public void scale (float amount) { setScale(scaleX + amount, scaleY + amount); }
/** Scales the font by the specified amount in both directions. * @see #setScale(float, float) * @throws IllegalArgumentException if scaleX or scaleY is zero. */ public void setScale (float scaleXY) { setScale(scaleXY, scaleXY); }
/** Sets the font's scale relative to the current scale. * @see #setScale(float, float) * @throws IllegalArgumentException if the resulting scale is zero. */ public void scale (float amount) { setScale(scaleX + amount, scaleY + amount); }