Java Code Examples for com.badlogic.gdx.graphics.g2d.BitmapFont#draw()
The following examples show how to use
com.badlogic.gdx.graphics.g2d.BitmapFont#draw() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NavMeshDebugDrawer.java From GdxDemo3D with Apache License 2.0 | 6 votes |
private void drawNavMeshIndices(SpriteBatch spriteBatch, Camera camera, BitmapFont font) { // TODO: Get rid of all the transform matrix setting if (spriteBatch.isDrawing()) { spriteBatch.end(); } spriteBatch.begin(); spriteBatch.setProjectionMatrix(camera.combined); for (int i = 0; i < navMesh.graph.getNodeCount(); i++) { Triangle t = navMesh.graph.getTriangleFromGraphIndex(i); if (triangleIsVisible(t)) { tmpMatrix.set(camera.view).inv().getRotation(tmpQuat); tmpMatrix.setToTranslation(t.centroid).rotate(tmpQuat); spriteBatch.setTransformMatrix(tmpMatrix); font.draw(spriteBatch, Integer.toString(t.triIndex), 0, 0); } } spriteBatch.end(); }
Example 2
Source File: HighlightTextArea.java From vis-ui with Apache License 2.0 | 6 votes |
@Override protected void drawText (Batch batch, BitmapFont font, float x, float y) { maxAreaHeight = 0; float offsetY = 0; for (int i = firstLineShowing * 2; i < (firstLineShowing + linesShowing) * 2 && i < linesBreak.size; i += 2) { for (Chunk chunk : renderChunks) { if (chunk.lineIndex == i) { font.setColor(chunk.color); font.draw(batch, chunk.text, x + chunk.offsetX, y + offsetY); } } offsetY -= font.getLineHeight(); maxAreaHeight += font.getLineHeight(); } maxAreaHeight += 30; }
Example 3
Source File: MyButton.java From killingspree with MIT License | 5 votes |
public void render(SpriteBatch batch, BitmapFont font, float delta){ if (active) { font.setColor(1, 1, 1, 1); font.draw(batch, text, x + MathUtils.random(0, 1), y + MathUtils.random(0, 1)); } else { font.setColor(0.5f, 0.5f, 0.5f, 1); font.draw(batch, text, x, y); } slackTime += delta; }
Example 4
Source File: VisTextArea.java From vis-ui with Apache License 2.0 | 5 votes |
@Override protected void drawText (Batch batch, BitmapFont font, float x, float y) { float offsetY = 0; for (int i = firstLineShowing * 2; i < (firstLineShowing + linesShowing) * 2 && i < linesBreak.size; i += 2) { font.draw(batch, displayText, x, y + offsetY, linesBreak.items[i], linesBreak.items[i + 1], 0, Align.left, false); offsetY -= font.getLineHeight(); } }
Example 5
Source File: RenderSystem.java From riiablo with Apache License 2.0 | 4 votes |
private void drawDebugSpecial(ShapeRenderer shapes) { for (int i = Map.WALL_OFFSET, x, y; i < Map.WALL_OFFSET + Map.MAX_WALLS; i++) { int startX2 = startX; int startY2 = startY; float startPx2 = startPx; float startPy2 = startPy; for (y = 0; y < viewBuffer.length; y++) { int tx = startX2; int ty = startY2; int stx = tx * Tile.SUBTILE_SIZE; int sty = ty * Tile.SUBTILE_SIZE; float px = startPx2; float py = startPy2; int size = viewBuffer[y]; for (x = 0; x < size; x++) { Map.Zone zone = map.getZone(stx, sty); if (zone != null) { DS1.Cell cell = zone.getCell(i, tx, ty); if (cell != null) { if (Map.ID.POPPADS.contains(cell.id)) { shapes.setColor(Map.ID.getColor(cell)); Map.Preset preset = zone.getGrid(tx, ty); Map.Preset.PopPad popPad = preset.popPads.get(cell.id); if (popPad.startX == zone.getGridX(tx) && popPad.startY == zone.getGridY(ty)) { int width = popPad.endX - popPad.startX; int height = popPad.endY - popPad.startY; iso.getPixOffset(tmpVec2); float offsetX = tmpVec2.x; float offsetY = tmpVec2.y; iso.toScreen(tmpVec2.set(stx, sty)); float topLeftX = tmpVec2.x - offsetX; float topLeftY = tmpVec2.y - offsetY; iso.toScreen(tmpVec2.set(stx, sty).add(width, 0)); float topRightX = tmpVec2.x - offsetX; float topRightY = tmpVec2.y - offsetY; iso.toScreen(tmpVec2.set(stx, sty).add(0, height)); float bottomLeftX = tmpVec2.x - offsetX; float bottomLeftY = tmpVec2.y - offsetY; iso.toScreen(tmpVec2.set(stx, sty).add(width, height)); float bottomRightX = tmpVec2.x - offsetX; float bottomRightY = tmpVec2.y - offsetY; shapes.line(topLeftX, topLeftY, topRightX, topRightY); shapes.line(topRightX, topRightY, bottomRightX, bottomRightY); shapes.line(bottomRightX, bottomRightY, bottomLeftX, bottomLeftY); shapes.line(bottomLeftX, bottomLeftY, topLeftX, topLeftY); } } else { shapes.setColor(Color.WHITE); DebugUtils.drawDiamond2(shapes, px, py, Tile.WIDTH, Tile.HEIGHT); } shapes.end(); batch.begin(); batch.setShader(null); BitmapFont font = Riiablo.fonts.consolas12; String str = String.format("%s%n%08x", Map.ID.getName(cell.id), cell.value); GlyphLayout layout = new GlyphLayout(font, str, 0, str.length(), font.getColor(), 0, Align.center, false, null); font.draw(batch, layout, px + Tile.WIDTH50, py + Tile.HEIGHT50 + font.getLineHeight() / 4); batch.end(); batch.setShader(Riiablo.shader); shapes.begin(ShapeRenderer.ShapeType.Line); } } tx++; stx += Tile.SUBTILE_SIZE; px += Tile.WIDTH50; py -= Tile.HEIGHT50; } startY2++; if (y >= tilesX - 1) { startX2++; startPy2 -= Tile.HEIGHT; } else { startX2--; startPx2 -= Tile.WIDTH; } } } }
Example 6
Source File: Client.java From riiablo with Apache License 2.0 | 4 votes |
private void drawLoading(Batch b) { BitmapFont font = console.getFont(); if (font == null) return; GlyphLayout ellipsis = new GlyphLayout(font, "Loading... " + (int) (Riiablo.assets.getProgress() * 100) + "%"); font.draw(b, ellipsis, 0, ellipsis.height); }
Example 7
Source File: Client.java From riiablo with Apache License 2.0 | 4 votes |
private void drawFps(Batch b) { BitmapFont font = console.getFont(); if (font == null) return; StringBuilder builder = new StringBuilder(64); builder .append(String.format("%d FPS", Gdx.graphics.getFramesPerSecond())) .append('\n').append(String.format("MEM: %d / %d MB", Gdx.app.getJavaHeap() / (1 << 20), Runtime.getRuntime().totalMemory() / (1 << 20))) .append('\n').append(String.format("Ping: %3d ms", Riiablo.metrics.ping)) .append('\n').append(String.format("RTT: %3d ms", Riiablo.metrics.rtt)) .append('\n').append(String.format("CPU: %2.1f ms", Riiablo.metrics.cpu)) .append('\n').append(String.format("GPU: %2.1f ms", Riiablo.metrics.gpu)) ; fps.setText(font, builder.toString()); int drawFpsMethod = this.drawFpsMethod; if (forceDrawFps && drawFpsMethod == FPS_NONE) { drawFpsMethod = FPS_TOPLEFT; } float x, y; switch (drawFpsMethod) { case FPS_TOPLEFT: x = 2; y = Riiablo.viewport.getScreenHeight() - 2; break; case FPS_TOPRIGHT: x = Riiablo.viewport.getScreenWidth() - fps.width; y = viewportHeight - 2; break; case FPS_BOTTOMLEFT: x = 2; y = fps.height; break; case FPS_BOTTOMRIGHT: x = Riiablo.viewport.getScreenWidth() - fps.width; y = fps.height; break; default: Gdx.app.error(TAG, "Invalid draw fps method: " + drawFpsMethod); return; } font.draw(b, fps, x, y); }
Example 8
Source File: VisTextField.java From vis-ui with Apache License 2.0 | 4 votes |
@Override public void draw (Batch batch, float parentAlpha) { Stage stage = getStage(); boolean focused = stage != null && stage.getKeyboardFocus() == this; if (!focused) keyRepeatTask.cancel(); final BitmapFont font = style.font; final Color fontColor = (disabled && style.disabledFontColor != null) ? style.disabledFontColor : ((focused && style.focusedFontColor != null) ? style.focusedFontColor : style.fontColor); final Drawable selection = style.selection; final Drawable cursorPatch = style.cursor; Drawable background = (disabled && style.disabledBackground != null) ? style.disabledBackground : ((focused && style.focusedBackground != null) ? style.focusedBackground : style.background); // vis if (!disabled && style.backgroundOver != null && (clickListener.isOver() || focused)) { background = style.backgroundOver; } Color color = getColor(); float x = getX(); float y = getY(); float width = getWidth(); float height = getHeight(); batch.setColor(color.r, color.g, color.b, color.a * parentAlpha); float bgLeftWidth = 0, bgRightWidth = 0; if (background != null) { background.draw(batch, x, y, width, height); bgLeftWidth = background.getLeftWidth(); bgRightWidth = background.getRightWidth(); } float textY = getTextY(font, background); calculateOffsets(); if (focused && hasSelection && selection != null) { drawSelection(selection, batch, font, x + bgLeftWidth, y + textY); } float yOffset = font.isFlipped() ? -textHeight : 0; if (displayText.length() == 0) { if (!focused && messageText != null) { if (style.messageFontColor != null) { font.setColor(style.messageFontColor.r, style.messageFontColor.g, style.messageFontColor.b, style.messageFontColor.a * color.a * parentAlpha); } else font.setColor(0.7f, 0.7f, 0.7f, color.a * parentAlpha); BitmapFont messageFont = style.messageFont != null ? style.messageFont : font; messageFont.draw(batch, messageText, x + bgLeftWidth, y + textY + yOffset, 0, messageText.length(), width - bgLeftWidth - bgRightWidth, textHAlign, false, "..."); } } else { font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * color.a * parentAlpha); drawText(batch, font, x + bgLeftWidth, y + textY + yOffset); } if (drawBorder && focused && !disabled) { blink(); if (cursorOn && cursorPatch != null) { drawCursor(cursorPatch, batch, font, x + bgLeftWidth, y + textY); } } // vis if (isDisabled() == false && inputValid == false && style.errorBorder != null) style.errorBorder.draw(batch, getX(), getY(), getWidth(), getHeight()); else if (focusBorderEnabled && drawBorder && style.focusBorder != null) style.focusBorder.draw(batch, getX(), getY(), getWidth(), getHeight()); }
Example 9
Source File: VisTextField.java From vis-ui with Apache License 2.0 | 4 votes |
protected void drawText (Batch batch, BitmapFont font, float x, float y) { font.draw(batch, displayText, x + textOffset, y, visibleTextStart, visibleTextEnd, 0, Align.left, false); }
Example 10
Source File: RetroSceneScreen.java From bladecoder-adventure-engine with Apache License 2.0 | 4 votes |
private void drawHotspots(SpriteBatch batch) { final World world = ui.getWorld(); 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(); 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 = getWorld().getI18N().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); } } }
Example 11
Source File: FilteredSelectBox.java From bladecoder-adventure-engine with Apache License 2.0 | 4 votes |
protected GlyphLayout drawItem(Batch batch, BitmapFont font, T item, float x, float y, float width) { String string = toString(item); return font.draw(batch, string, x, y, 0, string.length(), width, alignment, false, "..."); }
Example 12
Source File: CreditsScreen.java From bladecoder-adventure-engine with Apache License 2.0 | 3 votes |
public void drawCenteredScreenX(SpriteBatch batch, BitmapFont font, CharSequence str, float y, int viewportWidth) { float x = 0; layout.setText(font, str, Color.WHITE, viewportWidth, Align.center, true); // x = (viewportWidth - layout.width)/2; font.draw(batch, layout, x, y); }