List of usage examples for com.badlogic.gdx.graphics.g2d BitmapFont getScaleY
public float getScaleY()
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;// ww w . j av a 2s . 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.haxtastic.haxmasher.entity.ui.Console.java
License:Apache License
@Override public void draw(SpriteBatch batch, BitmapFont font) { AtlasRegion spriteRegion = Art.regions.get(name); if (width == 0) width = spriteRegion.getRegionWidth(); if (height == 0) height = spriteRegion.getRegionHeight(); if (width < 0) width = -width;//from w w w . j av a 2s . com float posX = x * Constants.PIXELS_PER_METER_X; float posY = y * Constants.PIXELS_PER_METER_Y; batch.draw(spriteRegion, posX, posY, width * Constants.PIXELS_PER_METER_X, height * Constants.PIXELS_PER_METER_Y); //Draw text font.setColor(0, 0, 0, 1); float sX = font.getScaleX(); float sY = font.getScaleY(); font.setScale(1.1f, 1.1f); String msg = null; int i = 0; ListIterator<String> iter = lines.listIterator(lines.size()); while (iter.hasPrevious()) { msg = iter.previous(); posX = linex * Constants.PIXELS_PER_METER_X; posY = (liney + (space * i)) * Constants.PIXELS_PER_METER_Y + (font.getBounds(msg).height * i); font.draw(batch, msg, posX, posY); i++; } font.setScale(sX, sY); }
From source file:com.haxtastic.haxmasher.scene.Stats.java
License:Apache License
@Override public void draw(float dt, SpriteBatch batch, BitmapFont font) { if (parent != null) parent.draw(dt, batch, font);/*www. j a v a 2 s. co m*/ Iterator<Actor> iter = getActors().iterator(); while (iter.hasNext()) { Actor actor = iter.next(); actor.draw(batch, font); } font.setColor(0, 0, 0, 1); float sX = font.getScaleX(); float sY = font.getScaleY(); font.setScale(1.575f, 1.725f); String msg = "You have gained " + level; msg += (level > 1 ? " levels." : " level."); float posX = (Constants.Positions.pointsTextX) * Constants.PIXELS_PER_METER_X + (font.getBounds(" to spend").width / 2); float posY = (Constants.Positions.pointsTextY + 0.1f) * Constants.PIXELS_PER_METER_Y + (font.getBounds(msg).height); font.draw(batch, msg, posX, posY); msg = "You have " + points + " skill points to spend."; posX = Constants.Positions.pointsTextX * Constants.PIXELS_PER_METER_X; posY = Constants.Positions.pointsTextY * Constants.PIXELS_PER_METER_Y; font.draw(batch, msg, posX, posY); msg = Constants.Stats.healthWeight + " * " + (PlayerStats.pHealth + PlayerStats.level); posX = Constants.Buttons.healthTextX * Constants.PIXELS_PER_METER_X - (font.getBounds(msg).width / 2); posY = Constants.Buttons.pointsY * Constants.PIXELS_PER_METER_Y + (font.getBounds(msg).height); font.draw(batch, msg, posX, posY); msg = Constants.Stats.damageWeight + " * " + (PlayerStats.pDamage + PlayerStats.level); posX = Constants.Buttons.damageTextX * Constants.PIXELS_PER_METER_X - (font.getBounds(msg).width / 2); posY = Constants.Buttons.pointsY * Constants.PIXELS_PER_METER_Y + (font.getBounds(msg).height); font.draw(batch, msg, posX, posY); msg = Constants.Stats.armorWeight + " * " + (PlayerStats.pArmor + PlayerStats.level); posX = Constants.Buttons.armorTextX * Constants.PIXELS_PER_METER_X - (font.getBounds(msg).width / 2); posY = Constants.Buttons.pointsY * Constants.PIXELS_PER_METER_Y + (font.getBounds(msg).height); font.draw(batch, msg, posX, posY); msg = Constants.Stats.critWeight + " * " + (PlayerStats.pCrit + PlayerStats.level); posX = Constants.Buttons.critTextX * Constants.PIXELS_PER_METER_X - (font.getBounds(msg).width / 2); posY = Constants.Buttons.pointsY * Constants.PIXELS_PER_METER_Y + (font.getBounds(msg).height); font.draw(batch, msg, posX, posY); font.setScale(sX, sY); }