private void renderWrappedCached () { String text = "Wrapped Cached Wrapped Cached"; float x = logoSprite.getX(); float y = logoSprite.getY(); float width = logoSprite.getWidth(); float height = logoSprite.getHeight(); // Obviously you wouldn't set the cache text every frame in real code. GlyphLayout layout = cache.setText(text, 0, 0, width, Align.left, true); // Note that wrapped text can be aligned: // cache.setWrappedText(text, 0, 0, width, HAlignment.CENTER); x += width / 2 - layout.width / 2; y += height / 2 + layout.height / 2; cache.setPosition(x, y); cache.draw(spriteBatch); }
private void renderMultiLineCached () { String text = "Multi Line\nCached"; int lines = 2; float x = logoSprite.getX(); float y = logoSprite.getY(); float width = logoSprite.getWidth(); float height = logoSprite.getHeight(); // Obviously you wouldn't set the cache text every frame in real code. GlyphLayout layout = cache.setText(text, 0, 0); // Note that multi line text can be aligned: // cache.setText(text, 0, 0, width, Align.center, false); x += width / 2 - layout.width / 2; y += height / 2 + layout.height / 2; cache.setPosition(x, y); cache.draw(spriteBatch); }
private void renderSingleLineCached () { String text = "Single Line Cached"; float x = logoSprite.getX(); float y = logoSprite.getY(); float width = logoSprite.getWidth(); float height = logoSprite.getHeight(); // Obviously you wouldn't set the cache text every frame in real code. GlyphLayout layout = cache.setText(text, 0, 0); cache.setColors(Color.BLUE, 1, 4); x += width / 2 - layout.width / 2; y += height / 2 + layout.height / 2; cache.setPosition(x, y); cache.draw(spriteBatch); }
public void draw (Batch batch, float parentAlpha) { validate(); Color color = tempColor.set(getColor()); color.a *= parentAlpha; if (style.background != null) { batch.setColor(color.r, color.g, color.b, color.a); style.background.draw(batch, getX(), getY(), getWidth(), getHeight()); } if (style.fontColor != null) color.mul(style.fontColor); cache.tint(color); cache.setPosition(getX(), getY()); cache.draw(batch); }
public void draw (Batch batch, float parentAlpha) { validate(); Color color = tempColor.set(getColor()); color.a *= parentAlpha; if (style.background != null) { batch.setColor(color.r, color.g, color.b, color.a); style.background.draw(batch, getX(), getY(), getWidth(), getHeight()); } if (style.fontColor != null) color.mul(style.fontColor); cache.tint(color); cache.setPosition(getX(), getY()); cache.draw(batch); }
@Override public void render () { Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); texture.bind(0); shader.begin(); shader.setUniformMatrix("u_projView", matrix); shader.setUniformi("u_texture", 0); mesh.render(shader, GL20.GL_TRIANGLES); shader.end(); batch.begin(); batch.draw(atlas.findRegion("font"), 0, 100); sprite.rotate(Gdx.graphics.getDeltaTime() * 45); for (Vector2 position : positions) { sprite.setPosition(position.x, position.y); sprite.draw(batch); } font.draw(batch, "fps:" + Gdx.graphics.getFramesPerSecond() + ", delta: " + Gdx.graphics.getDeltaTime() + ", #sprites: " + numSprites, 0, 30); cache.setPosition(200, 200); cache.draw(batch); batch.end(); }
@Override public void onChatMessage(Message message) { if (message instanceof TranslationMessage) { TranslationMessage tmsg = (TranslationMessage)message; try { chatMessages.add(String.format("<%s> %s", tmsg.getTranslationParams()[0], tmsg.getTranslationParams()[1])); } catch (ArrayIndexOutOfBoundsException e) { e.printStackTrace(); chatMessages.add(message.getFullText()); } } else { chatMessages.add(message.getFullText()); } StringBuilder messages = new StringBuilder(); for(String s : chatMessages) { messages.append(s).append("\n"); } fontCache.clear(); chatAreaLayout = fontCache.addText(messages, 0, 0, 512, Align.left, true); fontCache.setPosition(4, chatAreaLayout.height + 50); }
shadowColor.a = getColor().a; fontCache.tint(shadowColor); fontCache.setPosition(getX() + shadowOffsetX, getY() + shadowOffsetY); fontCache.draw(batch); shadowColor.a = oldShadowAlpha; for (int i = 0; i < dxs.length; i++) { fontCache.tint(shadowColor); fontCache.setPosition(getX() + offsetX + dxs[i] * strokeWidth, getY() + offsetY + dys[i] * strokeWidth + strokeWidth); fontCache.draw(batch); fontCache.setPosition(getX() + offsetX, getY() + offsetY); fontCache.draw(batch);
public void drawLabel(Batch batch, float parentAlpha) { validate(); if (getStyle().background != null) { batch.setColor(1,1,1,getColor().a); float padding=getHeight()*0.15f; float paddingX=getStyle().font.getSpaceWidth()*0.5f; getStyle().background.draw(batch, getX()-paddingX, getY(), getWidth()+paddingX*2, getHeight()+padding); } if (isStroke) { strokeColor.a = getColor().a; fontCache.tint(strokeColor); for (int i = 0; i < dxs.length; i++) { fontCache.setPosition(getX() + dxs[i] * strokeWidth, getY() + dys[i] * strokeWidth + strokeWidth); fontCache.draw(batch); } fontCache.setPosition(getX(), getY() + strokeWidth); fontCache.tint(getColor()); fontCache.draw(batch); } else { fontCache.setPosition(getX(), getY() + strokeWidth); fontCache.tint(getColor()); fontCache.draw(batch); } } }
public void draw (Batch batch, float parentAlpha) { validate(); Color color = tempColor.set(getColor()); color.a *= parentAlpha; if (style.background != null) { batch.setColor(color.r, color.g, color.b, color.a); style.background.draw(batch, getX(), getY(), getWidth(), getHeight()); } if (style.fontColor != null) color.mul(style.fontColor); cache.tint(color); cache.setPosition(getX(), getY()); cache.draw(batch); }
Gdx.gl.glGetString(GL_RENDERER), Gdx.gl.glGetString(GL_VERSION), Gdx.gl.glGetString(GL_VENDOR)); GlyphLayout glGl = glInfoRender.setText(glInfoStr, 0, 0); glInfoRender.setPosition((float) Gdx.graphics.getWidth() - glGl.width, (Gdx.graphics.getHeight() - currentHeight)); currentHeight += debugTextRenderer.getLineHeight(); fpsRender.setPosition((float) Gdx.graphics.getWidth() - fpsGl.width, (Gdx.graphics.getHeight() - currentHeight)); currentHeight += debugTextRenderer.getLineHeight(); posFormat.format(game.getPlayer().getPosition().getZ())); GlyphLayout posGl = positionRender.setText(coordsStr, 0, 0); positionRender.setPosition((float) Gdx.graphics.getWidth() - posGl.width, (Gdx.graphics.getHeight() - currentHeight)); currentHeight += debugTextRenderer.getLineHeight(); game.getWorld().getChunkPosition(game.getPlayer().getPosition().getZ())); GlyphLayout chunkGl = chunkposRender.setText(chunk, 0, 0); chunkposRender.setPosition((float) Gdx.graphics.getWidth() - chunkGl.width, (Gdx.graphics.getHeight() - currentHeight)); currentHeight += debugTextRenderer.getLineHeight(); posFormat.format(game.getPlayer().getRotation().getPitch())); GlyphLayout headingGl = headingRender.setText(headingStr, 0, 0); headingRender.setPosition((float) Gdx.graphics.getWidth() - headingGl.width, (Gdx.graphics.getHeight() - currentHeight)); currentHeight += debugTextRenderer.getLineHeight(); playerY, playerZ & (game.getWorld().getChunkSize() - 1))); GlyphLayout llGl = lightlevelRender.setText(llStr, 0, 0); lightlevelRender.setPosition((float) Gdx.graphics.getWidth() - llGl.width, (Gdx.graphics.getHeight() - currentHeight));
@Override protected void drawBackground (Batch batch, float parentAlpha, float x, float y) { float width = getWidth(), height = getHeight(); float padTop = getPadTop(); super.drawBackground(batch, parentAlpha, x, y); // Draw button table. buttonTable.getColor().a = getColor().a; buttonTable.pack(); buttonTable.setPosition(width - buttonTable.getWidth(), Math.min(height - padTop, height - buttonTable.getHeight())); buttonTable.draw(batch, parentAlpha); // Draw the title without the batch transformed or clipping applied. y += height; TextBounds bounds = titleCache.getBounds(); if ((titleAlignment & Align.left) != 0) x += getPadLeft(); else if ((titleAlignment & Align.right) != 0) x += width - bounds.width - getPadRight(); else x += (width - bounds.width) / 2; if ((titleAlignment & Align.top) == 0) { if ((titleAlignment & Align.bottom) != 0) y -= padTop - bounds.height; else y -= (padTop - bounds.height) / 2; } titleCache.setColors(tmpColor.set(getColor()).mul(style.titleFontColor)); titleCache.setPosition((int)x, (int)y - 15); // HACK for Kenney's skin only!! titleCache.draw(batch, parentAlpha); }