List of usage examples for com.badlogic.gdx.graphics.g2d BitmapFont draw
public TextBounds draw(Batch batch, CharSequence str, float x, float y)
From source file:at.juggle.games.counting.CountingGameModel.java
License:Apache License
public void drawGameState(SpriteBatch batch, float delta, BitmapFont buttonFont) { animationTime += delta * 10;// ww w . j ava 2 s . c o m balloonList = getBalloonList(); for (int i = 0; i < balloonList.size(); i++) { for (int j = 0; j < balloonList.size(); j++) { if (i != j) { // check for collision float distX = (balloonList.get(i).getX() - balloonList.get(j).getX()); float distY = (balloonList.get(i).getY() - balloonList.get(j).getY()); if (Math.abs(distX) < balloonList.get(i).getWidth() && Math.abs(distY) < balloonList.get(i).getHeight()) { // it's a collision balloonList.get(i).setPosition(balloonList.get(i).getX() + distX * 0.05f, balloonList.get(i).getY() + distY * 0.05f); } } } balloonList.get(i).draw(batch, delta); // batch.draw(spriteAnimRed[((int) (animationTime % spriteAnimRed.length))], sprite.getX(), sprite.getY()); } for (int i = 0; i < answers.length; i++) { String answer = Integer.toString(answers[i]); layout.setText(buttonFont, answer); if (answerIsGiven && answers[i] == numberOfSprites) buttonFont.setColor(Color.GREEN); else buttonFont.setColor(Color.BLACK); float posX = CountingGame.GAME_WIDTH / 4 * (i + 1) - layout.width / 2; buttonFont.draw(batch, answer, posX, posButtonsY); } }
From source file:at.juggle.games.counting.gameobjects.Balloon.java
License:Apache License
public void draw(SpriteBatch batch, float delta, BitmapFont font) { draw(batch, delta);//from w w w .j av a 2s . co m if (number > 0) { // find center of the baloon ... String str = "" + number; layout.setText(font, str); font.draw(batch, str, getX() + getWidth() / 2 - layout.width / 2, getY() + getHeight() / 2 + layout.height / 2 + 48); } }
From source file:CB_Locator.Map.MapViewBase.java
License:Open Source License
protected void renderDebugInfo(Batch batch) { CB_RectF r = this.thisWorldRec; Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST); BitmapFont font = Fonts.getNormal(); font.setColor(Color.BLACK);//from w w w . j ava2 s. com Matrix4 def = new Matrix4().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); def.translate(r.getX(), r.getY(), 1); batch.setProjectionMatrix(def); // str = debugString; font.draw(batch, str, 20, 120); str = "fps: " + Gdx.graphics.getFramesPerSecond(); font.draw(batch, str, 20, 100); str = String.valueOf(aktZoom) + " - camzoom: " + Math.round(camera.zoom * 100) / 100; font.draw(batch, str, 20, 80); str = "lTiles: " + mapTileLoader.LoadedTilesSize() + " - qTiles: " + mapTileLoader.QueuedTilesSize(); font.draw(batch, str, 20, 60); str = "lastMove: " + lastMovement.x + " - " + lastMovement.y; font.draw(batch, str, 20, 20); Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST); }
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); }// w w w. j a v a2 s .c om } spriteBatch.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); font.setScale(scale); }
From source file:com.bladecoder.engine.ui.CreditsScreen.java
License:Apache License
public void drawCenteredScreenX(SpriteBatch batch, BitmapFont font, CharSequence str, float y, int viewportWidth) { float x = 0;/*from w w w . j a v a2s . co m*/ layout.setText(font, str, Color.WHITE, viewportWidth, Align.center, true); //x = (viewportWidth - layout.width)/2; font.draw(batch, layout, x, y); }
From source file:com.bladecoder.engine.ui.defaults.DefaultSceneScreen.java
License:Apache License
private void drawHotspots(SpriteBatch batch) { final World world = World.getInstance(); for (BaseActor a : world.getCurrentScene().getActors().values()) { if (!(a instanceof InteractiveActor) || !a.isVisible() || a == world.getCurrentScene().getPlayer()) continue; InteractiveActor ia = (InteractiveActor) a; if (!ia.canInteract()) continue; Polygon p = a.getBBox();/* www . j ava 2 s. c om*/ if (p == null) { EngineLogger.error("ERROR DRAWING HOTSPOT FOR: " + a.getId()); } Rectangle r = a.getBBox().getBoundingRectangle(); unprojectTmp.set(r.getX() + r.getWidth() / 2, r.getY() + r.getHeight() / 2, 0); world.getSceneCamera().scene2screen(viewport, unprojectTmp); if (!showDesc || ia.getDesc() == null) { float size = DPIUtils.ICON_SIZE * DPIUtils.getSizeMultiplier(); if (ia.getVerb("leave") != null) { TextureRegionDrawable drawable = (TextureRegionDrawable) getUI().getSkin().getDrawable("leave"); // drawable.draw(batch, unprojectTmp.x - size / 2, // unprojectTmp.y - size / 2, size, size); drawable.draw(batch, unprojectTmp.x - size / 2, unprojectTmp.y - size / 2, size / 2, size / 2, size, size, 1.0f, 1.0f, calcLeaveArrowRotation(ia)); } else { Drawable drawable = ((TextureRegionDrawable) getUI().getSkin().getDrawable("hotspot")) .tint(Color.RED); drawable.draw(batch, unprojectTmp.x - size / 2, unprojectTmp.y - size / 2, size, size); } } else { BitmapFont font = getUI().getSkin().getFont("desc"); String desc = ia.getDesc(); if (desc.charAt(0) == I18N.PREFIX) desc = I18N.getString(desc.substring(1)); textLayout.setText(font, desc); float textX = unprojectTmp.x - textLayout.width / 2; float textY = unprojectTmp.y + textLayout.height; RectangleRenderer.draw(batch, textX - 8, textY - textLayout.height - 8, textLayout.width + 16, textLayout.height + 16, Color.BLACK); font.draw(batch, textLayout, textX, textY); } } }
From source file:com.bladecoder.engine.ui.retro.RetroSceneScreen.java
License:Apache License
private void drawHotspots(SpriteBatch batch) { final World world = World.getInstance(); for (BaseActor a : world.getCurrentScene().getActors().values()) { if (!(a instanceof InteractiveActor) || !a.isVisible() || a == world.getCurrentScene().getPlayer()) continue; InteractiveActor ia = (InteractiveActor) a; if (!ia.canInteract()) continue; Polygon p = a.getBBox();//from w w w . j av a 2s .c o m if (p == null) { EngineLogger.error("ERROR DRAWING HOTSPOT FOR: " + a.getId()); } Rectangle r = a.getBBox().getBoundingRectangle(); unprojectTmp.set(r.getX() + r.getWidth() / 2, r.getY() + r.getHeight() / 2, 0); world.getSceneCamera().scene2screen(worldViewport, unprojectTmp); if (world.getInventory().isVisible()) { // unprojectTmp.y += verbUI.getHeight(); } if (ia.getDesc() == null) { float size = DPIUtils.ICON_SIZE * DPIUtils.getSizeMultiplier(); Drawable drawable = ((TextureRegionDrawable) getUI().getSkin().getDrawable("circle")) .tint(Color.RED); drawable.draw(batch, unprojectTmp.x - size / 2, unprojectTmp.y - size / 2, size, size); } else { BitmapFont font = getUI().getSkin().getFont("desc"); String desc = ia.getDesc(); if (desc.charAt(0) == I18N.PREFIX) desc = I18N.getString(desc.substring(1)); textLayout.setText(font, desc); float textX = unprojectTmp.x - textLayout.width / 2; float textY = unprojectTmp.y + textLayout.height; RectangleRenderer.draw(batch, textX - 8, textY - textLayout.height - 8, textLayout.width + 16, textLayout.height + 16, Color.BLACK); font.draw(batch, textLayout, textX, textY); } } }
From source file:com.bladecoder.engineeditor.ui.components.CellRenderer.java
License:Apache License
public void draw(Batch batch, float parentAlpha, T item, boolean selected, float x, float y, float width, float height) { BitmapFont font = style.font; Drawable selectedDrawable = style.selection; Color fontColorSelected = style.fontColorSelected; Color fontColorUnselected = style.fontColorUnselected; if (selected) { selectedDrawable.draw(batch, x, y - height, width, height); font.setColor(fontColorSelected.r, fontColorSelected.g, fontColorSelected.b, fontColorSelected.a * parentAlpha); } else {// w ww . j a va 2 s.c o m font.setColor(fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b, fontColorUnselected.a * parentAlpha); } if (hasImage()) { TextureRegion r = getCellImage(item); float ih = r.getRegionHeight(); float iw = r.getRegionWidth(); if (ih > getItemHeight() - MARGIN) { ih = getItemHeight() - MARGIN; iw *= ih / r.getRegionHeight(); } batch.draw(r, x, y - ih - MARGIN / 2, iw, ih); x += iw; } font.draw(batch, getCellTitle(item), x + textOffsetX, y - textOffsetY); if (hasSubtitle()) { String sub = getCellSubTitle(item); if (sub != null) { if (selected) { style.subtitleFont.setColor(fontColorSelected.r, fontColorSelected.g, fontColorSelected.b, fontColorSelected.a * parentAlpha * 0.5f); } else { style.subtitleFont.setColor(fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b, fontColorUnselected.a * parentAlpha * 0.5f); } style.subtitleFont.draw(batch, sub, x + textOffsetX, y - textOffsetY - (font.getCapHeight() - font.getDescent() * 2)); } } }
From source file:com.evoluzion.Organismo.java
License:Open Source License
public void verMarcado(ShapeRenderer sr, SpriteBatch sb, BitmapFont f) { if (marcado == -1) { sr.begin(ShapeType.Rectangle); sr.setColor(Color.GREEN); sr.rect(borde.x - 2, borde.y - 2, borde.width + 4, borde.height + 4); sr.end();/* w w w.ja v a2s. com*/ sb.begin(); f.setColor(Color.GREEN); f.draw(sb, nombre, posicion.x + ancho + 5, posicion.y + (alto) + 5); f.draw(sb, "" + format.format(energia), posicion.x + ancho + 5, posicion.y); sb.end(); } }
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;//from w w w . j a v a 2s.c om 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); }