List of usage examples for com.badlogic.gdx.graphics.g2d BitmapFont setScale
public void setScale(float scaleXY)
From source file:com.badlydrawngames.veryangryrobots.WorldView.java
License:Apache License
private void drawFlyups() { BitmapFont font = Assets.flyupFont; float scale = font.getScaleX(); font.setScale(1.0f / Assets.pixelDensity); spriteBatch.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE); for (Flyup flyup : flyupManager.flyups) { if (flyup.active) { font.draw(spriteBatch, flyup.scoreString, flyup.x, flyup.y); }/*from ww w.j a v a 2 s.c o m*/ } spriteBatch.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); font.setScale(scale); }
From source file:com.game.libgdx.roguelikeengine.PopupInfoText.java
License:Open Source License
public void drawScreen(SpriteBatch batch, BitmapFont font, String text, float fadein, int linedist, Color color, boolean resize) { float scaleX = font.getScaleX(); float scaleY = font.getScaleY(); update_x((int) (Gdx.graphics.getWidth() * 0.5f - this.width * 0.5f)); update_y((int) (Gdx.graphics.getHeight() * 0.5f - this.height * 0.5f)); mouseOverElement = ""; if (!lastMessage.equals(text) || resize) { this.clearRenderWords(); lineCount = 0;/* w w w.j a v a 2 s.c o m*/ int linepos = 0; int currentWidth = textoffsetx; int nextWidth = 0; int maxWidth = (int) (width - textoffsetx); String[] words = null; for (String line : text.split("\n")) { lineCount = lineCount + 1; currentWidth = textoffsetx; words = line.split(" "); for (String word : words) { if (word.contains("\t")) { word = word.replace("\t", " "); } Color wordColor = color; if (word.length() > 7) { String hex = word.substring(0, 7); if (Pattern.matches(colorPattern, hex)) { wordColor = this.hex2Rgb(hex); word = word.replace(hex, ""); } } nextWidth = (int) (currentWidth + font.getBounds(word + " ").width); if (nextWidth > maxWidth) { currentWidth = textoffsetx; nextWidth = (int) (currentWidth + font.getBounds(word + " ").width); linepos = linepos + 1; lineCount = lineCount + 1; } int wordx = currentWidth; int wordy = height - ((textoffsety) + (linepos * linedist)); this.addWordToRender(word, new WordRectangle(wordx, wordy, font.getBounds(word + " ").width, font.getLineHeight()) .withColor(wordColor)); currentWidth = nextWidth; } linepos++; currentWidth = x + textoffsetx; } } this.background.draw(batch, x, y, width, height); while (((lineCount * font.getLineHeight() + lineCount * linedist) * font.getScaleY()) > height - textoffsety) { font.setScale(font.getScaleY() - 0.1f); } if (font.getScaleY() != scaleY) { drawScreen(batch, font, text, fadein, linedist, color, true); font.setScale(scaleX, scaleY); return; } boolean anyClickable = false; Set<Entry<String, LinkedList<WordRectangle>>> keys = renderWords.entrySet(); for (Entry<String, LinkedList<WordRectangle>> entry : keys) { for (WordRectangle rect : entry.getValue()) { font.setColor(rect.color.r, rect.color.g, rect.color.b, fadein); if (wordClickListeners.containsKey(entry.getKey())) { if (mouseOverWord(rect, font)) { font.setColor(Color.BLUE.r, Color.BLUE.g, Color.BLUE.b, fadein); mouseOverElement = entry.getKey(); } else { font.setColor(Color.CYAN); font.setColor(Color.CYAN.r, Color.CYAN.g, Color.CYAN.b, fadein); } anyClickable = true; } font.draw(batch, entry.getKey().replace("_", " "), rect.x + x, rect.y + y); } } if (!anyClickable) { Color c = font.getColor(); font.setColor(instructionsColor.r, instructionsColor.g, instructionsColor.b, fadein); font.draw(batch, instructions, x + (width * 0.5f) - (font.getBounds(instructions).width * 0.5f), y + font.getBounds(instructions).height + Gdx.graphics.getHeight() * 0.05f); font.setColor(c); } lastMessage = text; font.setScale(scaleX, scaleY); }
From source file:com.havidarou.MeduNetjer.scene2d.ui.AbstractButton.java
License:Apache License
public AbstractButton(BitmapFont bitMapFont, Drawable up, Drawable down, float width, float height, boolean DIPActive) { super(up, down); this.bitMapFont = bitMapFont; this.DIPActive = DIPActive; ///*from ww w . ja v a 2s .c o m*/ if (DIPActive) { setSize(width * AppSettings.getWorldSizeRatio(), height * AppSettings.getWorldSizeRatio()); if (this.bitMapFont != null) { bitMapFont.setScale(AppSettings.getWorldSizeRatio()); } } }
From source file:com.havidarou.MeduNetjer.scene2d.ui.AbstractButton.java
License:Apache License
/** * Set the font/*w w w . j a v a 2 s . com*/ */ public void setBitMapFont(BitmapFont bitMapFont) { this.bitMapFont = bitMapFont; if (DIPActive) { bitMapFont.setScale(AppSettings.getWorldSizeRatio()); } }
From source file:com.havidarou.MeduNetjer.scene2d.ui.Text.java
License:Apache License
public Text(BitmapFont bitMapFont, float width, float height, boolean DIPActive) { super(width, height, DIPActive); this.bitMapFont = bitMapFont; ///*ww w .ja v a2 s .c o m*/ if (DIPActive) { bitMapFont.setScale(AppSettings.getWorldSizeRatio()); } }
From source file:com.havidarou.MeduNetjer.scene2d.ui.Text.java
License:Apache License
public void setBitMapFont(BitmapFont bitMapFont, boolean DIPActive) { this.bitMapFont = bitMapFont; ////from w w w .j a v a2 s . c o m if (DIPActive) { bitMapFont.setScale(AppSettings.getWorldSizeRatio()); } }
From source file:com.jmstudios.pointandhit.MainMenuScreen.java
License:Open Source License
public MainMenuScreen(final OneShotGame game) { this.game = game; this.stage = new Stage(); this.scale = game.scale; this.table = new Table(); this.buttonsTable = new Table(); table.setFillParent(true);//from w w w . j a v a2 s.c om //buttonsTable.setDebug(true); stage.addActor(table); float padding = 40 * scale; Vector2 screenSize = new Vector2(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); BitmapFont titleFont = new BitmapFont(Gdx.files.internal("fonts/deja_vu_sans_large.fnt")); titleFont.setScale(scale); Label.LabelStyle titleLabelStyle = new Label.LabelStyle(titleFont, Color.WHITE); titleText = new Label("Point & Hit", titleLabelStyle); titleText.setWrap(true); titleText.setWidth(screenSize.x - padding * 2); titleText.setAlignment(Align.center); // Set up buttons Texture buttonsTex = game.buttons; Texture bigPlayButton = new Texture(Gdx.files.internal("buttons/play_button.png")); TextureRegion playTex = new TextureRegion(bigPlayButton), optionsTex = new TextureRegion(buttonsTex, 0, 256, 256, 256), tutorialTex = new TextureRegion(buttonsTex, 768, 0, 256, 256), exitTex = new TextureRegion(buttonsTex, 256, 256, 256, 256); TextureRegionDrawable playDrawable = new TextureRegionDrawable(playTex), optionsDrawable = new TextureRegionDrawable(optionsTex), tutorialDrawable = new TextureRegionDrawable(tutorialTex), exitDrawable = new TextureRegionDrawable(exitTex); playButton = new ImageButton(playDrawable); optionsButton = new ImageButton(optionsDrawable); tutorialButton = new ImageButton(tutorialDrawable); exitButton = new ImageButton(exitDrawable); // Set up buttonsTable buttonsTable.defaults().pad(padding); buttonsTable.add(playButton).colspan(3).center().padBottom(2.5f * padding) .width(scale * playButton.getWidth()).height(scale * playButton.getHeight()); buttonsTable.row(); buttonsTable.add(tutorialButton).width(scale * tutorialButton.getWidth()) .height(scale * tutorialButton.getHeight()); buttonsTable.add(optionsButton).width(scale * optionsButton.getWidth()) .height(scale * optionsButton.getHeight()); // Title table.defaults().pad(padding); table.add(titleText).width(screenSize.x - padding * 2).center(); table.row(); table.add(buttonsTable).center(); // Listeners tutorialButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { game.setScreen(new TutorialScreen(game, false)); } }); playButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { if (game.preferences.getBoolean("tutorial", false)) { game.setScreen(game.getGameScreen()); } else { game.setScreen(new TutorialScreen(game, false)); } } }); optionsButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { game.setScreen(new OptionsScreen(game)); } }); exitButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { game.setScreen(new CreditsScreen(game)); } }); }
From source file:com.jmstudios.pointandhit.NoCompassScreen.java
License:Open Source License
@Override public void show() { stage = new Stage(); table = new Table(); float padding = 50 * scale; BitmapFont font = new BitmapFont(Gdx.files.internal("fonts/deja_vu_sans_medium.fnt")); Vector2 screenSize = new Vector2(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); font.setScale(scale); Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE); messageLabel = new Label(text, labelStyle); messageLabel.setWrap(true);//from ww w . j a v a 2s . c o m messageLabel.setWidth(screenSize.x - padding * 2); messageLabel.setAlignment(Align.center); table.setFillParent(true); table.defaults().pad(padding); table.add(messageLabel).width(screenSize.x - padding * 2); stage.addActor(table); }
From source file:com.jmstudios.pointandhit.OptionsScreen.java
License:Open Source License
public OptionsScreen(final OneShotGame game) { this.game = game; this.scale = game.scale; Vector2 screenSize = new Vector2(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); // Font/*from w w w . jav a 2s . c o m*/ textFont = new BitmapFont(Gdx.files.internal("fonts/deja_vu_sans_medium.fnt")); textFont.setScale(scale); BitmapFont titleFont = new BitmapFont(Gdx.files.internal("fonts/deja_vu_sans_large.fnt")); titleFont.setScale(scale); // Checkbox style Texture checkBoxes = new Texture(Gdx.files.internal("buttons/radiobutton.png")); TextureRegionDrawable checkBoxUnchecked = new TextureRegionDrawable( new TextureRegion(checkBoxes, 0, 0, 64, 64)); TextureRegionDrawable checkBoxChecked = new TextureRegionDrawable( new TextureRegion(checkBoxes, 64, 0, 64, 64)); checkBoxStyle = new CheckBox.CheckBoxStyle(checkBoxUnchecked, checkBoxChecked, textFont, Color.WHITE); CheckBox verySensitive = newRadioButton("Very sensitive"), sensitive = newRadioButton("Sensitive"), normal = newRadioButton("Normal"), forgiving = newRadioButton("Forgiving"), veryForgiving = newRadioButton("Very forgiving"), invertControls = newRadioButton("Invert the controls"); sensitivityGroup = new ButtonGroup<CheckBox>(verySensitive, sensitive, normal, forgiving, veryForgiving, invertControls); int startSetting = game.preferences.getInteger("sensitivity", 2); sensitivityGroup.uncheckAll(); sensitivityGroup.getButtons().get(startSetting).setChecked(true); float padding = 20 * scale; // Title Table titleTable = new Table(); titleTable.align(Align.topLeft); Pixmap backgroundPixmap = new Pixmap(1, 1, Format.RGBA8888); backgroundPixmap.setColor(new Color(0.9f, 0.35f, 0.1f, 1)); backgroundPixmap.fill(); titleTable.setBackground(new TextureRegionDrawable(new TextureRegion(new Texture(backgroundPixmap)))); Label.LabelStyle titleLabelStyle = new Label.LabelStyle(titleFont, Color.WHITE); Label titleLabel = new Label("Control sensitivity", titleLabelStyle); titleLabel.setWrap(true); titleLabel.setWidth(screenSize.x - padding * 2); titleLabel.setAlignment(Align.center); titleTable.add(titleLabel).align(Align.topLeft).pad(2 * padding).width(screenSize.x - padding * 2); // Checkboxes optionsTable = new Table(); optionsTable.align(Align.topLeft); optionsTable.defaults().align(Align.topLeft).pad(padding).padBottom(0).padLeft(2 * padding); optionsTable.row(); optionsTable.add(verySensitive); optionsTable.row(); optionsTable.add(sensitive); optionsTable.row(); optionsTable.add(normal); optionsTable.row(); optionsTable.add(forgiving); optionsTable.row(); optionsTable.add(veryForgiving); optionsTable.row(); optionsTable.add(invertControls); optionsTable.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { int newSensitivity = sensitivityGroup.getCheckedIndex(); if (newSensitivity == -1) newSensitivity = 2; game.preferences.putInteger("sensitivity", newSensitivity); game.preferences.flush(); } }); mainTable = new Table(); mainTable.setFillParent(true); mainTable.align(Align.top); mainTable.add(titleTable).pad(0).padBottom(padding * 4).fill(10, 1).align(Align.topLeft); mainTable.row(); mainTable.add(optionsTable).align(Align.left); mainStage = new Stage(); mainStage.addActor(mainTable); // Input inputMultiplexer = new InputMultiplexer(); inputMultiplexer.addProcessor(mainStage); inputMultiplexer.addProcessor(this); }
From source file:com.laex.cg2d.render.impl.ScreenManagerImpl.java
License:Open Source License
@Override public void drawText(String text, float x, float y) { BitmapFont font = new BitmapFont(); spriteBatch.begin();//from w ww .j ava 2 s. co m font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear); font.setScale(0.1f); font.draw(spriteBatch, text, x, y); spriteBatch.end(); }